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

add otel tracing support #182

Merged
merged 24 commits into from
Jun 17, 2024
Merged

add otel tracing support #182

merged 24 commits into from
Jun 17, 2024

Conversation

endorama
Copy link
Member

@endorama endorama commented Jun 12, 2024

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

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.
@obltmachine obltmachine added the safe-to-test Automated label for running bench-diff on forked PRs label Jun 12, 2024
Comment on lines +330 to +333
logger = logger.With(
zap.String("traceId", span.SpanContext().TraceID().String()),
zap.String("spanId", span.SpanContext().SpanID().String()),
)
Copy link
Member Author

@endorama endorama Jun 12, 2024

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.

appender_test.go Outdated Show resolved Hide resolved
config.go Outdated Show resolved Hide resolved
appender.go Outdated Show resolved Hide resolved
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(
Copy link
Member Author

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.

@endorama endorama marked this pull request as ready for review June 13, 2024 10:52
@endorama endorama requested a review from a team as a code owner June 13, 2024 10:52
kruskall
kruskall previously approved these changes Jun 13, 2024
1pkg
1pkg previously approved these changes Jun 13, 2024
axw
axw previously approved these changes Jun 17, 2024
config.go Outdated
Comment on lines 49 to 54
// 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
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

done in 6cc6cea (#182)

Comment on lines +44 to +46
// 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.
Copy link
Member

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?

Copy link
Member Author

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)

@endorama endorama dismissed stale reviews from axw, 1pkg, and kruskall via a5fa1ad June 17, 2024 07:21
kruskall
kruskall previously approved these changes Jun 17, 2024
@@ -85,6 +87,8 @@ type Appender struct {
metrics metrics
mu sync.Mutex
closed chan struct{}

tracer trace.Tracer
Copy link
Member

@carsonip carsonip Jun 17, 2024

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?

Copy link
Member

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?

Copy link
Member Author

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.

appender.go Show resolved Hide resolved
Co-authored-by: Carson Ip <carsonip@users.noreply.github.com>
kruskall
kruskall previously approved these changes Jun 17, 2024
@endorama endorama merged commit 0c05046 into elastic:main Jun 17, 2024
5 checks passed
@endorama endorama deleted the otel-tracing branch June 17, 2024 14:52
codeboten pushed a commit to open-telemetry/opentelemetry-collector-contrib that referenced this pull request Jul 9, 2024
[![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
[@&#8203;kruskall](https://github.com/kruskall) in
[elastic/go-docappender#181
- bulk_indexer: track all response status codes by
[@&#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 [@&#8203;dependabot](https://github.com/dependabot) in
[elastic/go-docappender#183
- add otel tracing support by
[@&#8203;endorama](https://github.com/endorama) in
[elastic/go-docappender#182

##### New Contributors

- [@&#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>
cparkins pushed a commit to AmadeusITGroup/opentelemetry-collector-contrib that referenced this pull request Jul 11, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe-to-test Automated label for running bench-diff on forked PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for OTel tracing
6 participants