Skip to content

Commit

Permalink
ref(pkg otelify): change method and rename funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
kenriortega committed Nov 14, 2021
1 parent 71516b1 commit f626bbd
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions pkg/otelify/otelify.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ var MetricRequestLatencyProxy = promauto.NewHistogram(prometheus.HistogramOpts{
func InitProvider(name, version, namEnv, endpoint string) func() {
ctx := context.Background()

res, err := resource.New(ctx,
resource.WithAttributes(
semconv.ServiceNameKey.String(name),
semconv.ServiceVersionKey.String(version),
attribute.String("environment", namEnv),
),
)
handleErr(err, "failed to create resource")

// Set up a trace exporter
traceExporter, err := otlptracegrpc.New(ctx,
otlptracegrpc.WithInsecure(),
Expand All @@ -51,7 +42,7 @@ func InitProvider(name, version, namEnv, endpoint string) func() {
bsp := sdktrace.NewBatchSpanProcessor(traceExporter)
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithResource(res),
sdktrace.WithResource(NewResource(name, version, namEnv)),
sdktrace.WithSpanProcessor(bsp),
)
otel.SetTracerProvider(tracerProvider)
Expand All @@ -69,3 +60,17 @@ func handleErr(err error, message string) {
log.Fatalf("%s: %v", message, err)
}
}

// NewResource returns a resource describing this application.
func NewResource(name, version, namEnv string) *resource.Resource {
r, _ := resource.Merge(
resource.Default(),
resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String(name),
semconv.ServiceVersionKey.String(version),
attribute.String("environment", namEnv),
),
)
return r
}

0 comments on commit f626bbd

Please sign in to comment.