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

Pass arbitrary data in context and generate defer calls for popular frameworks #46

Closed
gagbo opened this issue May 12, 2023 · 0 comments · Fixed by #47
Closed

Pass arbitrary data in context and generate defer calls for popular frameworks #46

gagbo opened this issue May 12, 2023 · 0 comments · Fixed by #47

Comments

@gagbo
Copy link
Member

gagbo commented May 12, 2023

This is a stepping stone to deal more largely with #44 later.

The use-case for contexts

Currently the runtime context of autometrics embeds a context.Context just because it was needed when we added OpenTelemetry support. Now there's a specific need for contexts:

  • We want to be able to pass data between function calls (to transmit the traceId for example)
  • We want to be able to pass arbitrary data (it is the only way to have autometrics work with any instrumented code)

Therefore, instead of always initializing the context to a default one, we want to add the options and ability to create an autometrics.Context:

  • with a context.Context parent, and/or
  • with specific key-value pairs embedded (a TraceId and a SpanId)

End goal

Creating a context like that will allow autometrics to fetch any data using its embedded context, therefore enabling autometrics to attach any runtime data to the generated metrics

Support for popular libraries

Doing this will allow, in a second time, to use the function signatures of instrumented functions to detect what popular framework they use. If a function has func hello(ctx *gin.Context) as its signature, we could detect the gin context and generate code that will extract and add this information directly in autometrics. At that point, having tracing info in the metrics would only be one middleware away (the one that calls ctx.Set(autometrics.TraceIdKey, "traceId"))

Being able to do this needs a big refactoring of the internal.generate package though, since it kind of assumes there's only 1 way to generate the //autometrics:defer statement

@gagbo gagbo linked a pull request May 22, 2023 that will close this issue
2 tasks
@gagbo gagbo closed this as completed in #47 May 26, 2023
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 a pull request may close this issue.

1 participant