1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-25 22:41:46 +02:00
Commit Graph

25 Commits

Author SHA1 Message Date
Flc゛
80cb909774 refactor: replace context.Background() with t.Context()/b.Context() in tests (#7352)
Based on the Go version we currently use, the dependency already
supports 1.24+, which allows using `t.Context()` and `b.Context()` in
unit tests and benchmarks respectively.

- Enable `context-background` and `context-todo` in
[`usetesting`](https://golangci-lint.run/docs/linters/configuration/#usetesting)
- Adjust the code to support linter detection

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2025-09-23 09:52:45 +02:00
Tyler Yahn
7fdebbe3ed Rename Self-Observability as just Observability (#7302)
Self-Observability is a redundant term, the self being instrumented is
always the self that observability is being provided for. Remove this
redundancy.

Continue to provide backwards compatibility for any users already using
`OTEL_GO_X_SELF_OBSERVABILITY` to enable the feature.

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
2025-09-11 10:01:19 +02:00
Tyler Yahn
9b6585ae54 Encapsulate stdouttrace.Exporter instrumentation in internal package (#7307)
[Follow
guidelines](a5dcd68ebb/CONTRIBUTING.md (encapsulation))
and move instrumentation into its own type.
2025-09-09 12:11:08 -07:00
Tyler Yahn
5358fd737d Upgrade semconv dependencies to v1.37.0 (#7260)
Resolve https://github.com/open-telemetry/opentelemetry-go/issues/7255
2025-08-28 11:29:52 +02:00
Tyler Yahn
41f03302cd Amortize measurement option allocations (#7215)
This is not a performance critical exporter, but it is acting as the
foundation for all other self-observability work. We want to ensure
performance is considered for all this other work.

- Do not allocate the add and record measurement option slices.
- Do not allocate the `metric.attrOpt` to head when on default path
(i.e. `WithAttributeSet` or `WithAttributes`)

There are three additional allocations in the self-observability. It
appears these are added in the error scenario where we need to
dynamically build the attributes that are being recorded.

### Benchmarks

```terminal
$ benchstat main-49be00144.txt amortize-opts-stdouttrace.txt
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/exporters/stdout/stdouttrace
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                                        │ main-49be00144.txt │   amortize-opts-stdouttrace.txt    │
                                        │       sec/op       │   sec/op     vs base               │
ExporterExportSpans/SelfObservability-8          26.89µ ± 3%   27.40µ ± 3%       ~ (p=0.143 n=10)
ExporterExportSpans/NoObservability-8            25.99µ ± 3%   27.22µ ± 2%  +4.76% (p=0.004 n=10)

                                        │ main-49be00144.txt │    amortize-opts-stdouttrace.txt     │
                                        │        B/op        │     B/op      vs base                │
ExporterExportSpans/SelfObservability-8         5.459Ki ± 0%   4.081Ki ± 0%  -25.24% (p=0.000 n=10)
ExporterExportSpans/NoObservability-8           3.873Ki ± 0%   3.873Ki ± 0%        ~ (p=1.000 n=10)

                                        │ main-49be00144.txt │    amortize-opts-stdouttrace.txt     │
                                        │     allocs/op      │ allocs/op   vs base                  │
ExporterExportSpans/SelfObservability-8           80.00 ± 0%   67.00 ± 0%  -16.25% (p=0.000 n=10)
ExporterExportSpans/NoObservability-8             65.00 ± 0%   65.00 ± 0%        ~ (p=1.000 n=10) ¹
¹ all samples are equal
```

## Follow-up

- Investigate if the `semconv` helper packages can be updated to accept
some of this complexity (e.g. add a `AddSet` method that accepts an
`attribute.Set` instead of just `...attribute.KeyValue`).

## Alternatives

A cleaner version is found in
https://github.com/open-telemetry/opentelemetry-go/pull/7226. That
relies on an external [`bind`](https://github.com/MrAlias/bind) package
and the clean up mentioned above.
2025-08-26 09:10:29 -07:00
Tyler Yahn
44a0d621ee Pool attribute slices in stdouttrace self-observability (#7201)
### Benchmarks

```terminal
goos: linux
goarch: amd64
pkg: go.opentelemetry.io/otel/exporters/stdout/stdouttrace
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
                      │  main.txt   │   stdouttrace-pool-obs-attrs.txt   │
                      │   sec/op    │   sec/op     vs base               │
ExporterExportSpans-8   30.55µ ± 2%   31.76µ ± 3%  +3.96% (p=0.000 n=10)

                      │   main.txt   │   stdouttrace-pool-obs-attrs.txt    │
                      │     B/op     │     B/op      vs base               │
ExporterExportSpans-8   6.538Ki ± 0%   6.353Ki ± 0%  -2.84% (p=0.000 n=10)

                      │  main.txt  │  stdouttrace-pool-obs-attrs.txt   │
                      │ allocs/op  │ allocs/op   vs base               │
ExporterExportSpans-8   135.0 ± 0%   134.0 ± 0%  -0.74% (p=0.000 n=10)
```
2025-08-18 10:27:17 -07:00
Tyler Yahn
907d93b8e1 Handle partial export counts in stdouttrace observability (#7199)
Do not fail all exported metric counts if only some of them failed.
2025-08-18 09:37:33 -07:00
Tyler Yahn
3ca7996db3 Use t.Cleanup instead of defer in stdouttrace (#7204)
Let the testing system ensure proper cleanup ordering and execution.
2025-08-18 12:35:54 +02:00
Tyler Yahn
e799586d10 Restructure component ID counting in stdouttrace (#7196)
Use a resettable counter so tests can have deterministic component IDs
that do not depend on previous state.
2025-08-17 09:05:09 -07:00
Tyler Yahn
cdd18ab3a1 Fix component name for stdouttrace (#7195)
The STDOUT exporter not a standardized type. Use the [semantic
convention recommendation of a "language-defined name of the
type"](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/registry/attributes/otel.md#otel-component-type).
2025-08-17 08:46:13 -07:00
Tyler Yahn
ee6d57b7cf Flatten stdouttrace Exporter.initSelfObservability into Exporter.New (#7197)
- Do not use [side-effect
programming](https://en.wikipedia.org/wiki/Side_effect_(computer_science))
to setup an exporter. Make the setup explicit, unique, and local.
- Report instrument creation errors back to the user instead of passing
them to `otel.Handle`.
2025-08-17 08:37:42 -07:00
Flc゛
0a834865f6 feat(stdouttrace): add experimental self-observability metrics (#7133)
Fixes https://github.com/open-telemetry/opentelemetry-go/issues/7008
2025-08-11 16:05:02 +02:00
Robert Pająk
30c0f3fa6e sdk/instrumentation: Add Attributes to Scope (#5903)
Towards https://github.com/open-telemetry/opentelemetry-go/issues/3368
2024-10-29 13:47:14 +01:00
Matthieu MOREL
d284a86fa5 [chore]: enable error-nil rule from testifylint (#5843)
Testifylint is a linter that provides best practices with the use of
testify.

This PR enables
[error-nil](https://github.com/Antonboom/testifylint?tab=readme-ov-file#error-nil)
rule from [testifylint](https://github.com/Antonboom/testifylint)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
2024-09-25 11:07:59 +02:00
Damien Mathieu
3e17ef99d6 Allow relying on InstrumentationScope in SpanStub and fix remaining deprecation issues (#5627)
Rather than the deprecated InstrumentationLibrary

This is a replacement for
https://github.com/open-telemetry/opentelemetry-go/pull/3104, as after
this, there is no usage of `instrumentation.Library` within the SDK
anymore.

---------

Co-authored-by: Robert Pająk <pellared@hotmail.com>
Co-authored-by: Sam Xie <sam@samxie.me>
2024-07-24 09:33:07 +02:00
Prasad Shirodkar
fd6d4db8c3 Remove context check on stdout exporters (#5189) 2024-04-25 17:11:45 +02:00
Robert Pająk
7dea232a46 [chore] Simplify the license header (#4987) 2024-02-29 07:05:28 +01:00
Aaron Clawson
7aba25d651 Revert Adding attributes to the instrumentation scope.
Revert "Add instrumentation scope attributes (#3131)" (#3154)

This reverts commit 0078faeb0e.

Revert "Add WithScopeAttributes MeterOption to metric API package (#3132)"

This reverts commit 81a9bab814.
2022-09-09 09:06:58 -05:00
Tyler Yahn
0078faeb0e Add instrumentation scope attributes (#3131)
* Add WithScopeAttributes TracerOption to trace API

* Add Attributes field to instrumentation Scope

* Use scope attributes for new Tracer

* Fix stdouttrace expected test output

* Allow unexported Set fields in sdk/trace test

* Export instrumentation scope attrs in OTLP

* Add changes to the changelog

* Fix imports with make lint

* Add unit tests for WithScopeAttributes

* Fix English in Scope documentation
2022-08-31 15:19:50 -07:00
Tyler Yahn
1f5b159161 Use already enabled revive linter and add depguard (#2883)
* Refactor golangci-lint conf

Order settings alphabetically.

* Add revive settings to golangci conf

* Check blank imports

* Check bool-literal-in-expr

* Check constant-logical-expr

* Check context-as-argument

* Check context-key-type

* Check deep-exit

* Check defer

* Check dot-imports

* Check duplicated-imports

* Check early-return

* Check empty-block

* Check empty-lines

* Check error-naming

* Check error-return

* Check error-strings

* Check errorf

* Stop ignoring context first arg in tests

* Check exported comments

* Check flag-parameter

* Check identical branches

* Check if-return

* Check increment-decrement

* Check indent-error-flow

* Check deny list of go imports

* Check import shadowing

* Check package comments

* Check range

* Check range val in closure

* Check range val address

* Check redefines builtin id

* Check string-format

* Check struct tag

* Check superfluous else

* Check time equal

* Check var naming

* Check var declaration

* Check unconditional recursion

* Check unexported return

* Check unhandled errors

* Check unnecessary stmt

* Check unnecessary break

* Check waitgroup by value

* Exclude deep-exit check in example*_test.go files
2022-05-19 15:15:07 -05:00
Tyler Yahn
0f3ab76ff3 Rename all test funcs that mix camel and snake (#2788)
Unify on Go standard camel case naming.

Co-authored-by: Chester Cheung <cheung.zhy.csu@gmail.com>
2022-04-15 08:47:09 -07:00
Lucas Käldström
c912b179fd Print JSON objects to stdout without a wrapping array (#2196)
* Encode JSON objects to stdout one by one; not wrapped in lists

* Add changelog entry
2021-08-25 08:48:48 -07:00
Lucas Käldström
add511c105 Make WithoutTimestamps work (#2195)
* Make WithoutTimestamps work

* Add changes to changelog

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
2021-08-23 14:29:51 -07:00
Tyler Yahn
7a624ac21c Deprecated the oteltest.TraceStateFromKeyValues function (#2122)
* Deprecated the oteltest.TraceStateFromKeyValues func

* Update changelog

* make precommit
2021-07-26 11:12:53 -04:00
Anthony Mirabella
c30cd1d0fd Split stdout exporter into stdouttrace and stdoutmetric (#2005)
* Split stdout exporter into stdouttrace and stdoutmetric

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Remove unused options from stdouttrace and stdoutmetric exporters

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Update stdout exporter references in website docs

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Update docs to include correct import paths, properly describe exporter scope

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>

* Remove pointless options to disable signals from what are now single-signal exporters

Signed-off-by: Anthony J Mirabella <a9@aneurysm9.com>
2021-06-16 11:32:42 -04:00