Skip to content

Commit

Permalink
Add resource attribute sets
Browse files Browse the repository at this point in the history
  • Loading branch information
simitt committed Aug 3, 2024
1 parent 7aeb1f5 commit b5396e8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion systemtest/cmd/sendotlp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/plog/plogotlp"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
"go.opentelemetry.io/otel/metric"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.8.0"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -137,7 +139,10 @@ func Main(ctx context.Context, logger *zap.SugaredLogger) (result error) {
if err != nil {
return err
}
tracerProvider := sdktrace.NewTracerProvider(sdktrace.WithSyncer(otlpExporters.trace))
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithSyncer(otlpExporters.trace),
sdktrace.WithResource(getCommonResource()),
)
defer func() {
if err := tracerProvider.Shutdown(ctx); err != nil {
result = errors.Join(result,
Expand Down Expand Up @@ -184,6 +189,14 @@ func Main(ctx context.Context, logger *zap.SugaredLogger) (result error) {
return nil
}

func getCommonResource() *resource.Resource {
return resource.NewWithAttributes(
semconv.SchemaURL,
attribute.StringSlice("testfix", []string{"test1", "test2"}),
attribute.IntSlice("testfixnum", []int{20, 40, 60}),
)
}

func generateSpans(ctx context.Context, tracer trace.Tracer) error {
ctx, parent := tracer.Start(ctx, "parent")
defer parent.End()
Expand Down

0 comments on commit b5396e8

Please sign in to comment.