Skip to content

How to use a middleware pattern for Span#makeCurrent? #3858

Answered by jkwatson
mikelane asked this question in Q&A
Discussion options

You must be logged in to vote

This is definitely the hardest part of writing instrumentation. If you create a Scope, you must close it on the same thread that it was opened on. How you accomplish that is definitely going to depend very strongly on the threading model of your application server (or whatever framework you're using).

There definitely isn't a one-size-fits-all answer to this question, unfortunately. If you can, I recommend putting together an example that could be reviewed by the instrumentation experts.

One thing that I will say about your code snippet, though, is that you shouldn't ever need to interact with ContextStorage directly under normal circumstances. Everything you need should be available on t…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@mikelane
Comment options

Answer selected by mikelane
Comment options

You must be logged in to vote
2 replies
@mikelane
Comment options

@jkwatson
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants