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

opentelemetry tracer: add support for environment resource detector #29547

Conversation

joaopgrassi
Copy link
Contributor

@joaopgrassi joaopgrassi commented Sep 11, 2023

Commit Message: Allow specifying resource detectors for the OpenTelemetry tracer via a new configuration resource_detectors. The resource detector reads from the env variable OTEL_RESOURCE_ATTRIBUTES which is defined by the OTel specification. The detector returns a resource object populated with the detected attributes, which is sent as part of the OTLP request.

Additional Description: This PR adds the "foundation" for building other resource detectors in Envoy. It is based on the OTel collector implementation. Users can configure multiple resource detectors, and they work together to "merge" all the detected attributes into a single resource object, which is then part of the OTLP message exported.

Risk Level: Low

Testing: Multiple unit tests, that cover all new code/scenarios. I also did manual testing, running Envoy locally with the OTel tracer + env resource detector enabled. Resource attributes detected from my environment is successfully exported as seen in the Jaeger screenshot.
resource-detectors-env-jaeger

Docs Changes: Not sure if I should add/where. Happy to do it.
Release Notes: N/A
Platform Specific Features: N/A
[Optional Runtime guard:] N/A
[Optional Fixes #28929]

Here is how the new config is used:

tracing:
  provider:
    name: envoy.tracers.opentelemetry
    typed_config:
      "@type": type.googleapis.com/envoy.config.trace.v3.OpenTelemetryConfig
       grpc_service:
         envoy_grpc:
           cluster_name: opentelemetry_collector
         timeout: 0.250s
       service_name: envoy-gRPC-exporter
       resource_detectors: # --> NEW CONFIG
         - name: envoy.tracers.opentelemetry.resource_detectors.environment
           typed_config:
             "@type": type.googleapis.com/envoy.extensions.tracers.opentelemetry.resource_detectors.v3.EnvironmentResourceDetectorConfig

Add the extension interfaces and the environment resource detector.

Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
When the OTel tracer starts, all the configured resource detector extensions are loaded and the resource object is constructed. The resource is then used when building the final OTLP request.

Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
@joaopgrassi joaopgrassi requested a review from htuch as a code owner September 11, 2023 08:34
@repokitteh-read-only
Copy link

Hi @joaopgrassi, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #29547 was opened by joaopgrassi.

see: more, trace.

@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @markdroth
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #29547 was opened by joaopgrassi.

see: more, trace.

…detectors-env

Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution.
Here's a first-pass review.
FWIW, it is better to create s series of smaller PRs to increase review speed.

@htuch htuch assigned adisuissa and unassigned markdroth Sep 13, 2023
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
@joaopgrassi
Copy link
Contributor Author

joaopgrassi commented Sep 14, 2023

@adisuissa I fixed the docs CI issues. Now the new proto is present in the API docs.

Here are the changed/new pages:

Sorry for the size of the PR. I wasn't sure if I should break it only adding the detectors and later using. I will keep it in mind for the next ones :)

@phlax
Copy link
Member

phlax commented Sep 14, 2023

/docs

for ref @joaopgrassi you can get it to link the docs that it has built in ci - this gives a generic pr link which resolves to commit - you can link these for specific pages

@repokitteh-read-only
Copy link

Docs for this Pull Request will be rendered here:

https://storage.googleapis.com/envoy-pr/29547/docs/index.html

The docs are (re-)rendered each time the CI envoy-presubmit (precheck docs) job completes.

🐱

Caused by: a #29547 (comment) was created by @phlax.

see: more, trace.

@RyanTheOptimist
Copy link
Contributor

Looks like a formatting issue?

./source/extensions/tracers/opentelemetry/resource_detectors/resource_detector.h:16: * @brief A strig key-value map that stores the resource attributes.
^
Checked 4800 file(s) and 132399 comment(s), found 1 error(s).
ERROR: spell check failed. Run 'tools/spelling/check_spelling_pedantic.py fix and/or add new words to tools/spelling/spelling_dictionary.txt'

Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
@joaopgrassi
Copy link
Contributor Author

@RyanTheOptimist sorry, it was a typo. fixed!

Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
@RyanTheOptimist
Copy link
Contributor

Looks like this needs a main merge
/wait

…detectors-env

Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
@joaopgrassi
Copy link
Contributor Author

joaopgrassi commented Oct 27, 2023

@RyanTheOptimist updated and solved the conflict. I gave write permission to maintainers on the branch/PR, in case it happens again. Should be good to go!

@joaopgrassi
Copy link
Contributor Author

/retest

…detectors-env

Signed-off-by: Joao Grassi <joao.grassi@dynatrace.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenTelemetry tracer - Hability to configure a resource detector
8 participants