Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource detection to checkout service #662

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,5 @@ significant modifications will be credited to OpenTelemetry Authors.
([#648](https://github.com/open-telemetry/opentelemetry-demo/pull/648))
* Add Jaeger-SPM-Config
([#655](https://github.com/open-telemetry/opentelemetry-demo/pull/655))
* Add resource detectors to checkout service
([#662](https://github.com/open-telemetry/opentelemetry-demo/pull/662))
1 change: 1 addition & 0 deletions docs/services/checkoutservice.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func initTracerProvider() *sdktrace.TracerProvider {
}
tp := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
sdktrace.WithResource(initResource()),
)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
Expand Down
17 changes: 17 additions & 0 deletions src/checkoutservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/propagation"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -71,6 +72,21 @@ func init() {
log.Out = os.Stdout
}

func initResource() *resource.Resource {
extraResources, _ := resource.New(
context.Background(),
resource.WithOS(),
resource.WithProcess(),
resource.WithContainer(),
resource.WithHost(),
)
result, _ := resource.Merge(
resource.Default(),
extraResources,
)
return result
}

func initTracerProvider() *sdktrace.TracerProvider {
ctx := context.Background()

Expand All @@ -80,6 +96,7 @@ func initTracerProvider() *sdktrace.TracerProvider {
}
tp := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
sdktrace.WithResource(initResource()),
)
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
Expand Down