Skip to content
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

Baggage is found, but empty #27

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

@kevinmichaelchen kevinmichaelchen linked an issue Nov 11, 2022 that may be closed by this pull request
propagator struct{}
)

type Values baggage.Baggage
Copy link
Owner Author

@kevinmichaelchen kevinmichaelchen Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is our special Context Propagator, pulled verbatim from temporalio/samples-go, except with just this line changed

@@ -20,7 +22,8 @@ func NewClient(lc fx.Lifecycle) (client.Client, error) {
}

c, err := client.Dial(client.Options{
Interceptors: interceptors,
Interceptors: interceptors,
ContextPropagators: []workflow.ContextPropagator{ctxpropagation.NewContextPropagator()},
Copy link
Owner Author

@kevinmichaelchen kevinmichaelchen Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All Temporal clients use Temporal's OTel interceptor, and a special Context Propagator.

See https://github.com/temporalio/samples-go/blob/v1.3.0/ctxpropagation/starter/main.go#L24

// Optional: Sets ContextPropagators that allows users to control the context information passed through a workflow
// default: nil
ContextPropagators []ContextPropagator

logrus.WithField("otel.baggage.num_members", len(members)).Info("OTel baggage")
//for _, m := range bg.Members() {
// span.SetAttributes(attribute.String(m.Key(), m.Value()))
//}
Copy link
Owner Author

@kevinmichaelchen kevinmichaelchen Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are in the gRPC server interceptor. The server should be able to find baggage in its context.

},
// create span, do context propagation
otelgrpc.UnaryClientInterceptor(),
),
Copy link
Owner Author

@kevinmichaelchen kevinmichaelchen Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are in the Temporal worker. Before we invoke the next interceptor in the chain, we're going to pull baggage from context using our special PropagateKey and then re-set it in context.

ctx = context.WithValue(ctx, ctxpropagation.PropagateKey, bg)

return ctx, nil
}
Copy link
Owner Author

@kevinmichaelchen kevinmichaelchen Nov 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are in the Temporal workflow starter. We create some OTel baggage and inject it in context using our special PropagateKey.


func injectBaggage(ctx context.Context, workflowID string) (context.Context, error) {
// Inject the workflow ID as OTel baggage, so it appears on all spans
bgMem, err := baggage.NewMember("foo", "bar")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're creating some baggage with one element 😄

// EXTRACT BAGGAGE!!
bg := baggage.FromContext(ctx)
members := bg.Members()
logrus.WithField("otel.baggage.num_members", len(members)).Info("OTel baggage")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're seeing 0 baggage elements 😟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OTel Baggage
1 participant