-
Notifications
You must be signed in to change notification settings - Fork 845
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement HttpServerResponseCustomizer support for Armeria (#8274)
- Loading branch information
Showing
5 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...a/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaHttpResponseMutator.java
This file contains 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 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.armeria.v1_3; | ||
|
||
import com.linecorp.armeria.common.ResponseHeadersBuilder; | ||
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseMutator; | ||
|
||
enum ArmeriaHttpResponseMutator implements HttpServerResponseMutator<ResponseHeadersBuilder> { | ||
INSTANCE; | ||
|
||
@Override | ||
public void appendHeader(ResponseHeadersBuilder response, String name, String value) { | ||
response.add(name, value); | ||
} | ||
} |
This file contains 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
47 changes: 47 additions & 0 deletions
47
...io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ResponseCustomizingDecorator.java
This file contains 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,47 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.armeria.v1_3; | ||
|
||
import com.linecorp.armeria.common.FilteredHttpResponse; | ||
import com.linecorp.armeria.common.HttpObject; | ||
import com.linecorp.armeria.common.HttpRequest; | ||
import com.linecorp.armeria.common.HttpResponse; | ||
import com.linecorp.armeria.common.ResponseHeaders; | ||
import com.linecorp.armeria.common.ResponseHeadersBuilder; | ||
import com.linecorp.armeria.server.HttpService; | ||
import com.linecorp.armeria.server.ServiceRequestContext; | ||
import com.linecorp.armeria.server.SimpleDecoratingHttpService; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.javaagent.bootstrap.http.HttpServerResponseCustomizerHolder; | ||
|
||
class ResponseCustomizingDecorator extends SimpleDecoratingHttpService { | ||
|
||
ResponseCustomizingDecorator(HttpService delegate) { | ||
super(delegate); | ||
} | ||
|
||
@Override | ||
public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception { | ||
HttpResponse response = unwrap().serve(ctx, req); | ||
Context context = Context.current(); | ||
return new FilteredHttpResponse(response) { | ||
@Override | ||
public HttpObject filter(HttpObject obj) { | ||
// Ignore other objects like HttpData. | ||
if (!(obj instanceof ResponseHeaders)) { | ||
return obj; | ||
} | ||
|
||
ResponseHeaders headers = (ResponseHeaders) obj; | ||
ResponseHeadersBuilder headersBuilder = headers.toBuilder(); | ||
HttpServerResponseCustomizerHolder.getCustomizer() | ||
.customize(context, headersBuilder, ArmeriaHttpResponseMutator.INSTANCE); | ||
|
||
return headersBuilder.build(); | ||
} | ||
}; | ||
} | ||
} |
This file contains 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 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