Skip to content

Commit

Permalink
SWATCH-2809: Add traceresponse header to quarkus HTTP responses
Browse files Browse the repository at this point in the history
  • Loading branch information
wottop committed Aug 26, 2024
1 parent 04ed802 commit fee64ab
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ include ':swatch-common-platform-spring-boot'
include ':swatch-common-platform-quarkus'
include ':swatch-common-clock'
include ':swatch-metrics'
include ':swatch-common-trace-response'
1 change: 1 addition & 0 deletions swatch-billable-usage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
implementation project(':swatch-common-panache')
implementation project(':swatch-common-kafka')
implementation project(':swatch-common-smallrye-fault-tolerance')
implementation project(':swatch-common-trace-response')
implementation libraries["clowder-quarkus-config-source"]
implementation libraries["quarkus-logging-splunk"]
implementation libraries["splunk-library-javalogging"]
Expand Down
11 changes: 11 additions & 0 deletions swatch-common-trace-response/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id 'swatch.java-library-conventions'
}

dependencies {
implementation enforcedPlatform(libraries["quarkus-bom"])
implementation 'io.quarkus:quarkus-resteasy-reactive-jackson'
implementation('io.opentelemetry:opentelemetry-api')
}

description = 'Shared header logic for quarkus swatch services'
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Red Hat trademarks are not licensed under GPLv3. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/
package com.redhat.swatch.traceresponse;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.container.ContainerResponseContext;
import lombok.extern.slf4j.Slf4j;
import org.jboss.resteasy.reactive.server.ServerResponseFilter;

/** See https://w3c.github.io/trace-context/#traceresponse-header for reference and format */
@ApplicationScoped
@Slf4j
public class TraceResponseFilter {

@ServerResponseFilter
public void responseBasicHeaderFilter(ContainerResponseContext responseContext) {
SpanContext spanContext = Span.current().getSpanContext();
responseContext
.getHeaders()
.putSingle(
"traceresponse",
String.format(
"00-%s-%s-%s ",
spanContext.getTraceId(), spanContext.getSpanId(), spanContext.getTraceFlags()));
}

@ServerResponseFilter
public void responseLoggingFilter(ContainerResponseContext responseContext) {
log.debug(
"Sent: [traceresponse: {}] {} {}",
responseContext.getHeaderString("traceresponse"),
responseContext.getStatusInfo(),
responseContext.getEntity());
}
}
1 change: 1 addition & 0 deletions swatch-contracts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies {
implementation project(':swatch-product-configuration')
implementation project(':swatch-common-resteasy-client')
implementation project(":clients:rh-partner-gateway-client")
implementation project(':swatch-common-trace-response')
implementation libraries["clowder-quarkus-config-source"]
implementation libraries["quarkus-logging-splunk"]
implementation libraries["splunk-library-javalogging"]
Expand Down
1 change: 1 addition & 0 deletions swatch-metrics/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
implementation project(':swatch-common-clock')
implementation project(':swatch-model-events')
implementation project(':clients:quarkus:prometheus-client')
implementation project(':swatch-common-trace-response')
implementation libraries["clowder-quarkus-config-source"]
implementation libraries["quarkus-logging-splunk"]
implementation libraries["splunk-library-javalogging"]
Expand Down
1 change: 1 addition & 0 deletions swatch-producer-aws/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies {
implementation project(":swatch-product-configuration")
implementation project(":swatch-common-kafka")
implementation project(":swatch-common-resteasy-client")
implementation project(':swatch-common-trace-response')
testImplementation 'io.rest-assured:rest-assured'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'org.testcontainers:junit-jupiter'
Expand Down
1 change: 1 addition & 0 deletions swatch-producer-azure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
implementation project(':swatch-common-resteasy-client')
implementation project(":clients:azure-marketplace-client")
implementation project(':swatch-model-billable-usage')
implementation project(':swatch-common-trace-response')
annotationProcessor enforcedPlatform(libraries["quarkus-bom"])
testImplementation 'io.rest-assured:rest-assured'
testImplementation 'org.mockito:mockito-junit-jupiter'
Expand Down

0 comments on commit fee64ab

Please sign in to comment.