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: exit spans, infer destination.service.resource #2458

Closed
wants to merge 8 commits into from

Conversation

trentm
Copy link
Member

@trentm trentm commented Nov 18, 2021

This adds the explicit concept of "exit spans" -- spans the represent an
outgoing call to a downstream service. An exit span doesn't have child
spans. (Technically it can have spans of the same type+subtype, but this
agent doesn't have any cases of that.) An exit span is explicitly marked
at creation time by setting the exitSpan option to true.
https://github.com/elastic/apm/blob/master/specs/agents/tracing-spans.md#exit-spans

For exit spans the 'span.context.destination.service.resource' is
automatically inferred from other context. This can be overriden with
the new span.setDestinationService(resource).
https://github.com/elastic/apm/blob/master/specs/agents/tracing-spans-destination.md

Fixes: #2103

Checklist

This adds the explicit concept of "exit spans" -- spans the represent an
outgoing call to a downstream service. An exit span doesn't have child
spans. (Technically it can have spans of the same type+subtype, but this
agent doesn't have any cases of that.) An exit span is explicitly marked
at creation time by setting the `exitSpan` option to true.
https://github.com/elastic/apm/blob/master/specs/agents/tracing-spans.md#exit-spans

For exit spans the 'span.context.destination.service.resource' is
automatically inferred from other context. This can be overriden with
the new `span.setDestinationService(resource)`.
https://github.com/elastic/apm/blob/master/specs/agents/tracing-spans-destination.md

Fixes: #2103
@trentm trentm self-assigned this Nov 18, 2021
@github-actions github-actions bot added the agent-nodejs Make available for APM Agents project planning. label Nov 18, 2021
@apmmachine
Copy link
Contributor

apmmachine commented Nov 18, 2021

💔 Build Failed

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

Expand to view the summary

Build stats

  • Start Time: 2021-11-29T15:24:48.700+0000

  • Duration: 33 min 35 sec

  • Commit: 2dda24f

Test stats 🧪

Test Results
Failed 0
Passed 22
Skipped 0
Total 22

Steps errors 31

Expand to view the steps failures

Show only the first 10 steps failures

Run Tests
  • Took 4 min 5 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "" "12"
Run Tests
  • Took 8 min 21 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "" "12"
Run Tests
  • Took 4 min 5 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "" "12"
Run Tests
  • Took 8 min 22 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "" "12.0"
Run Tests
  • Took 4 min 13 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "" "12.0"
Run Tests
  • Took 8 min 14 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "" "12.0"
Run Tests
  • Took 4 min 5 sec . View more details here
  • Description: .ci/scripts/test.sh -b "release" -t "" "12.0"
Sleep
  • Took 1 min 47 sec . View more details here
  • Description: 5
Windows Batch Script
  • Took 1 min 29 sec . View more details here
  • Description: node test/test.js
Error signal
  • Took 0 min 0 sec . View more details here
  • Description: hudson.AbortException: script returned exit code 1

🤖 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 a commit that referenced this pull request Sep 14, 2022
This adds the new `span.context.service.target.{type,name}` fields for
improved granularity on backend services data in exit spans. This data is
used for "Service Maps" and "Dependencies" in the Kibana APM app.

All instrumentations have been updated to set appropriate service target
values.  `service.target.*` is typically inferred automatically from other
span data, so much of the instrumentation work was in adding other span
fields, most commonly `span.context.db.instance`. The one current exception
to the general inference algorithm is S3 spans, for which the spec'd
`service.target.name` doesn't follow the general pattern.

A new, public `span.setServiceTarget(type, name)` API has been added (this is
a "SHOULD" in the spec).

The new fields will replace the (now deprecated)
`span.context.destination.service.*` fields. In the current stage of
transition:

- `destination.service.{type,name}` are set to the empty string. They are no
  longer used, but the intake API v2 schema up to 7.13 require them to be
  set.
- Setting `destination.service.resource` directly is discouraged. Typically
  it is inferred from `service.target.*` values when a span is ended. Again
  the one exception is S3 spans.

The not-public-but-available-because-JavaScript `span.setDestinationContext`
has been deprecated (using it will `process.emitWarning()`) and replaced with
an internal `span._setDestinationContext()`.

As part of this change, improvements have been made to some module
instrumentations:

- `redis` and `ioredis`: `span.type` has changed from "cache" to "db" per
  spec (https://github.com/elastic/apm/blob/main/specs/agents/tracing-instrumentation-db.md#redis)
- `mongodb`: `span.action` used to be "query", now it will be the mongodb
  command name, e.g. "find", "insert".
- `mongodb` and `mongodb-core`: `span.db.instance` is now set to the database
  name (#1494)
- `mysql` and `mysql2`: `span.db.{instance,user}` are now populated.
- `@elastic/elasticsearch`: The cluster name is heuristically determined for
  Elastic Cloud deployments and used for `db.instance`.
- `sqs`: `span.destination.{address,port}` are now populated.
- `pg`: `span.db.{instance,user}` are now populated.
- `cassandra-driver`: the Cassandra keyspace is captured for service target
  data, if available.
- OpenTelemetry Bridge: OTel spans with kind PRODUCER and CLIENT are now
  handled as exit spans (e.g. span compression could apply).

Closes: #2621
Closes: #2822
Closes: #1494
Closes: #1897
Closes: #2103
Obsoletes: #2458
@trentm
Copy link
Member Author

trentm commented Sep 14, 2022

This was obsoleted by #2552 that added exit spans and #2882 that added service.target.* fields, and the inference of destination.service.resource from service.target.* and other span fields.

@trentm trentm closed this Sep 14, 2022
fpm-peter pushed a commit to fpm-git/apm-agent-nodejs that referenced this pull request Aug 20, 2024
This adds the new `span.context.service.target.{type,name}` fields for
improved granularity on backend services data in exit spans. This data is
used for "Service Maps" and "Dependencies" in the Kibana APM app.

All instrumentations have been updated to set appropriate service target
values.  `service.target.*` is typically inferred automatically from other
span data, so much of the instrumentation work was in adding other span
fields, most commonly `span.context.db.instance`. The one current exception
to the general inference algorithm is S3 spans, for which the spec'd
`service.target.name` doesn't follow the general pattern.

A new, public `span.setServiceTarget(type, name)` API has been added (this is
a "SHOULD" in the spec).

The new fields will replace the (now deprecated)
`span.context.destination.service.*` fields. In the current stage of
transition:

- `destination.service.{type,name}` are set to the empty string. They are no
  longer used, but the intake API v2 schema up to 7.13 require them to be
  set.
- Setting `destination.service.resource` directly is discouraged. Typically
  it is inferred from `service.target.*` values when a span is ended. Again
  the one exception is S3 spans.

The not-public-but-available-because-JavaScript `span.setDestinationContext`
has been deprecated (using it will `process.emitWarning()`) and replaced with
an internal `span._setDestinationContext()`.

As part of this change, improvements have been made to some module
instrumentations:

- `redis` and `ioredis`: `span.type` has changed from "cache" to "db" per
  spec (https://github.com/elastic/apm/blob/main/specs/agents/tracing-instrumentation-db.md#redis)
- `mongodb`: `span.action` used to be "query", now it will be the mongodb
  command name, e.g. "find", "insert".
- `mongodb` and `mongodb-core`: `span.db.instance` is now set to the database
  name (elastic#1494)
- `mysql` and `mysql2`: `span.db.{instance,user}` are now populated.
- `@elastic/elasticsearch`: The cluster name is heuristically determined for
  Elastic Cloud deployments and used for `db.instance`.
- `sqs`: `span.destination.{address,port}` are now populated.
- `pg`: `span.db.{instance,user}` are now populated.
- `cassandra-driver`: the Cassandra keyspace is captured for service target
  data, if available.
- OpenTelemetry Bridge: OTel spans with kind PRODUCER and CLIENT are now
  handled as exit spans (e.g. span compression could apply).

Closes: elastic#2621
Closes: elastic#2822
Closes: elastic#1494
Closes: elastic#1897
Closes: elastic#2103
Obsoletes: elastic#2458
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 448] Auto-infer destination.service.resource and adapt public API
2 participants