Skip to content

Commit da81a5d

Browse files
authored
lowercase all http header and rpc metadata keys (#250)
1 parent b7ea78d commit da81a5d

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

javaagent-core/src/main/java/org/hypertrace/agent/core/instrumentation/HypertraceSemanticAttributes.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ private HypertraceSemanticAttributes() {}
3030
public static final String ADDITIONAL_DATA_SPAN_NAME = "additional-data";
3131

3232
public static AttributeKey<String> httpRequestHeader(String header) {
33-
return AttributeKey.stringKey("http.request.header." + header);
33+
return AttributeKey.stringKey("http.request.header." + header.toLowerCase());
3434
}
3535

3636
public static AttributeKey<String> httpResponseHeader(String header) {
37-
return AttributeKey.stringKey("http.response.header." + header);
37+
return AttributeKey.stringKey("http.response.header." + header.toLowerCase());
3838
}
3939

4040
public static final AttributeKey<String> HTTP_REQUEST_BODY =
@@ -51,10 +51,10 @@ public static AttributeKey<String> httpResponseHeader(String header) {
5151
AttributeKey.stringKey("rpc.response.body");
5252

5353
public static final AttributeKey<String> rpcRequestMetadata(String key) {
54-
return AttributeKey.stringKey("rpc.request.metadata." + key);
54+
return AttributeKey.stringKey("rpc.request.metadata." + key.toLowerCase());
5555
}
5656

5757
public static final AttributeKey<String> rpcResponseMetadata(String key) {
58-
return AttributeKey.stringKey("rpc.response.metadata." + key);
58+
return AttributeKey.stringKey("rpc.response.metadata." + key.toLowerCase());
5959
}
6060
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright The Hypertrace Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.hypertrace.agent.core.instrumentation;
18+
19+
import org.junit.jupiter.api.Assertions;
20+
import org.junit.jupiter.api.Test;
21+
22+
public class HypertraceSemanticAttributesTest {
23+
24+
@Test
25+
public void caseInsensitiveHttpRequestHeader() {
26+
Assertions.assertEquals(
27+
"http.request.header.content-type",
28+
HypertraceSemanticAttributes.httpRequestHeader("Content-Type").getKey());
29+
}
30+
31+
@Test
32+
public void caseInsensitiveHttpResponseHeader() {
33+
Assertions.assertEquals(
34+
"http.response.header.content-type",
35+
HypertraceSemanticAttributes.httpResponseHeader("Content-Type").getKey());
36+
}
37+
38+
@Test
39+
public void caseInsensitiveRpcRequestMetadata() {
40+
Assertions.assertEquals(
41+
"rpc.request.metadata.md", HypertraceSemanticAttributes.rpcRequestMetadata("MD").getKey());
42+
}
43+
44+
@Test
45+
public void caseInsensitiveRpcResponseMetadata() {
46+
Assertions.assertEquals(
47+
"rpc.response.metadata.md",
48+
HypertraceSemanticAttributes.rpcResponseMetadata("MD").getKey());
49+
}
50+
}

0 commit comments

Comments
 (0)