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

apm: add ParentID methods to Span and Transaction #956

Merged
merged 5 commits into from
Apr 23, 2021
Merged

apm: add ParentID methods to Span and Transaction #956

merged 5 commits into from
Apr 23, 2021

Conversation

marclop
Copy link
Contributor

@marclop marclop commented Apr 23, 2021

Description

Adds a new parentID field to both Transaction and Span structures.

The parentID is only populated at start time and remains immutable
throughout the lifecycle of the Transaction or Span, making it possible
to retrieve the parentID for either after they have ended.

However, the ParentID() call might return a zero value SpanID when
a trace has no parent.

Removes the TransactionData.parentSpan field in favor of the new
Transaction.parentID and updates EnsureParent() to update that field
and Transaction.ParentID() to hold a read lock to read tx.parentID.

Last, removes the SpanData.parentID field and instead relies on the
new top level Span.parentID.

Related issues

Closes #909.

Adds two new methods to the `Span` and `Transaction` types, expanding
the API so consumers can extract the ParentIDs should they desire to.

The `Transaction.ParentID()` call reuses the already existing method
`Transaction.EnsureParent()` since it handles all the cases already.

`Span.ParentID()` is much simpler and does not generate a new SpanID
when `parentID` is zero or nil, simply returns an empty `SpanID` with
its zero value.

Closes #909.

Signed-off-by: Marc Lopez <marc5.12@outlook.com>
@marclop marclop added enhancement New feature or request agent-go labels Apr 23, 2021
@marclop marclop self-assigned this Apr 23, 2021
@elastic-apm-tech elastic-apm-tech added this to In Progress in APM-Agents (OLD) Apr 23, 2021
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

Thanks @marclop! Looks good overall, but I'd like to request a couple of main changes:

  • Don't generate a parent ID in Transaction.ParentID (name doesn't suggest that, and I don't think it's generally desirable behaviour anyway)
  • Add parentID as an immutable field to the top-level Transaction and Span types. When creating a transaction or span, set these fields. Then we can access them even after they're ended, like we can for TraceContext.

span.go Outdated Show resolved Hide resolved
span.go Outdated Show resolved Hide resolved
transaction.go Outdated Show resolved Hide resolved
docs/api.asciidoc Outdated Show resolved Hide resolved
docs/api.asciidoc Outdated Show resolved Hide resolved
@apmmachine
Copy link
Collaborator

apmmachine commented Apr 23, 2021

❕ Build Aborted

Either there was a build timeout or someone aborted the build.'}

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

Expand to view the summary

Build stats

  • Build Cause: Pull request #956 event

  • Start Time: 2021-04-23T08:01:04.592+0000

  • Duration: 63 min 41 sec

  • Commit: 899c34c

Test stats 🧪

Test Results
Failed 0
Passed 10244
Skipped 266
Total 10510

Trends 🧪

Image of Build Times

Image of Tests

Log output

Expand to view the last 100 lines of log output

