Skip to content

Conversation

constanca-m
Copy link
Contributor

Description

This PR uses a JSON struct now instead of map[string]any, as we know what to expect from a GCP log entry. This causes significant performance improvement:

goos: linux
goarch: amd64
pkg: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/googlecloudlogentryencodingextension
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
        │   old.txt    │               new.txt               │
        │    sec/op    │   sec/op     vs base                │
Test-16   19.907µ ± 3%   6.583µ ± 4%  -66.93% (p=0.000 n=10)

        │    old.txt    │               new.txt                │
        │     B/op      │     B/op      vs base                │
Test-16   13.310Ki ± 0%   5.326Ki ± 0%  -59.98% (p=0.000 n=10)

        │   old.txt   │              new.txt               │
        │  allocs/op  │ allocs/op   vs base                │
Test-16   340.00 ± 0%   90.00 ± 0%  -73.53% (p=0.000 n=10)

The main goal of using a JSON struct is so that we can use semantic conventions, like mentioned in issue #41087.

There are also two breaking changes, since the code implemented before was not working correctly for these cases:

  • Logs also have now observedTimeUnixNano and flags
  • If there is an error handling the log, just return the error and empty logs for ALL cases. Before this behavior was inconsistent: either the error was ignored (here), or it would stop the logs from being received (here)

Link to tracking issue

Relates to #41087 (comment).

Testing

Unit tests fixed.

Documentation

N/A.

@atoulme
Copy link
Contributor

atoulme commented Jul 22, 2025

@alexvanboxel please take a look as codeowner

@constanca-m
Copy link
Contributor Author

Please @alexvanboxel, can you take a look? Thanks :)

Copy link
Contributor

@alexvanboxel alexvanboxel left a comment

Choose a reason for hiding this comment

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

This is a big commit.

@constanca-m
Copy link
Contributor Author

@atoulme can you merge this PR now that it is approved? Thank you

)

var json = jsoniter.ConfigCompatibleWithStandardLibrary
// See: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
type logEntry struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to not use the upstream definitions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, what do you mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand what you mean now.

There are fields missing from the definitions: app hub and error groups, for example

atoulme pushed a commit that referenced this pull request Jul 29, 2025
This PR transfers ownership of the GCP encoding.

My contributions:
-
#41087
-
#41446
-
#41467
-
#41137
@atoulme
Copy link
Contributor

atoulme commented Jul 30, 2025

Please resolve conflicts

@constanca-m
Copy link
Contributor Author

@atoulme conflicts are fixed

@atoulme atoulme merged commit e7c3295 into open-telemetry:main Jul 30, 2025
178 checks passed
Dylan-M pushed a commit to Dylan-M/opentelemetry-collector-contrib that referenced this pull request Aug 5, 2025
Dylan-M pushed a commit to Dylan-M/opentelemetry-collector-contrib that referenced this pull request Aug 5, 2025
…ormance (open-telemetry#41467)

#### Description

This PR uses a JSON struct now instead of `map[string]any`, as we know
what to expect from a GCP log entry. This causes significant performance
improvement:

```
goos: linux
goarch: amd64
pkg: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/googlecloudlogentryencodingextension
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
        │   old.txt    │               new.txt               │
        │    sec/op    │   sec/op     vs base                │
Test-16   19.907µ ± 3%   6.583µ ± 4%  -66.93% (p=0.000 n=10)

        │    old.txt    │               new.txt                │
        │     B/op      │     B/op      vs base                │
Test-16   13.310Ki ± 0%   5.326Ki ± 0%  -59.98% (p=0.000 n=10)

        │   old.txt   │              new.txt               │
        │  allocs/op  │ allocs/op   vs base                │
Test-16   340.00 ± 0%   90.00 ± 0%  -73.53% (p=0.000 n=10)
```

The main goal of using a JSON struct is so that we can use semantic
conventions, like mentioned in issue
open-telemetry#41087.

There are also two breaking changes, since the code implemented before
was not working correctly for these cases:
- Logs also have now observedTimeUnixNano and flags
- If there is an error handling the log, just return the error and empty
logs for ALL cases. Before this behavior was inconsistent: either the
error was ignored
([here](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/5943f5a933843e6f81bed28a05e2f33d8c1fc485/extension/encoding/googlecloudlogentryencodingextension/extension.go#L86)),
or it would stop the logs from being received
([here](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/5943f5a933843e6f81bed28a05e2f33d8c1fc485/extension/encoding/googlecloudlogentryencodingextension/extension.go#L94))

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Relates to
open-telemetry#41087 (comment).

<!--Describe what testing was performed and which tests were added.-->
#### Testing

Unit tests fixed.

<!--Describe the documentation added.-->
#### Documentation

N/A.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants