-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add tracing tags for headers and query parameters to GTFS API #6712
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
Merged
VillePihlava
merged 15 commits into
opentripplanner:dev-2.x
from
HSLdevcom:add-tracing-tags-to-gtfs-api
Jun 27, 2025
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7d9a82b
Initial version of GTFS tracing tags.
VillePihlava 4c17283
Fix tests.
VillePihlava c497b69
Add query parameter parsing.
VillePihlava 784ef19
Merge branch 'dev-2.x' of github.com:opentripplanner/OpenTripPlanner …
VillePihlava a82cd99
Fix format.
VillePihlava 7fbb7a8
Use server context instead of setUp function.
VillePihlava ae19c05
Change router config field name and add Javadoc.
VillePihlava b588ef5
Remove unnecessary changes.
VillePihlava 5deefd9
Rename APIUtils to TracingUtils, extract a constant for '__UNKNOWN__'…
VillePihlava 364f8f6
Use 'Api' instead of 'API'.
VillePihlava 7a005e3
Rename functions in TracingUtils.
VillePihlava 78e6553
Move TracingUtils to support package.
VillePihlava 1a04e28
Add documentation.
VillePihlava 8f00ceb
Improve documentation.
VillePihlava b4de1da
Change how comment reference is imported and update docs.
VillePihlava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
application/src/main/java/org/opentripplanner/apis/TracingUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.opentripplanner.apis; | ||
|
||
import io.micrometer.core.instrument.Tag; | ||
import jakarta.ws.rs.core.HttpHeaders; | ||
import jakarta.ws.rs.core.MultivaluedMap; | ||
import java.util.Collection; | ||
|
||
public final class TracingUtils { | ||
|
||
private static final String UNKNOWN_VALUE = "__UNKNOWN__"; | ||
|
||
/** | ||
* This method tries to find a tracing tag from a request's headers. | ||
* If no value is found for a tag, the value is set to "__UNKNOWN__". | ||
* | ||
* @param tracingHeaderTags a collection of tag names to match against headers | ||
* @param headers headers from a request | ||
* @return a list of tracing tags with computed values | ||
*/ | ||
public static Iterable<Tag> findTagsInHeaders( | ||
Collection<String> tracingHeaderTags, | ||
HttpHeaders headers | ||
) { | ||
return tracingHeaderTags | ||
.stream() | ||
.map(header -> { | ||
String value = headers.getHeaderString(header); | ||
return Tag.of(header, value == null ? UNKNOWN_VALUE : value); | ||
}) | ||
.toList(); | ||
} | ||
|
||
/** | ||
* This method tries to find a tracing tag from either a request's headers or query parameters. | ||
* The value from headers is favored if a value is present in both. | ||
* If no value is found for a tag, the value is set to "__UNKNOWN__". | ||
* | ||
* @param tracingTags a collection of tag names to match against headers or query parameters | ||
* @param headers headers from a request | ||
* @param queryParameters query parameters from a request | ||
* @return a list of tracing tags with computed values | ||
*/ | ||
public static Iterable<Tag> findTagsInHeadersOrQueryParameters( | ||
Collection<String> tracingTags, | ||
HttpHeaders headers, | ||
MultivaluedMap<String, String> queryParameters | ||
) { | ||
return tracingTags | ||
.stream() | ||
.map(header -> { | ||
String headerValue = headers.getHeaderString(header); | ||
String queryParameterValue = queryParameters.getFirst(header); | ||
if (headerValue != null) { | ||
return Tag.of(header, headerValue); | ||
} else if (queryParameterValue != null) { | ||
return Tag.of(header, queryParameterValue); | ||
} else { | ||
return Tag.of(header, UNKNOWN_VALUE); | ||
} | ||
}) | ||
.toList(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
application/src/main/java/org/opentripplanner/apis/gtfs/GtfsApiParameters.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.opentripplanner.apis.gtfs; | ||
|
||
import java.util.Collection; | ||
import org.opentripplanner.ext.actuator.MicrometerGraphQLInstrumentation; | ||
|
||
/** | ||
* GTFS API parameters. These parameters configure the behaviour of some aspects of the | ||
* GTFS GraphQL API. | ||
*/ | ||
public interface GtfsApiParameters { | ||
/** | ||
* Which HTTP headers or query parameters should be used as tags for performance metering in the | ||
* Actuator API. | ||
* | ||
* @see MicrometerGraphQLInstrumentation | ||
VillePihlava marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
*/ | ||
Collection<String> tracingTags(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
application/src/main/java/org/opentripplanner/standalone/config/sandbox/GtfsApiConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.opentripplanner.standalone.config.sandbox; | ||
|
||
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_8; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
import org.opentripplanner.apis.gtfs.GtfsApiParameters; | ||
import org.opentripplanner.standalone.config.framework.json.NodeAdapter; | ||
|
||
/** | ||
* @see GtfsApiParameters for documentation of parameters | ||
*/ | ||
public class GtfsApiConfig implements GtfsApiParameters { | ||
|
||
private final Collection<String> tracingTags; | ||
|
||
public GtfsApiConfig(String parameterName, NodeAdapter root) { | ||
var c = root | ||
.of(parameterName) | ||
.since(V2_8) | ||
.summary("Configuration for the GTFS GraphQL API.") | ||
.asObject(); | ||
|
||
tracingTags = c | ||
.of("tracingTags") | ||
.summary("Used to group requests when monitoring OTP.") | ||
VillePihlava marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
.asStringList(Set.of()); | ||
} | ||
|
||
@Override | ||
public Collection<String> tracingTags() { | ||
return tracingTags; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.