[2021-04-23T08:30:58.047Z]     Then transaction outcome is "success"
[2021-04-23T08:30:58.047Z]     Given a gRPC span with 'UNIMPLEMENTED' status
[2021-04-23T08:30:58.047Z]     Then span outcome is "failure"
[2021-04-23T08:30:58.047Z] === RUN   TestFeatures/Outcome/gRPC_transaction_and_span_outcome#13
[2021-04-23T08:30:58.047Z]     Given an agent
[2021-04-23T08:30:58.047Z]     And a gRPC transaction with 'INTERNAL' status
[2021-04-23T08:30:58.047Z]     Then transaction outcome is "failure"
[2021-04-23T08:30:58.047Z]     Given a gRPC span with 'INTERNAL' status
[2021-04-23T08:30:58.047Z]     Then span outcome is "failure"
[2021-04-23T08:30:58.047Z] === RUN   TestFeatures/Outcome/gRPC_transaction_and_span_outcome#14
[2021-04-23T08:30:58.047Z]     Given an agent
[2021-04-23T08:30:58.047Z]     And a gRPC transaction with 'UNAVAILABLE' status
[2021-04-23T08:30:58.047Z]     Then transaction outcome is "failure"
[2021-04-23T08:30:58.048Z]     Given a gRPC span with 'UNAVAILABLE' status
[2021-04-23T08:30:58.048Z]     Then span outcome is "failure"
[2021-04-23T08:30:58.048Z] === RUN   TestFeatures/Outcome/gRPC_transaction_and_span_outcome#15
[2021-04-23T08:30:58.048Z]     Given an agent
[2021-04-23T08:30:58.048Z]     And a gRPC transaction with 'DATA_LOSS' status
[2021-04-23T08:30:58.048Z]     Then transaction outcome is "failure"
[2021-04-23T08:30:58.048Z]     Given a gRPC span with 'DATA_LOSS' status
[2021-04-23T08:30:58.048Z]     Then span outcome is "failure"
[2021-04-23T08:30:58.048Z] === RUN   TestFeatures/Outcome/gRPC_transaction_and_span_outcome#16
[2021-04-23T08:30:58.048Z]     Given an agent
[2021-04-23T08:30:58.048Z]     And a gRPC transaction with 'UNAUTHENTICATED' status
[2021-04-23T08:30:58.048Z]     Then transaction outcome is "success"
[2021-04-23T08:30:58.048Z]     Given a gRPC span with 'UNAUTHENTICATED' status
[2021-04-23T08:30:58.048Z]     Then span outcome is "failure"
[2021-04-23T08:30:58.048Z] === RUN   TestFeatures/Outcome/gRPC_transaction_and_span_outcome#17
[2021-04-23T08:30:58.048Z]     Given an agent
[2021-04-23T08:30:58.048Z]     And a gRPC transaction with 'n/a' status
[2021-04-23T08:30:58.048Z]     Then transaction outcome is "failure"
[2021-04-23T08:30:58.048Z]     Given a gRPC span with 'n/a' status
[2021-04-23T08:30:58.048Z]     Then span outcome is "failure"
[2021-04-23T08:30:58.048Z] --- PASS: TestFeatures (0.33s)
[2021-04-23T08:30:58.048Z]     --- PASS: TestFeatures/API_Key. (0.00s)
[2021-04-23T08:30:58.048Z]         --- PASS: TestFeatures/API_Key./A_configured_API_key_is_sent_in_the_Authorization_header. (0.00s)
[2021-04-23T08:30:58.048Z]         --- PASS: TestFeatures/API_Key./A_configured_API_key_takes_precedence_over_a_secret_token. (0.00s)
[2021-04-23T08:30:58.048Z]         --- PASS: TestFeatures/API_Key./A_configured_secret_token_is_sent_if_no_API_key_is_configured. (0.00s)
[2021-04-23T08:30:58.048Z]     --- PASS: TestFeatures/Extracting_Metadata_for_Azure_App_Service (0.22s)
[2021-04-23T08:30:58.048Z]         --- PASS: TestFeatures/Extracting_Metadata_for_Azure_App_Service/Azure_App_Service_with_all_environment_variables_present_in_expected_format (0.04s)
[2021-04-23T08:30:58.048Z]         --- PASS: TestFeatures/Extracting_Metadata_for_Azure_App_Service/Azure_App_Service_with_all_environment_variables_present_in_expected_format#01 (0.03s)
[2021-04-23T08:30:58.048Z]         --- PASS: TestFeatures/Extracting_Metadata_for_Azure_App_Service/WEBSITE_OWNER_NAME_environment_variable_not_expected_format (0.03s)
[2021-04-23T08:30:58.048Z]         --- PASS: TestFeatures/Extracting_Metadata_for_Azure_App_Service/Missing_WEBSITE_OWNER_NAME_environment_variable (0.03s)
[2021-04-23T08:30:58.048Z]         --- PASS: TestFeatures/Extracting_Metadata_for_Azure_App_Service/Missing_WEBSITE_RESOURCE_GROUP_environment_variable (0.03s)
[2021-04-23T08:30:58.048Z]         --- PASS: TestFeatures/Extracting_Metadata_for_Azure_App_Service/Missing_WEBSITE_SITE_NAME_environment_variable (0.03s)
[2021-04-23T08:30:58.048Z]         --- PASS: TestFeatures/Extracting_Metadata_for_Azure_App_Service/Missing_WEBSITE_INSTANCE_ID_environment_variable (0.03s)
[2021-04-23T08:30:58.049Z]     --- PASS: TestFeatures/Outcome (0.03s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/User_set_outcome_on_span_has_priority_over_instrumentation (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/User_set_outcome_on_transaction_has_priority_over_instrumentation (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/span_with_error (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/span_without_error (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/transaction_with_error (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/transaction_without_error (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/HTTP_transaction_and_span_outcome (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/HTTP_transaction_and_span_outcome#01 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/HTTP_transaction_and_span_outcome#02 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/HTTP_transaction_and_span_outcome#03 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/HTTP_transaction_and_span_outcome#04 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/HTTP_transaction_and_span_outcome#05 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/HTTP_transaction_and_span_outcome#06 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#01 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#02 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#03 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#04 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#05 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#06 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#07 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#08 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#09 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#10 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#11 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#12 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#13 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#14 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#15 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#16 (0.00s)
[2021-04-23T08:30:58.049Z]         --- PASS: TestFeatures/Outcome/gRPC_transaction_and_span_outcome#17 (0.00s)
[2021-04-23T08:30:58.049Z] PASS
[2021-04-23T08:30:58.049Z] ok  	apmgodog	0.506s
[2021-04-23T08:30:58.521Z] ?   	genmod	[no test files]
[2021-04-23T08:30:58.521Z] + status=0
[2021-04-23T08:30:58.521Z] + go-junit-report
[2021-04-23T08:30:58.521Z] + exit 0
[2021-04-23T08:30:59.600Z] Post stage
[2021-04-23T08:30:59.665Z] Recording test results
[2021-04-23T08:31:03.542Z] [Checks API] No suitable checks publisher found.
[2021-04-23T09:03:44.372Z] Cancelling nested steps due to timeout
[2021-04-23T09:03:44.413Z] Failed in branch Windows
[2021-04-23T09:03:44.469Z] Stage "Integration Tests" skipped due to earlier failure(s)
[2021-04-23T09:03:44.496Z] Stage "Release" skipped due to earlier failure(s)
[2021-04-23T09:03:44.509Z] Stage "Release" skipped due to earlier failure(s)
[2021-04-23T09:03:44.537Z] Stage "Release" skipped due to earlier failure(s)
[2021-04-23T09:03:45.292Z] Running on Jenkins in /var/lib/jenkins/workspace/agent-go_apm-agent-go-mbp_PR-956
[2021-04-23T09:03:45.324Z] [INFO] getVaultSecret: Getting secrets
[2021-04-23T09:03:45.356Z] Masking supported pattern matches of $VAULT_ADDR or $VAULT_ROLE_ID or $VAULT_SECRET_ID
[2021-04-23T09:03:46.051Z] + chmod 755 generate-build-data.sh
[2021-04-23T09:03:46.051Z] + ./generate-build-data.sh https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-go/apm-agent-go-mbp/PR-956/ https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-go/apm-agent-go-mbp/PR-956/runs/5 ABORTED 3761201
[2021-04-23T09:03:46.051Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-go/apm-agent-go-mbp/PR-956/runs/5/steps/?limit=10000 -o steps-info.json
[2021-04-23T09:03:46.301Z] INFO: curl https://apm-ci.elastic.co/blue/rest/organizations/jenkins/pipelines/apm-agent-go/apm-agent-go-mbp/PR-956/runs/5/tests/?status=FAILED -o tests-errors.json

Adds a new `parentID` field to both `Transaction` and `Span` structures.
The `parentID` is only populated at start time and remains immutable
throughout the lifecycle of the Transaction or Span, making it possible
to retrieve the `parentID` for either after they have ended.
However, the `ParentID()` call might return a zero value `SpanID` when
a trace has no parent.

Signed-off-by: Marc Lopez <marc5.12@outlook.com>
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

Looks good, thanks! Just a few minor things.

I think we'll hold off on merging this until the next release. We probably need a new branching strategy now that we're doing feature freezes...

docs/api.asciidoc Outdated Show resolved Hide resolved
docs/api.asciidoc Outdated Show resolved Hide resolved
span.go Show resolved Hide resolved
span.go Outdated Show resolved Hide resolved
transaction.go Show resolved Hide resolved
Removes the `TransactionData.parentSpan` field in favor of the new
`Transaction.parentID` and updates `EnsureParent()` to update that field
and `Transaction.ParentID()` to hold a read lock to read `tx.parentID`.

Signed-off-by: Marc Lopez <marc5.12@outlook.com>
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

lovely, thanks for the updates :)

Signed-off-by: Marc Lopez <marc5.12@outlook.com>
@marclop
Copy link
Contributor Author

marclop commented Apr 23, 2021

Still TODO is entry in the change log, once the upcoming version is released, we should update this PR with the change log entry.

@axw
Copy link
Member

axw commented Apr 23, 2021

I think we'll hold off on merging this until the next release. We probably need a new branching strategy now that we're doing feature freezes...

Turns out I misunderstood the agreed upon definition of feature freeze for agent development. @marclop it's OK to merge this now (with changelog updated).

Signed-off-by: Marc Lopez <marc5.12@outlook.com>
@axw
Copy link
Member

axw commented Apr 23, 2021

Windows failed due to CI platform issues. Merging, nothing platform-specific here.

@axw axw merged commit 02c92aa into elastic:master Apr 23, 2021
APM-Agents (OLD) automation moved this from In Progress to Done Apr 23, 2021
stuartnelson3 pushed a commit that referenced this pull request Jul 30, 2021
* apm: add ParentID methods to Span and Transaction

Adds two new methods to the `Span` and `Transaction` types, expanding
the API so consumers can extract the ParentIDs should they desire to.

The `Transaction.ParentID()` call reuses the already existing method
`Transaction.EnsureParent()` since it handles all the cases already.

`Span.ParentID()` is much simpler and does not generate a new SpanID
when `parentID` is zero or nil, simply returns an empty `SpanID` with
its zero value.

Closes #909.

Signed-off-by: Marc Lopez <marc5.12@outlook.com>

* Address review comments

Adds a new `parentID` field to both `Transaction` and `Span` structures.
The `parentID` is only populated at start time and remains immutable
throughout the lifecycle of the Transaction or Span, making it possible
to retrieve the `parentID` for either after they have ended.
However, the `ParentID()` call might return a zero value `SpanID` when
a trace has no parent.

Signed-off-by: Marc Lopez <marc5.12@outlook.com>

* Address review comments

Removes the `TransactionData.parentSpan` field in favor of the new
`Transaction.parentID` and updates `EnsureParent()` to update that field
and `Transaction.ParentID()` to hold a read lock to read `tx.parentID`.

Signed-off-by: Marc Lopez <marc5.12@outlook.com>

* Remove SpanData.parentID in favor of Span.parentID

Signed-off-by: Marc Lopez <marc5.12@outlook.com>

* Update changelog

Signed-off-by: Marc Lopez <marc5.12@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-go enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

Introduce a way to extract the parent ID from Transactions and Spans
3 participants