-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e994ca
commit e1b06b6
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package mux | ||
|
||
import ( | ||
"net/http" | ||
|
||
ddspanname "github.com/RangelReale/opentelemetry-go-datadog-spanname" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
// NewHandler should be used with [github.com/gorilla/mux]. | ||
func NewHandler(opts ...Option) trace.TracerProvider { | ||
optns := options{ | ||
operationName: "http.request", | ||
} | ||
for _, opt := range opts { | ||
opt(&optns) | ||
} | ||
return ddspanname.NewTracerProvider(optns.operationName, | ||
ddspanname.WithTracerProvider(optns.tracerProvider)) | ||
} | ||
|
||
// SpanNameFormatter should be used with [otelmux.WithSpanNameFormatter] because | ||
// the default formatter only outputs the route without the http method. | ||
func SpanNameFormatter(routeName string, r *http.Request) string { | ||
return r.Method + " " + routeName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package mux | ||
|
||
import "go.opentelemetry.io/otel/trace" | ||
|
||
type options struct { | ||
tracerProvider trace.TracerProvider | ||
operationName string | ||
} | ||
|
||
type Option func(*options) | ||
|
||
func WithTracerProvider(tracerProvider trace.TracerProvider) Option { | ||
return func(o *options) { | ||
o.tracerProvider = tracerProvider | ||
} | ||
} | ||
|
||
func WithOperationName(name string) Option { | ||
return func(o *options) { | ||
o.operationName = name | ||
} | ||
} |