mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-03-25 21:28:58 +02:00
Update example instrumentation names (#5612)
Part of #5412 - Use the recommended package name for the instrumentation exemplified in the repository. - Use the recommended detection of a `TracerProvider` from passed context.
This commit is contained in:
parent
9535f08920
commit
f5b4e99025
@ -15,6 +15,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
### Fixed
|
||||
|
||||
- Correct comments for the priority of the `WithEndpoint` and `WithEndpointURL` options and their corresponding environment variables in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#5584)
|
||||
- Correct the `Tracer`, `Meter`, and `Logger` names used in `go.opentelemetry.io/otel/example/dice`. (#5612)
|
||||
- Correct the `Tracer` names used in `go.opentelemetry.io/otel/example/namedtracer`. (#5612)
|
||||
- Correct the `Tracer` name used in `go.opentelemetry.io/otel/example/opencensus`. (#5612)
|
||||
- Correct the `Tracer` and `Meter` names used in `go.opentelemetry.io/otel/example/otel-collector`. (#5612)
|
||||
- Correct the `Tracer` names used in `go.opentelemetry.io/otel/example/passthrough`. (#5612)
|
||||
- Correct the `Meter` name used in `go.opentelemetry.io/otel/example/prometheus`. (#5612)
|
||||
- Correct the `Tracer` names used in `go.opentelemetry.io/otel/example/zipkin`. (#5612)
|
||||
|
||||
<!-- Released section -->
|
||||
<!-- Don't change this section unless doing release -->
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
const name = "rolldice"
|
||||
const name = "go.opentelemetry.io/otel/example/dice"
|
||||
|
||||
var (
|
||||
tracer = otel.Tracer(name)
|
||||
|
@ -18,7 +18,7 @@ var lemonsKey = attribute.Key("ex.com/lemons")
|
||||
func SubOperation(ctx context.Context) error {
|
||||
// Using global provider. Alternative is to have application provide a getter
|
||||
// for its component to get the instance of the provider.
|
||||
tr := otel.Tracer("example/namedtracer/foo")
|
||||
tr := otel.Tracer("go.opentelemetry.io/otel/example/namedtracer/foo")
|
||||
|
||||
var span trace.Span
|
||||
_, span = tr.Start(ctx, "Sub operation...")
|
||||
|
@ -52,7 +52,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Create a named tracer with package path as its name.
|
||||
tracer := tp.Tracer("example/namedtracer/main")
|
||||
tracer := tp.Tracer("go.opentelemetry.io/otel/example/namedtracer")
|
||||
ctx := context.Background()
|
||||
defer func() { _ = tp.Shutdown(ctx) }()
|
||||
|
||||
|
@ -76,7 +76,8 @@ func tracing(otExporter sdktrace.SpanExporter) {
|
||||
tp.ForceFlush(ctx)
|
||||
|
||||
log.Println("Creating OpenTelemetry span\n-- It should have the OpenCensus span as a parent, since the OpenCensus span was written with using OpenTelemetry APIs.")
|
||||
ctx, otspan := tp.Tracer("simple").Start(ctx, "OpenTelemetrySpan")
|
||||
tracer := tp.Tracer("go.opentelemetry.io/otel/example/opencensus")
|
||||
ctx, otspan := tracer.Start(ctx, "OpenTelemetrySpan")
|
||||
otspan.End()
|
||||
tp.ForceFlush(ctx)
|
||||
|
||||
|
@ -130,8 +130,9 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
tracer := otel.Tracer("test-tracer")
|
||||
meter := otel.Meter("test-meter")
|
||||
name := "go.opentelemetry.io/otel/example/otel-collector"
|
||||
tracer := otel.Tracer(name)
|
||||
meter := otel.Meter(name)
|
||||
|
||||
// Attributes represent additional key-value descriptors that can be bound
|
||||
// to a metric observer or recorder.
|
||||
|
@ -30,7 +30,7 @@ func New(next func(r *http.Request)) *Handler {
|
||||
// global progatators and tracer providers.
|
||||
return &Handler{
|
||||
propagators: otel.GetTextMapPropagator(),
|
||||
tracer: otel.Tracer("examples/passthrough/handler"),
|
||||
tracer: otel.Tracer("go.opentelemetry.io/otel/example/passthrough/handler"),
|
||||
next: next,
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ import (
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
const name = "go.opentelemetry.io/otel/example/passthrough"
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
@ -37,16 +39,22 @@ func main() {
|
||||
// This is roughly what an instrumented http client does.
|
||||
log.Println("The \"make outer request\" span should be recorded, because it is recorded with a Tracer from the SDK TracerProvider")
|
||||
var span trace.Span
|
||||
ctx, span = tp.Tracer("example/passthrough/outer").Start(ctx, "make outer request")
|
||||
tracer := tp.Tracer(name)
|
||||
ctx, span = tracer.Start(ctx, "make outer request")
|
||||
defer span.End()
|
||||
r = r.WithContext(ctx)
|
||||
otel.GetTextMapPropagator().Inject(ctx, propagation.HeaderCarrier(r.Header))
|
||||
|
||||
backendFunc := func(r *http.Request) {
|
||||
// This is roughly what an instrumented http server does.
|
||||
ctx := otel.GetTextMapPropagator().Extract(r.Context(), propagation.HeaderCarrier(r.Header))
|
||||
ctx := r.Context()
|
||||
|
||||
tp := trace.SpanFromContext(ctx).TracerProvider()
|
||||
tracer := tp.Tracer(name)
|
||||
|
||||
ctx = otel.GetTextMapPropagator().Extract(ctx, propagation.HeaderCarrier(r.Header))
|
||||
log.Println("The \"handle inner request\" span should be recorded, because it is recorded with a Tracer from the SDK TracerProvider")
|
||||
_, span := tp.Tracer("example/passthrough/inner").Start(ctx, "handle inner request")
|
||||
_, span := tracer.Start(ctx, "handle inner request")
|
||||
defer span.End()
|
||||
|
||||
// Do "backend work"
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"go.opentelemetry.io/otel/sdk/metric"
|
||||
)
|
||||
|
||||
const meterName = "github.com/open-telemetry/opentelemetry-go/example/prometheus"
|
||||
const meterName = "go.opentelemetry.io/otel/example/prometheus"
|
||||
|
||||
func main() {
|
||||
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
@ -21,6 +21,8 @@ import (
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
const name = "go.opentelemetry.io/otel/example/zipkin"
|
||||
|
||||
var logger = log.New(os.Stderr, "zipkin-example", log.Ldate|log.Ltime|log.Llongfile)
|
||||
|
||||
// initTracer creates a new trace provider instance and registers it as global trace provider.
|
||||
@ -69,7 +71,7 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
tr := otel.GetTracerProvider().Tracer("component-main")
|
||||
tr := otel.GetTracerProvider().Tracer(name)
|
||||
ctx, span := tr.Start(ctx, "foo", trace.WithSpanKind(trace.SpanKindServer))
|
||||
<-time.After(6 * time.Millisecond)
|
||||
bar(ctx)
|
||||
@ -78,7 +80,7 @@ func main() {
|
||||
}
|
||||
|
||||
func bar(ctx context.Context) {
|
||||
tr := otel.GetTracerProvider().Tracer("component-bar")
|
||||
tr := trace.SpanFromContext(ctx).TracerProvider().Tracer(name)
|
||||
_, span := tr.Start(ctx, "bar")
|
||||
<-time.After(6 * time.Millisecond)
|
||||
span.End()
|
||||
|
Loading…
x
Reference in New Issue
Block a user