Skip to content

Commit

Permalink
OTEL: use updated GCP detectors
Browse files Browse the repository at this point in the history
Prefer to use the updated GCP detector for OTEL resource generation, and
change the order that the resources are stacked.
  • Loading branch information
memes committed Aug 23, 2022
1 parent fb2548c commit ed349ad
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions v2/cmd/pi/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/go-logr/logr"
"github.com/google/uuid"
"github.com/spf13/viper"
gcpdetectors "go.opentelemetry.io/contrib/detectors/gcp"
"go.opentelemetry.io/contrib/detectors/gcp"
runtimeinstrumentation "go.opentelemetry.io/contrib/instrumentation/runtime"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric"
Expand Down Expand Up @@ -77,13 +77,8 @@ func newTelemetryResource(ctx context.Context, name string) (*resource.Resource,
return nil, fmt.Errorf("failed to generate UUID for telemetry resource: %w", err)
}
res, err := resource.New(ctx,
resource.WithDetectors(gcp.NewDetector()),
resource.WithSchemaURL(semconv.SchemaURL),
resource.WithAttributes(
semconv.ServiceNamespaceKey.String(OTELNamespace),
semconv.ServiceNameKey.String(name),
semconv.ServiceVersionKey.String(version),
semconv.ServiceInstanceIDKey.String(id.String()),
),
resource.WithTelemetrySDK(),
resource.WithHost(),
resource.WithOS(),
Expand All @@ -96,11 +91,11 @@ func newTelemetryResource(ctx context.Context, name string) (*resource.Resource,
resource.WithProcessRuntimeName(),
resource.WithProcessRuntimeVersion(),
resource.WithProcessRuntimeDescription(),
// These detectors place last to override the base service attributes with specifiers from GCP
resource.WithDetectors(
&gcpdetectors.GCE{},
&gcpdetectors.GKE{},
gcpdetectors.NewCloudRun(),
resource.WithAttributes(
semconv.ServiceNamespaceKey.String(OTELNamespace),
semconv.ServiceNameKey.String(name),
semconv.ServiceVersionKey.String(version),
semconv.ServiceInstanceIDKey.String(id.String()),
),
)
if err != nil {
Expand Down

0 comments on commit ed349ad

Please sign in to comment.