Skip to content

Wrong current observation is set during DataFetcher execution #757

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

Closed
mareksvatos opened this issue Jul 18, 2023 · 1 comment
Closed

Wrong current observation is set during DataFetcher execution #757

mareksvatos opened this issue Jul 18, 2023 · 1 comment
Assignees
Labels
in: core Issues related to config and core support status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@mareksvatos
Copy link

Hi I’m trying out Micrometer Tracing with Spring GraphQL.

Schema:

type Query{
    playlists: [Playlist]
}

type Playlist {
    id: ID!
    name: String!
    tracks: [Track]
    artists: [Artist]
}

type Track{
    id :ID!
    name: String!
    year: Int!
    artists: [Artist]
}

type Artist{
    id: ID!
    name: String!
}

Schema mappings:

   @QueryMapping
   public List<Playlist> playlists() {
       return playlistService.getAll();
   }

   @BatchMapping(typeName = "Playlist", field = "artists")
   public Map<Playlist, List<Artist>> playlistArtists(final List<Playlist> playlists) {
       return artistService.getArtistsForPlaylists(playlists);
   }

   @BatchMapping(typeName = "Playlist", field = "tracks")
   public Map<Playlist, List<Track>> playlistTracks(final List<Playlist> playlists) {
       return tracksService.getTracks(playlists);
   }

   @BatchMapping(typeName = "Track", field = "artists")
   public Map<Track, List<Artist>> trackArtists(final List<Track> tracks) {
       return artistService.getArtistsForTracks(tracks);
   }

TrackService calls remote service via REST(Spring Cloud Feign)

ArtistService calls remote service via GRPC

Spans with calls to remote services are children of ‘graphql query’ span but they fetch data for tracks and artists fields. I would expect some correlation between the field span and batched request.

If I use @SchemaMapping instead of @BatchMapping and fetch tracks for each playlist individually the span which calls to trackService is still only child of ‘graphql field playlists’ and not ‘graphql field tracks’, which is kind of confusing to me.

Trace with BatchMapping:
batched
Trace with SchemaMapping:

not-batched

Could you please clarify if this is intended behaviour? Thank you.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 18, 2023
@bclozel bclozel self-assigned this Jul 18, 2023
@bclozel bclozel added this to the 1.2.3 milestone Aug 3, 2023
@bclozel bclozel added type: bug A general bug for: backport-to-1.2.x Marks an issue as a candidate for backport to 1.2.x and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 3, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-1.2.x Marks an issue as a candidate for backport to 1.2.x labels Aug 3, 2023
@bclozel bclozel changed the title Micrometer Tracing - Nested datafetcher spans Wrong current observation is set during DataFetcher execution Aug 17, 2023
@bclozel bclozel added the in: core Issues related to config and core support label Aug 17, 2023
@bclozel
Copy link
Member

bclozel commented Aug 17, 2023

Thanks for the report @mareksvatos!

Indeed, while reviewing the observability instrumentation I found that the current observation was properly set on the way out (in the local context of a DataFetcherResult) but not in the DataFetchingEnvironment instance given to the DataFetcher. This means that the propagation of observation would often skip a level and refer to the parent one instead of the current one, as you've noticed.

I'll revisit the instrumentation to fix this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues related to config and core support status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants