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

feat: Reporter for OTel Metrics #3152

Merged
merged 58 commits into from
Apr 28, 2023
Merged

feat: Reporter for OTel Metrics #3152

merged 58 commits into from
Apr 28, 2023

Conversation

trentm
Copy link
Member

@trentm trentm commented Feb 6, 2023

With this change the APM agent adds support for using OTel Metrics in two ways:

  1. The @opentelemetry/api package is instrumented so that usage of
    .metrics.getMeterProvider(...) will use one provided by the APM agent,
    if the user hasn't explicitly provided one of their own. This implementation
    uses a version of the OTel Metrics SDK included with the APM agent. It
    is configured to sent metrics to APM server by default. This allows a user
    to use the OTel Metrics API and get metrics set to APM server without any
    configuration.
  2. Alternatively, the @opentelemetry/sdk-metrics package is instrumented so
    that when a user creates a MeterProvider, the APM agent will added a
    MetricReader that sends metrics to APM server. This allows a user to
    configure metrics as they wish using the OTel Metrics SDK and then
    automatically get those metrics sent to APM server.

Closes: #2954
Refs: elastic/apm#691
Refs: elastic/apm#742 (spec PR)

…g the OTel SDK

Users of this can use '@opentelemetry/api' for metrics. Those metrics
will be sent to APM server via its native protocol (intake v2). This
is a first stab. See this for the best example:
    examples/otel-metrics-poc/use-otel-metrics-via-elastic-apm.js
…age); disable the 'OTel Metrics PoC' provider (will clean this out later)
@trentm trentm self-assigned this Feb 6, 2023
@github-actions github-actions bot added the agent-nodejs Make available for APM Agents project planning. label Feb 6, 2023
@apmmachine
Copy link
Contributor

apmmachine commented Feb 7, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview previewSnapshots

Expand to view the summary

Build stats

  • Start Time: 2023-03-29T22:08:55.154+0000

  • Duration: 21 min 21 sec

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run module tests for <modules> : Run TAV tests for one or more modules, where <modules> can be either a comma separated list of modules (e.g. memcached,redis) or the string literal ALL to test all modules

  • run benchmark tests : Run the benchmark test only.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

trentm added 22 commits February 6, 2023 16:43
…r if metrics is not enabled (metricsInterval=0s)
because that means a user cannot use it. Instead we instrument
otel.metrics.getMeterProvider() and provide one from the APM agent
if the user hasn't registered one. That means that user code can
use metrics from the OTel API:
    const otel = require('@opentelemetry/api')
    const meter = otel.metrics.getMeter('my-meter')
    const aCounter = meter.createCounter('a_counter')
    ...
and if the APM agent is in use, then metrics will go to APM server.
…tel/sdk-metrics creation of a MetricProvider as needed
… draft spec

Note that this differs from OTel Metrics SDK default for OTLP export.
@trentm trentm marked this pull request as ready for review April 17, 2023 22:29
lib/agent.js Outdated Show resolved Hide resolved
@trentm trentm merged commit 70ef967 into main Apr 28, 2023
@trentm trentm deleted the trentm/otel-metrics-poc branch April 28, 2023 23:06
trentm added a commit that referenced this pull request May 16, 2023
With this change the APM agent adds support for using OTel Metrics in two ways:

1. The `@opentelemetry/api` package is instrumented so that usage of
   `.metrics.getMeterProvider(...)` will use one provided by the APM agent,
   if the user hasn't explicitly provided one of their own. This implementation
   uses a version of the OTel Metrics SDK included with the APM agent. It
   is configured to sent metrics to APM server by default. This allows a user
   to use the OTel Metrics API and get metrics set to APM server without any
   configuration.
2. Alternatively, the `@opentelemetry/sdk-metrics` package is instrumented so
   that when a user creates a `MeterProvider`, the APM agent will added a
   `MetricReader` that sends metrics to APM server.  This allows a user to
   configure metrics as they wish using the OTel Metrics SDK and then
   automatically get those metrics sent to APM server.

This also adds some grouping in ".ci/tav.json" for the TAV workflow to avoid the
256 jobs GH Actions limit. I'm not yet sure if those will work well.

Closes: #2954
Refs: elastic/apm#691
Refs: elastic/apm#742 (spec PR)
fpm-peter pushed a commit to fpm-git/apm-agent-nodejs that referenced this pull request Aug 20, 2024
With this change the APM agent adds support for using OTel Metrics in two ways:

1. The `@opentelemetry/api` package is instrumented so that usage of
   `.metrics.getMeterProvider(...)` will use one provided by the APM agent,
   if the user hasn't explicitly provided one of their own. This implementation
   uses a version of the OTel Metrics SDK included with the APM agent. It
   is configured to sent metrics to APM server by default. This allows a user
   to use the OTel Metrics API and get metrics set to APM server without any
   configuration.
2. Alternatively, the `@opentelemetry/sdk-metrics` package is instrumented so
   that when a user creates a `MeterProvider`, the APM agent will added a
   `MetricReader` that sends metrics to APM server.  This allows a user to
   configure metrics as they wish using the OTel Metrics SDK and then
   automatically get those metrics sent to APM server.

This also adds some grouping in ".ci/tav.json" for the TAV workflow to avoid the
256 jobs GH Actions limit. I'm not yet sure if those will work well.

Closes: elastic#2954
Refs: elastic/apm#691
Refs: elastic/apm#742 (spec PR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[META 691] Reporter for OTel Metrics
3 participants