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

Expose HTTP/gRPC metrics to OpenTelemetry as well #11564

Merged
merged 6 commits into from
Sep 5, 2023

Conversation

dmathieu
Copy link
Member

@dmathieu dmathieu commented Sep 1, 2023

Motivation/summary

This modifies the HTTP and gRPC metrics middlewares to expose data to OpenTelemetry as well, so we can expose those metrics to the local exporter.

Checklist

For functional changes, consider:

  • Is it observable through the addition of either logging or metrics?
  • Is its use being published in telemetry to enable product improvement?
  • Have system tests been added to avoid regression?

How to test these changes

This is unit-tested. It can also be tested manually by running apm-server with Tilt and self instrumentation enabled.

Related issues

@dmathieu dmathieu requested a review from a team as a code owner September 1, 2023 09:28
@mergify
Copy link
Contributor

mergify bot commented Sep 1, 2023

This pull request does not have a backport label. Could you fix it @dmathieu? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-7.17 is the label to automatically backport to the 7.17 branch.
  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit.

NOTE: backport-skip has been added to this pull request.

@mergify mergify bot added the backport-skip Skip notification from the automated backport with mergify label Sep 1, 2023
}

func (m *monitoringMiddleware) getMetric(n request.ResultID) metric.Int64Counter {
name := "http.server." + n
Copy link
Member Author

Choose a reason for hiding this comment

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

I named those metrics http.server.xxx, and not apm-server.http.server.xxx, as the former better matches the otel semantic conventions.
https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-metrics.md

We can rename those metrics in the local exporter.

expectedOtel: map[string]int64{
"grpc.server." + string(request.IDRequestCount): 1,
"grpc.server." + string(request.IDResponseCount): 1,
"grpc.server." + string(request.IDResponseErrorsCount): 1,
Copy link
Member

Choose a reason for hiding this comment

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

question: why do we have an additional IDResponseErrorsInternal in monitoringInt ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't really figured out why, but nothing can set it from this interceptor, so I suspect it's because something elsewhere sets it, only for monitoring.Int.
The only location that sets it though is jaeger, and it's not executed here. So it may be state from a previous test?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have removed the metric from monitoring.Int, and the test doesn't fail either. So it does seem it's not being incremented in that interceptor (and the monitoring.Int test doesn't check for metrics that aren't emitted).

Copy link
Contributor

@simitt simitt left a comment

Choose a reason for hiding this comment

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

Didn't dive too deep into the technical details, but overall approach LGTM

@dmathieu dmathieu enabled auto-merge (squash) September 5, 2023 07:50
@dmathieu dmathieu merged commit 18ba151 into main Sep 5, 2023
6 checks passed
@dmathieu dmathieu deleted the middleware-otel-metrics branch September 5, 2023 08:04
bmorelli25 pushed a commit to bmorelli25/apm-server that referenced this pull request Sep 5, 2023
* add otel metrics to HTTP middleware

* add otel metrics to gRPC interceptor

* add server to metrics names

* remove unnecessary assignment

* remove metrics that doesn't appear to be used
@lahsivjar lahsivjar self-assigned this Oct 24, 2023
@lahsivjar
Copy link
Contributor

Tested via #11582 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Skip notification from the automated backport with mergify test-plan test-plan-ok v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants