Skip to content

Commit

Permalink
Add context propagation to Go Getting Started (#3408)
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Oct 19, 2023
1 parent b3d4327 commit 606469d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions content/en/docs/instrumentation/go/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Install the following packages:
go get "go.opentelemetry.io/otel" \
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric" \
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace" \
"go.opentelemetry.io/otel/propagation" \
"go.opentelemetry.io/otel/sdk/metric" \
"go.opentelemetry.io/otel/sdk/resource" \
"go.opentelemetry.io/otel/sdk/trace" \
Expand Down Expand Up @@ -131,6 +132,7 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
Expand Down Expand Up @@ -159,14 +161,18 @@ func setupOTelSDK(ctx context.Context, serviceName, serviceVersion string) (shut
err = errors.Join(inErr, shutdown(ctx))
}

// Setup resource.
// Set up resource.
res, err := newResource(serviceName, serviceVersion)
if err != nil {
handleErr(err)
return
}

// Setup trace provider.
// Set up propagator.
prop := newPropagator()
otel.SetTextMapPropagator(prop)

// Set up trace provider.
tracerProvider, err := newTraceProvider(res)
if err != nil {
handleErr(err)
Expand All @@ -175,7 +181,7 @@ func setupOTelSDK(ctx context.Context, serviceName, serviceVersion string) (shut
shutdownFuncs = append(shutdownFuncs, tracerProvider.Shutdown)
otel.SetTracerProvider(tracerProvider)

// Setup meter provider.
// Set up meter provider.
meterProvider, err := newMeterProvider(res)
if err != nil {
handleErr(err)
Expand All @@ -195,6 +201,13 @@ func newResource(serviceName, serviceVersion string) (*resource.Resource, error)
))
}

func newPropagator() propagation.TextMapPropagator {
return propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
)
}

func newTraceProvider(res *resource.Resource) (*trace.TracerProvider, error) {
traceExporter, err := stdouttrace.New(
stdouttrace.WithPrettyPrint())
Expand Down

0 comments on commit 606469d

Please sign in to comment.