Skip to content

Conversation

@errcheckenjoyer
Copy link
Contributor

This pull request introduces an option to significantly reduce the overhead caused by tracing instrumentation inside Tracer implementation in scenarios where it is not used. Metrics operations will still be performed, and their logic remains unaffected by this change.

While otepgx already offers a method to disable tracing by providing a noop traceprovider via option, the operations that prepare trace attributes still remain. Their results will not be used, so these operations are not needed, but they still consume resources.

Here is the benchmark result demonstrating improvements:

goos: linux
goarch: amd64
pkg: github.com/exaring/otelpgx
cpu: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
          │ NoopTraceProvider │      WithDisableTracing       │
          │      sec/op       │   sec/op     vs base          │
Tracer-16         740.0µ ± 2%   738.2µ ± 1%  ~ (p=0.853 n=10)

          │ NoopTraceProvider │          WithDisableTracing          │
          │       B/op        │     B/op      vs base                │
Tracer-16        3.438Ki ± 0%   1.884Ki ± 0%  -45.20% (p=0.000 n=10)

          │ NoopTraceProvider │         WithDisableTracing         │
          │     allocs/op     │ allocs/op   vs base                │
Tracer-16          65.00 ± 0%   34.00 ± 0%  -47.69% (p=0.000 n=10)

Copy link
Member

@obitech obitech left a comment

Choose a reason for hiding this comment

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

LGTM, @costela any final thoughts?

@errcheckenjoyer
Copy link
Contributor Author

Hi, @obitech !

After testing, I found that the same result can be obtained by using the noop trace provider and simply checking that the span is not recording. This is a more idiomatic approach in OpenTelemetry, so I removed option in a new commit.

Copy link
Member

@obitech obitech left a comment

Choose a reason for hiding this comment

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

LGTM

@obitech obitech merged commit 98d6540 into exaring:main Jan 12, 2026
3 checks passed
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.

2 participants