spanName specifies the name of the span at the start of a trace. A tracer is started only when spanName is not empty.
(ctx context.Context, spanName string, f func(context.Context) error)
| 123 | // spanName specifies the name of the span at the start of a trace. A tracer is |
| 124 | // started only when spanName is not empty. |
| 125 | func (c *observabilityFlags) run(ctx context.Context, spanName string, f func(context.Context) error) error { |
| 126 | if err := c.start(ctx); err != nil { |
| 127 | return errors.Wrap(err, "unable to start observability facilities") |
| 128 | } |
| 129 | |
| 130 | defer c.stop(ctx) |
| 131 | |
| 132 | if err := c.pf.start(ctx, filepath.Join(c.outputDirectory, c.outputSubdirectoryName)); err != nil { |
| 133 | return errors.Wrap(err, "failed to start profiling") |
| 134 | } |
| 135 | |
| 136 | defer c.pf.stop(ctx) |
| 137 | |
| 138 | if spanName != "" { |
| 139 | tctx, span := tracer.Start(ctx, spanName, oteltrace.WithSpanKind(oteltrace.SpanKindClient)) |
| 140 | ctx = tctx |
| 141 | |
| 142 | defer span.End() |
| 143 | } |
| 144 | |
| 145 | return f(ctx) |
| 146 | } |
| 147 | |
| 148 | func (c *observabilityFlags) start(ctx context.Context) error { |
| 149 | c.maybeStartListener(ctx) |