Skip to content

Commit

Permalink
[surfacers.otel] Improve resource information, default is not so good (
Browse files Browse the repository at this point in the history
  • Loading branch information
manugarg committed Dec 20, 2023
1 parent be62d09 commit 2b7b4ed
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion surfacers/internal/otel/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"go.opentelemetry.io/otel/sdk/instrumentation"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/resource"
"google.golang.org/grpc/credentials"
)

Expand Down Expand Up @@ -169,10 +170,15 @@ func New(ctx context.Context, config *configpb.SurfacerConf, opts *options.Optio
exportInterval := time.Second * time.Duration(config.GetExportIntervalSec())
r := metric.NewPeriodicReader(exp, metric.WithProducer(os), metric.WithInterval(exportInterval))

res, err := resource.New(ctx, resource.WithHost(), resource.WithContainer(), resource.WithFromEnv())
if err != nil {
return nil, fmt.Errorf("failed to create resource: %v", err)
}

// This step registers the reader and pipelines behind the scene.
// manugarg: This step seems kind of unnecessary right now but it's
// required.
metric.NewMeterProvider(metric.WithReader(r))
metric.NewMeterProvider(metric.WithReader(r), metric.WithResource(res))

l.Infof("Initialized opentelemetry surfacer with config: %s", config.String())
return os, nil
Expand Down

0 comments on commit 2b7b4ed

Please sign in to comment.