-
Notifications
You must be signed in to change notification settings - Fork 57
Add trace support into task #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
33790bd
9fd912b
d11688c
3bbf9d1
a5b3495
7a608b7
ab03cd0
14a9bda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,11 @@ import ( | |
| "log" | ||
| "net" | ||
|
|
||
| "go.opentelemetry.io/otel" | ||
| "go.opentelemetry.io/otel/attribute" | ||
| "go.opentelemetry.io/otel/exporters/zipkin" | ||
| "go.opentelemetry.io/otel/sdk/resource" | ||
| "go.opentelemetry.io/otel/sdk/trace" | ||
| "google.golang.org/grpc" | ||
|
|
||
| "github.com/microsoft/durabletask-go/backend" | ||
|
|
@@ -23,6 +28,17 @@ func main() { | |
| // Parse command-line arguments | ||
| flag.Parse() | ||
|
|
||
| // Tracing can be configured independently of the orchestration code. | ||
| tp, err := ConfigureZipkinTracing() | ||
|
||
| if err != nil { | ||
| log.Fatalf("Failed to create tracer: %v", err) | ||
| } | ||
| defer func() { | ||
| if err := tp.Shutdown(context.Background()); err != nil { | ||
| log.Fatalf("Failed to stop tracer: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| grpcServer := grpc.NewServer() | ||
| worker := createTaskHubWorker(grpcServer, *dbFilePath, backend.DefaultLogger()) | ||
| if err := worker.Start(ctx); err != nil { | ||
|
|
@@ -40,6 +56,30 @@ func main() { | |
| } | ||
| } | ||
|
|
||
| func ConfigureZipkinTracing() (*trace.TracerProvider, error) { | ||
| // Inspired by this sample: https://github.com/open-telemetry/opentelemetry-go/blob/main/example/zipkin/main.go | ||
| exp, err := zipkin.New("http://localhost:9411/api/v2/spans") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // NOTE: The simple span processor is not recommended for production. | ||
| // Instead, the batch span processor should be used for production. | ||
| processor := trace.NewSimpleSpanProcessor(exp) | ||
| // processor := trace.NewBatchSpanProcessor(exp) | ||
|
|
||
| tp := trace.NewTracerProvider( | ||
| trace.WithSpanProcessor(processor), | ||
| trace.WithSampler(trace.AlwaysSample()), | ||
| trace.WithResource(resource.NewWithAttributes( | ||
| "durabletask.io", | ||
| attribute.KeyValue{Key: "service.name", Value: attribute.StringValue("sample-app")}, | ||
| )), | ||
| ) | ||
| otel.SetTracerProvider(tp) | ||
| return tp, nil | ||
| } | ||
|
|
||
| func createTaskHubWorker(server *grpc.Server, sqliteFilePath string, logger backend.Logger) backend.TaskHubWorker { | ||
| sqliteOptions := sqlite.NewSqliteOptions(sqliteFilePath) | ||
| be := sqlite.NewSqliteBackend(sqliteOptions, logger) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to reset the
ParentTraceContexthere as the newly created context above already has the span information. It can be extracted in theExecuteActivityitself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I still need to set the
ParentTraceContextas I need to populate it heredurabletask-go/backend/executor.go
Line 151 in d11688c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can actually get span from context itself: https://pkg.go.dev/go.opentelemetry.io/otel/trace#SpanFromContext and then get traceContext from span, but i guess it's easier updating the event itself.
My issue was updating the event was that it should't cause any issue in case of errors/retries(like recursively adding a new span under activity span), but it doesn't seem anything like that happening for now, so no issues.