Skip to content

Commit dafdad1

Browse files
dmathieuXSAMpellared
authored
Templatize the otelhttp semconv module (#6626)
Co-authored-by: Sam Xie <[email protected]> Co-authored-by: Robert Pająk <[email protected]>
1 parent df8e435 commit dafdad1

24 files changed

+2823
-0
lines changed

instrumentation/net/http/otelhttp/internal/semconv/bench_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/bench_test.go.tmpl
3+
14
// Copyright The OpenTelemetry Authors
25
// SPDX-License-Identifier: Apache-2.0
36

instrumentation/net/http/otelhttp/internal/semconv/env.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/env.go.tmpl
3+
14
// Copyright The OpenTelemetry Authors
25
// SPDX-License-Identifier: Apache-2.0
36

instrumentation/net/http/otelhttp/internal/semconv/env_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/env_test.go.tmpl
3+
14
// Copyright The OpenTelemetry Authors
25
// SPDX-License-Identifier: Apache-2.0
36

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package semconv // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv"
5+
6+
// Generate semconv package:
7+
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/bench_test.go.tmpl "--data={}" --out=bench_test.go
8+
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/env.go.tmpl "--data={}" --out=env.go
9+
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/env_test.go.tmpl "--data={}" --out=env_test.go
10+
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/httpconv.go.tmpl "--data={}" --out=httpconv.go
11+
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/httpconv_test.go.tmpl "--data={}" --out=httpconv_test.go
12+
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/util.go.tmpl "--data={}" --out=util.go
13+
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/util_test.go.tmpl "--data={}" --out=util_test.go
14+
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/v1.20.0.go.tmpl "--data={}" --out=v1.20.0.go

instrumentation/net/http/otelhttp/internal/semconv/httpconv.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/httpconv.go.tmpl
3+
14
// Copyright The OpenTelemetry Authors
25
// SPDX-License-Identifier: Apache-2.0
36

instrumentation/net/http/otelhttp/internal/semconv/httpconv_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/httpconv_test.go.tmpl
3+
14
// Copyright The OpenTelemetry Authors
25
// SPDX-License-Identifier: Apache-2.0
36

instrumentation/net/http/otelhttp/internal/semconv/test/common_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/test/common_test.go.tmpl
3+
14
// Copyright The OpenTelemetry Authors
25
// SPDX-License-Identifier: Apache-2.0
36

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package test // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv/test"
5+
6+
// Generate semconv/test package:
7+
//go:generate gotmpl --body=../../../../../../../internal/shared/semconv/test/common_test.go.tmpl "--data={}" --out=common_test.go
8+
//go:generate gotmpl --body=../../../../../../../internal/shared/semconv/test/httpconv_test.go.tmpl "--data={}" --out=httpconv_test.go
9+
//go:generate gotmpl --body=../../../../../../../internal/shared/semconv/test/v1.20.0_test.go.tmpl "--data={}" --out=v1.20.0_test.go

instrumentation/net/http/otelhttp/internal/semconv/test/httpconv_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/test/httpconv_test.go.tmpl
3+
14
// Copyright The OpenTelemetry Authors
25
// SPDX-License-Identifier: Apache-2.0
36

instrumentation/net/http/otelhttp/internal/semconv/test/v1.20.0_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/test/v1.20.0_test.go.tmpl
3+
14
// Copyright The OpenTelemetry Authors
25
// SPDX-License-Identifier: Apache-2.0
36

instrumentation/net/http/otelhttp/internal/semconv/util.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/util.go.tmpl
3+
14
// Copyright The OpenTelemetry Authors
25
// SPDX-License-Identifier: Apache-2.0
36

instrumentation/net/http/otelhttp/internal/semconv/util_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/util_test.go.tmpl
3+
14
// Copyright The OpenTelemetry Authors
25
// SPDX-License-Identifier: Apache-2.0
36

instrumentation/net/http/otelhttp/internal/semconv/v1.20.0.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/v120.0.go.tmpl
3+
14
// Copyright The OpenTelemetry Authors
25
// SPDX-License-Identifier: Apache-2.0
36

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Code created by gotmpl. DO NOT MODIFY.
2+
// source: internal/shared/semconv/bench_test.go.tmpl
3+
4+
// Copyright The OpenTelemetry Authors
5+
// SPDX-License-Identifier: Apache-2.0
6+
7+
package semconv
8+
9+
import (
10+
"net/http"
11+
"net/url"
12+
"testing"
13+
14+
"go.opentelemetry.io/otel/attribute"
15+
)
16+
17+
var benchHTTPServerRequestResults []attribute.KeyValue
18+
19+
// BenchmarkHTTPServerRequest allows comparison between different version of the HTTP server.
20+
// To use an alternative start this test with OTEL_SEMCONV_STABILITY_OPT_IN set to the
21+
// version under test.
22+
func BenchmarkHTTPServerRequest(b *testing.B) {
23+
// Request was generated from TestHTTPServerRequest request.
24+
req := &http.Request{
25+
Method: http.MethodGet,
26+
URL: &url.URL{
27+
Path: "/",
28+
},
29+
Proto: "HTTP/1.1",
30+
ProtoMajor: 1,
31+
ProtoMinor: 1,
32+
Header: http.Header{
33+
"User-Agent": []string{"Go-http-client/1.1"},
34+
"Accept-Encoding": []string{"gzip"},
35+
},
36+
Body: http.NoBody,
37+
Host: "127.0.0.1:39093",
38+
RemoteAddr: "127.0.0.1:38738",
39+
RequestURI: "/",
40+
}
41+
serv := NewHTTPServer(nil)
42+
43+
b.ReportAllocs()
44+
b.ResetTimer()
45+
for i := 0; i < b.N; i++ {
46+
benchHTTPServerRequestResults = serv.RequestTraceAttrs("", req)
47+
}
48+
}

0 commit comments

Comments
 (0)