Skip to content

Commit 33cfd74

Browse files
committed
cleanup data we send
1 parent bdd60f5 commit 33cfd74

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

telemetry/exporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55

66
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
7-
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
7+
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
88
"go.opentelemetry.io/otel/sdk/resource"
99
sdktrace "go.opentelemetry.io/otel/sdk/trace"
1010
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
@@ -21,7 +21,7 @@ func TracerProvider(ctx context.Context, service string) (*sdktrace.TracerProvid
2121
),
2222
)
2323

24-
exporter, err := otlptrace.New(ctx, otlptracehttp.NewClient())
24+
exporter, err := otlptrace.New(ctx, otlptracegrpc.NewClient(otlptracegrpc.WithInsecure()))
2525
if err != nil {
2626
return nil, xerrors.Errorf("creating otlp exporter: %w", err)
2727
}

telemetry/httpmw.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,23 @@ func HTTPMW(tracerProvider *sdktrace.TracerProvider, name string) func(http.Hand
3131
next.ServeHTTP(rw, r)
3232

3333
// set the resource name as we get it only once the handler is executed
34-
resourceName := chi.RouteContext(r.Context()).RoutePattern()
35-
if resourceName == "" {
36-
resourceName = "unknown"
34+
route := chi.RouteContext(r.Context()).RoutePattern()
35+
if route == "" {
36+
route = "unknown"
3737
}
38-
resourceName = r.Method + " " + resourceName
39-
fmt.Println(resourceName)
40-
span.SetName(resourceName)
38+
span.SetName(fmt.Sprintf("%s %s", r.Method, route))
39+
span.SetAttributes(attribute.KeyValue{
40+
Key: "http.method",
41+
Value: attribute.StringValue(r.Method),
42+
})
43+
span.SetAttributes(attribute.KeyValue{
44+
Key: "http.route",
45+
Value: attribute.StringValue(route),
46+
})
47+
span.SetAttributes(attribute.KeyValue{
48+
Key: "http.path",
49+
Value: attribute.StringValue(r.URL.EscapedPath()),
50+
})
4151

4252
// set the status code
4353
status := wrw.Status()

0 commit comments

Comments
 (0)