-
Notifications
You must be signed in to change notification settings - Fork 10
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
add otel tracing support #182
Conversation
If APM tracer is not set and an otel tracer is configured use it to trace the Appender.flush execution
As we want to support otel tracing report tracing enabled if its configured. otel tracer will be checked only if there is no APM tracer configured.
logger = logger.With( | ||
zap.String("traceId", span.SpanContext().TraceID().String()), | ||
zap.String("spanId", span.SpanContext().SpanID().String()), | ||
) |
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.
For reviewers: A otel zap bridge exists at https://github.com/uptrace/opentelemetry-go-extra/tree/main/otelzap
This implementation is not compatible with a standard zap logger though, as it wraps the logger in a custom otelzap.Logger
type. Passing the context also requires to use an additional .Ctx(ctx)
call that is not supported by zap.Logger
.
Due to this I chose not to use it an instead provide correlation information as standard otel attributes. I expect this to retain the same behaviour that we get with logger.With(apmzap.TraceContext(ctx)...)
on line 320.
As we are using a span previously initialized we can ensure it's active before trying to record events on it.
As it's an in memory exporter shutting it down means we can't get spans from it.
Instead of accepting a Tracer use more idiomatic code by accepting a TracerProvider from which a Tracer is initialized in New()
span.RecordError does not set span status, which must be called manually.
@@ -316,6 +326,19 @@ func (a *Appender) flush(ctx context.Context, bulkIndexer *BulkIndexer) error { | |||
// Add trace IDs to logger, to associate any per-item errors | |||
// below with the trace. | |||
logger = logger.With(apmzap.TraceContext(ctx)...) | |||
} else if a.otelTracingEnabled() { | |||
// NOTE: this is missing transaction type information. How is this conveyed in otel? | |||
ctx, span = a.tracer.Start(ctx, "docappender.flush", trace.WithAttributes( |
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.
For reviewers: compared to APM this is missing "span type" information, but to my understanding this is delegated to an eventual otel<>Elastic APM bridge so is not a concern here.
config.go
Outdated
// OtelTracerProvider holds an optional otel TracerProvider for tracing | ||
// flush requests. | ||
// | ||
// If OtelTracerProvider is nil, requests will not be traced. | ||
// To use this provider Tracer must be nil. | ||
OtelTracerProvider trace.TracerProvider |
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.
Maybe call this TracerProvider
, with the expectation that we'll remove Tracer
in the future.
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.
done in 6cc6cea
(#182)
// If Tracer is nil, requests will not be traced. Note however that | ||
// OtelTracerProvider may not be nil, in which case the request will | ||
// be traced by a different tracer. |
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'm tempted to add a deprecation notice to this, WDYT?
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 agree, done in a5fa1ad
(#182)
@@ -85,6 +87,8 @@ type Appender struct { | |||
metrics metrics | |||
mu sync.Mutex | |||
closed chan struct{} | |||
|
|||
tracer trace.Tracer |
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.
nit: a.config.tracer is an Elastic APM tracer but a.tracer is an otel tracer, might be confusing to one. Is it possible to make it clearer?
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.
ah, I see that it was discussed. So maybe add a comment that this should not be confused with a.config.Tracer?
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.
Thanks for the suggestion, I approved it. Once the migration to otel is completed I think this will look way less confusing, but meanwhile a clarification comment helps for sure.
Co-authored-by: Carson Ip <carsonip@users.noreply.github.com>
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/elastic/go-docappender/v2](https://github.com/elastic/go-docappender) | `v2.1.4` -> `v2.2.0` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2felastic%2fgo-docappender%2fv2/v2.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2felastic%2fgo-docappender%2fv2/v2.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2felastic%2fgo-docappender%2fv2/v2.1.4/v2.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2felastic%2fgo-docappender%2fv2/v2.1.4/v2.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>elastic/go-docappender (github.com/elastic/go-docappender/v2)</summary> ### [`v2.2.0`](https://github.com/elastic/go-docappender/releases/tag/v2.2.0) [Compare Source](https://github.com/elastic/go-docappender/compare/v2.1.4...v2.2.0) ##### What's Changed - fix: update CODEOWNERS by [@​kruskall](https://github.com/kruskall) in [elastic/go-docappender#181 - bulk_indexer: track all response status codes by [@​marclop](https://github.com/marclop) in [elastic/go-docappender#177 - build(deps): bump github.com/klauspost/compress from 1.17.8 to 1.17.9 by [@​dependabot](https://github.com/dependabot) in [elastic/go-docappender#183 - add otel tracing support by [@​endorama](https://github.com/endorama) in [elastic/go-docappender#182 ##### New Contributors - [@​endorama](https://github.com/endorama) made their first contribution in [elastic/go-docappender#182 **Full Changelog**: elastic/go-docappender@v2.1.4...v2.2.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/open-telemetry/opentelemetry-collector-contrib). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjUuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQyNS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZWJvdCJdfQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com> Co-authored-by: Yang Song <songy23@users.noreply.github.com>
…lemetry#33967) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/elastic/go-docappender/v2](https://github.com/elastic/go-docappender) | `v2.1.4` -> `v2.2.0` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2felastic%2fgo-docappender%2fv2/v2.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2felastic%2fgo-docappender%2fv2/v2.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2felastic%2fgo-docappender%2fv2/v2.1.4/v2.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2felastic%2fgo-docappender%2fv2/v2.1.4/v2.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>elastic/go-docappender (github.com/elastic/go-docappender/v2)</summary> ### [`v2.2.0`](https://github.com/elastic/go-docappender/releases/tag/v2.2.0) [Compare Source](https://github.com/elastic/go-docappender/compare/v2.1.4...v2.2.0) ##### What's Changed - fix: update CODEOWNERS by [@&open-telemetry#8203;kruskall](https://github.com/kruskall) in [elastic/go-docappender#181 - bulk_indexer: track all response status codes by [@&open-telemetry#8203;marclop](https://github.com/marclop) in [elastic/go-docappender#177 - build(deps): bump github.com/klauspost/compress from 1.17.8 to 1.17.9 by [@&open-telemetry#8203;dependabot](https://github.com/dependabot) in [elastic/go-docappender#183 - add otel tracing support by [@&open-telemetry#8203;endorama](https://github.com/endorama) in [elastic/go-docappender#182 ##### New Contributors - [@&open-telemetry#8203;endorama](https://github.com/endorama) made their first contribution in [elastic/go-docappender#182 **Full Changelog**: elastic/go-docappender@v2.1.4...v2.2.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/open-telemetry/opentelemetry-collector-contrib). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjUuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQyNS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZWJvdCJdfQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com> Co-authored-by: Yang Song <songy23@users.noreply.github.com>
Add otel tracing support as a secondary tracing choice.
By default the current behaviour is retained: tracing with Elastic APM is preferred over otel tracing.
If Elastic APM tracing is not configured but otel tracing is, leverage otel tracing.
If no tracing is configured keep the current behaviour of skipping tracing.
Closes #45