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

Removed _Source use from get_trace_items #191647

Closed
wants to merge 10 commits into from
Closed

Conversation

bryce-b
Copy link
Contributor

@bryce-b bryce-b commented Aug 28, 2024

Summary

This PR switched out _source for fields in the get_trace_items API, and updates all downstream dependencies of that data. Additional APIs changed: get_top_dependency_spans, get_derived_service_annotations, and trace_samples.

Checklist

Delete any items that are not applicable to this PR.

Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.

When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:

Risk Probability Severity Mitigation/Notes
Are there performance risks associated with your feature? Does it potentially access or create: (1) many fields; (2) many indices; (3) lots of data; (4) lots of saved objects; (5) large saved objects
See more potential risk examples

For maintainers

@obltmachine
Copy link

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

'transaction.type': string[];
'transaction.result'?: string[];
'faas.coldstart': boolean[];
'span.links'?: SpanLink[][];
Copy link
Member

Choose a reason for hiding this comment

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

We need to verify taking span links from fields works for our use case. My suspicion is that we need to take span links from _source because fields doesn't return an array of span link objects, but arrays for all leaf fields, such as span.links.trace.id. Also, the content for OTel span links and APM span links will look slightly differently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it appears both will have to be specified: span.links.trace.id and span.links.span.id. Are there any additional leaf fields? I can experiment with collecting them and dedotting.

Copy link
Contributor Author

@bryce-b bryce-b Sep 4, 2024

Choose a reason for hiding this comment

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

it seems like span.links.trace.id and span.links.trace.id are string types, while the processed structure is an array of SpanLink[] which implies there may be more than one span link per span, but I'm not able to find examples of spans with more than one SpanLink.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did some tests and it appears that span.links.trace.id and span.links.span.id will be two equal length and the ids at relative indices are associated.
Screenshot 2024-09-05 at 14 31 15

I was able to recreate the SpanLink[] structure by merging these two arrays together. A commit is coming shortly.

@@ -71,21 +71,61 @@ export const Example: Story<any> = () => {
return doc['processor.event'] === ProcessorEvent.error;
});

const errorDocs = events.splice(errorEventId, 1);
Copy link
Contributor Author

@bryce-b bryce-b Sep 3, 2024

Choose a reason for hiding this comment

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

The issue here is the format the synth-trace data is returned, specifically error.exception.message, which looks like:

error {
  exception: [
      { message: "..." }
  ]
}

And now that we are using fields, the expected format is flat: error.exception.message.
Is there a better way to do this? A 'fields' formatter for snyth-trace? A global 'flatten' method available, perhaps?

dedot(
{
'trace.id': transaction[SPAN_LINKS_TRACE_ID]?.[i],
'span.id': transaction[SPAN_LINKS_SPAN_ID]?.[i],
Copy link
Contributor Author

@bryce-b bryce-b Sep 5, 2024

Choose a reason for hiding this comment

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

This expression isn't ideal if these two arrays are not equal lengths. If they are not equal lengths, it means the map between the trace.ids and span.ids is wrong. I can add a ?? "0" to line 152 so it doesn't blow up, but is there a better way to handle this?

@bryce-b bryce-b marked this pull request as ready for review September 5, 2024 21:51
@bryce-b bryce-b requested a review from a team as a code owner September 5, 2024 21:51
@botelastic botelastic bot added ci:project-deploy-observability Create an Observability project Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team labels Sep 5, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

'parent.id'?: string[];
'error.id': string[];
'error.log.message'?: string[];
'error.exception'?: Exception[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to get resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like the error.exception.stacktrace... fields are not accessible through the fields query. Should I try injecting them through the _sources response? @felixbarny

Copy link
Member

Choose a reason for hiding this comment

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

Hm, yes, I think the exception stack trace (and possibly span links) need to be fetched from _source. Make sure to only fetch the fields you need from source using source filtering.

Note that the structure will be different for OTel values. So we'll probably want to normalize/convert the data to have a consistent model the UI can work with.

Copy link
Contributor

@crespocarlos crespocarlos left a comment

Choose a reason for hiding this comment

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

Hey Bryce, Is there anything we can do to the fields type, to make it behave like _sources on InferSearchResponseOf? I'm concerned about losing type safety. There are many places where we're forcing type casting, eg: fields[TRANSACTION_ID]?.[0] as string

If we manage do adjust the fields type we'll probably simplify the changes in this PR.

@@ -6,83 +6,61 @@
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: is there anything we can do to avoid changing the types here?

Comment on lines +12 to +27
'timestamp.us': number[];
'trace.id': string[];
'service.name': string[];
'service.environment'?: string[];
'agent.name': string[];
'event.outcome'?: string[];
'parent.id'?: string[];
'processor.event': ['transaction'];
'transaction.duration.us': number[];
'transaction.id': string[];
'transaction.name': string[];
'transaction.type': string[];
'transaction.result'?: string[];
'faas.coldstart'?: boolean[];
'span.links.span.id'?: string[];
'span.links.trace.id'?: string[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: Why is everything defined as arrays?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I tend to agree with @crespocarlos here. IMHO the APIs must return the same payload whether we query for _source or fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shall be done.

Comment on lines +111 to +116
Object.keys(event).forEach((key) => {
const item = event[key];
if (!Array.isArray(item)) {
event[key] = [item];
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

we could use reduce to create a new object out of an array

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not trying to create a new object from an array, I'm wrapping the values in the object with an array to match the new expected format that 'fields' returns. Maybe I'm misunderstanding your recommendation?

Comment on lines +97 to +102
Object.keys(event).forEach((key) => {
const item = event[key];
if (!Array.isArray(item)) {
event[key] = [item];
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

we could use reduce to create a new object out of an array

@kibana-ci
Copy link
Collaborator

kibana-ci commented Sep 6, 2024

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #10 / APM API tests traces/find_traces.spec.ts basic no archive Find traces when traces exist when using EQL returns the correct trace samples for join sequences
  • [job] [logs] FTR Configs #10 / APM API tests traces/find_traces.spec.ts basic no archive Find traces when traces exist when using EQL returns the correct trace samples for join sequences
  • [job] [logs] Jest Tests #16 / Marker renders error marker
  • [job] [logs] Jest Tests #16 / Marker renders error marker

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
apm 1872 2083 +211

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
apm 3.5MB 4.0MB ⚠️ +537.2KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
apm 39.9KB 42.6KB +2.7KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@cauemarcondes cauemarcondes left a comment

Choose a reason for hiding this comment

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

Please make sure the APIs return the same payload as before. This will simplify the amount of work and all tests must keep working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:project-deploy-observability Create an Observability project release_note:enhancement Team:obs-ux-infra_services Observability Infrastructure & Services User Experience Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants