Skip to content

Commit 25693fb

Browse files
committed
Merge branch 'main' into metric-inst-conf-split
2 parents 4585799 + 0851690 commit 25693fb

File tree

24 files changed

+4858
-111
lines changed

24 files changed

+4858
-111
lines changed

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1515
- Return a `Registration` from the `RegisterCallback` method of a `Meter` in the `go.opentelemetry.io/otel/metric` package.
1616
This `Registration` can be used to unregister callbacks. (#3522)
1717
- Add `Producer` interface and `Reader.RegisterProducer(Producer)` to `go.opentelemetry.io/otel/sdk/metric` to enable external metric Producers. (#3524)
18+
- Add the `Callback` function type to the `go.opentelemetry.io/otel/metric` package.
19+
This new named function type is registered with a `Meter`. (#3564)
20+
- Add the `go.opentelemetry.io/otel/semconv/v1.13.0` package.
21+
The package contains semantic conventions from the `v1.13.0` version of the OpenTelemetry specification. (#3499)
22+
- The `EndUserAttributesFromHTTPRequest` function in `go.opentelemetry.io/otel/semconv/v1.12.0` is merged into `ClientRequest` and `ServerRequest` in `go.opentelemetry.io/otel/semconv/v1.13.0/httpconv`.
23+
- The `HTTPAttributesFromHTTPStatusCode` function in `go.opentelemetry.io/otel/semconv/v1.12.0` is merged into `ClientResponse` in `go.opentelemetry.io/otel/semconv/v1.13.0/httpconv`.
24+
- The `HTTPClientAttributesFromHTTPRequest` function in `go.opentelemetry.io/otel/semconv/v1.12.0` is replaced by `ClientRequest` in `go.opentelemetry.io/otel/semconv/v1.13.0/httpconv`.
25+
- The `HTTPServerAttributesFromHTTPRequest` function in `go.opentelemetry.io/otel/semconv/v1.12.0` is replaced by `ServerRequest` in `go.opentelemetry.io/otel/semconv/v1.13.0/httpconv`.
26+
- The `HTTPServerMetricAttributesFromHTTPRequest` function in `go.opentelemetry.io/otel/semconv/v1.12.0` is replaced by `ServerRequest` in `go.opentelemetry.io/otel/semconv/v1.13.0/httpconv`.
27+
- The `NetAttributesFromHTTPRequest` function in `go.opentelemetry.io/otel/semconv/v1.12.0` is split into `Transport` in `go.opentelemetry.io/otel/semconv/v1.13.0/netconv` and `ClientRequest` or `ServerRequest` in `go.opentelemetry.io/otel/semconv/v1.13.0/httpconv`.
28+
- The `SpanStatusFromHTTPStatusCode` function in `go.opentelemetry.io/otel/semconv/v1.12.0` is replaced by `ClientStatus` in `go.opentelemetry.io/otel/semconv/v1.13.0/httpconv`.
29+
- The `SpanStatusFromHTTPStatusCodeAndSpanKind` function in `go.opentelemetry.io/otel/semconv/v1.12.0` is split into `ClientStatus` and `ServerStatus` in `go.opentelemetry.io/otel/semconv/v1.13.0/httpconv`.
30+
- The `Client` function is included in `go.opentelemetry.io/otel/semconv/v1.13.0/netconv` to generate attributes for a `net.Conn`.
31+
- The `Server` function is included in `go.opentelemetry.io/otel/semconv/v1.13.0/netconv` to generate attributes for a `net.Listener`.
1832

1933
### Changed
2034

@@ -59,6 +73,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
5973
- `InstrumentKindAsyncCounter` is renamed to `InstrumentKindObservableCounter`
6074
- `InstrumentKindAsyncUpDownCounter` is renamed to `InstrumentKindObservableUpDownCounter`
6175
- `InstrumentKindAsyncGauge` is renamed to `InstrumentKindObservableGauge`
76+
- Update the `RegisterCallback` method of the `Meter` in the `go.opentelemetry.io/otel/sdk/metric` package to accept the added `Callback` type instead of an inline function type definition.
77+
The underlying type of a `Callback` is the same `func(context.Context)` that the method used to accept. (#3564)
6278

6379
### Deprecated
6480

RELEASING.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,25 @@ New versions of the [OpenTelemetry specification] mean new versions of the `semc
66
The `semconv-generate` make target is used for this.
77

88
1. Checkout a local copy of the [OpenTelemetry specification] to the desired release tag.
9-
2. Run the `make semconv-generate ...` target from this repository.
9+
2. Pull the latest `otel/semconvgen` image: `docker pull otel/semconvgen:latest`
10+
3. Run the `make semconv-generate ...` target from this repository.
1011

1112
For example,
1213

1314
```sh
14-
export TAG="v1.7.0" # Change to the release version you are generating.
15+
export TAG="v1.13.0" # Change to the release version you are generating.
1516
export OTEL_SPEC_REPO="/absolute/path/to/opentelemetry-specification"
16-
git -C "$OTEL_SPEC_REPO" checkout "tags/$TAG"
17+
git -C "$OTEL_SPEC_REPO" checkout "tags/$TAG" -b "$TAG"
18+
docker pull otel/semconvgen:latest
1719
make semconv-generate # Uses the exported TAG and OTEL_SPEC_REPO.
1820
```
1921

2022
This should create a new sub-package of [`semconv`](./semconv).
2123
Ensure things look correct before submitting a pull request to include the addition.
2224

25+
**Note**, the generation code was changed to generate versions >= 1.13.
26+
To generate versions prior to this, checkout the old release of this repository (i.e. [2fe8861](https://github.com/open-telemetry/opentelemetry-go/commit/2fe8861a24e20088c065b116089862caf9e3cd8b)).
27+
2328
## Pre-Release
2429

2530
First, decide which module sets will be released and update their versions

internal/tools/semconvkit/main.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package main
2121
import (
2222
"embed"
2323
"flag"
24+
"fmt"
2425
"log"
2526
"os"
2627
"path/filepath"
@@ -32,7 +33,7 @@ var (
3233
out = flag.String("output", "./", "output directory")
3334
tag = flag.String("tag", "", "OpenTelemetry tagged version")
3435

35-
//go:embed templates/*.tmpl
36+
//go:embed templates/*.tmpl templates/netconv/*.tmpl templates/httpconv/*.tmpl
3637
rootFS embed.FS
3738
)
3839

@@ -48,8 +49,8 @@ func (sc SemanticConventions) SemVer() string {
4849
}
4950

5051
// render renders all templates to the dest directory using the data.
51-
func render(dest string, data *SemanticConventions) error {
52-
tmpls, err := template.ParseFS(rootFS, "templates/*.tmpl")
52+
func render(src, dest string, data *SemanticConventions) error {
53+
tmpls, err := template.ParseFS(rootFS, src)
5354
if err != nil {
5455
return err
5556
}
@@ -78,7 +79,17 @@ func main() {
7879

7980
sc := &SemanticConventions{TagVer: *tag}
8081

81-
if err := render(*out, sc); err != nil {
82+
if err := render("templates/*.tmpl", *out, sc); err != nil {
83+
log.Fatal(err)
84+
}
85+
86+
dest := fmt.Sprintf("%s/netconv", *out)
87+
if err := render("templates/netconv/*.tmpl", dest, sc); err != nil {
88+
log.Fatal(err)
89+
}
90+
91+
dest = fmt.Sprintf("%s/httpconv", *out)
92+
if err := render("templates/httpconv/*.tmpl", dest, sc); err != nil {
8293
log.Fatal(err)
8394
}
8495
}

internal/tools/semconvkit/templates/http.go.tmpl

-93
Original file line numberDiff line numberDiff line change
@@ -14,101 +14,8 @@
1414

1515
package semconv // import "go.opentelemetry.io/otel/semconv/{{.TagVer}}"
1616

17-
import (
18-
"net/http"
19-
20-
"go.opentelemetry.io/otel/attribute"
21-
"go.opentelemetry.io/otel/codes"
22-
"go.opentelemetry.io/otel/semconv/internal"
23-
"go.opentelemetry.io/otel/trace"
24-
)
25-
2617
// HTTP scheme attributes.
2718
var (
2819
HTTPSchemeHTTP = HTTPSchemeKey.String("http")
2920
HTTPSchemeHTTPS = HTTPSchemeKey.String("https")
3021
)
31-
32-
var sc = &internal.SemanticConventions{
33-
EnduserIDKey: EnduserIDKey,
34-
HTTPClientIPKey: HTTPClientIPKey,
35-
HTTPFlavorKey: HTTPFlavorKey,
36-
HTTPHostKey: HTTPHostKey,
37-
HTTPMethodKey: HTTPMethodKey,
38-
HTTPRequestContentLengthKey: HTTPRequestContentLengthKey,
39-
HTTPRouteKey: HTTPRouteKey,
40-
HTTPSchemeHTTP: HTTPSchemeHTTP,
41-
HTTPSchemeHTTPS: HTTPSchemeHTTPS,
42-
HTTPServerNameKey: HTTPServerNameKey,
43-
HTTPStatusCodeKey: HTTPStatusCodeKey,
44-
HTTPTargetKey: HTTPTargetKey,
45-
HTTPURLKey: HTTPURLKey,
46-
HTTPUserAgentKey: HTTPUserAgentKey,
47-
NetHostIPKey: NetHostIPKey,
48-
NetHostNameKey: NetHostNameKey,
49-
NetHostPortKey: NetHostPortKey,
50-
NetPeerIPKey: NetPeerIPKey,
51-
NetPeerNameKey: NetPeerNameKey,
52-
NetPeerPortKey: NetPeerPortKey,
53-
NetTransportIP: NetTransportIP,
54-
NetTransportOther: NetTransportOther,
55-
NetTransportTCP: NetTransportTCP,
56-
NetTransportUDP: NetTransportUDP,
57-
NetTransportUnix: NetTransportUnix,
58-
}
59-
60-
// NetAttributesFromHTTPRequest generates attributes of the net
61-
// namespace as specified by the OpenTelemetry specification for a
62-
// span. The network parameter is a string that net.Dial function
63-
// from standard library can understand.
64-
func NetAttributesFromHTTPRequest(network string, request *http.Request) []attribute.KeyValue {
65-
return sc.NetAttributesFromHTTPRequest(network, request)
66-
}
67-
68-
// EndUserAttributesFromHTTPRequest generates attributes of the
69-
// enduser namespace as specified by the OpenTelemetry specification
70-
// for a span.
71-
func EndUserAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue {
72-
return sc.EndUserAttributesFromHTTPRequest(request)
73-
}
74-
75-
// HTTPClientAttributesFromHTTPRequest generates attributes of the
76-
// http namespace as specified by the OpenTelemetry specification for
77-
// a span on the client side.
78-
func HTTPClientAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue {
79-
return sc.HTTPClientAttributesFromHTTPRequest(request)
80-
}
81-
82-
// HTTPServerMetricAttributesFromHTTPRequest generates low-cardinality attributes
83-
// to be used with server-side HTTP metrics.
84-
func HTTPServerMetricAttributesFromHTTPRequest(serverName string, request *http.Request) []attribute.KeyValue {
85-
return sc.HTTPServerMetricAttributesFromHTTPRequest(serverName, request)
86-
}
87-
88-
// HTTPServerAttributesFromHTTPRequest generates attributes of the
89-
// http namespace as specified by the OpenTelemetry specification for
90-
// a span on the server side. Currently, only basic authentication is
91-
// supported.
92-
func HTTPServerAttributesFromHTTPRequest(serverName, route string, request *http.Request) []attribute.KeyValue {
93-
return sc.HTTPServerAttributesFromHTTPRequest(serverName, route, request)
94-
}
95-
96-
// HTTPAttributesFromHTTPStatusCode generates attributes of the http
97-
// namespace as specified by the OpenTelemetry specification for a
98-
// span.
99-
func HTTPAttributesFromHTTPStatusCode(code int) []attribute.KeyValue {
100-
return sc.HTTPAttributesFromHTTPStatusCode(code)
101-
}
102-
103-
// SpanStatusFromHTTPStatusCode generates a status code and a message
104-
// as specified by the OpenTelemetry specification for a span.
105-
func SpanStatusFromHTTPStatusCode(code int) (codes.Code, string) {
106-
return internal.SpanStatusFromHTTPStatusCode(code)
107-
}
108-
109-
// SpanStatusFromHTTPStatusCodeAndSpanKind generates a status code and a message
110-
// as specified by the OpenTelemetry specification for a span.
111-
// Exclude 4xx for SERVER to set the appropriate status.
112-
func SpanStatusFromHTTPStatusCodeAndSpanKind(code int, spanKind trace.SpanKind) (codes.Code, string) {
113-
return internal.SpanStatusFromHTTPStatusCodeAndSpanKind(code, spanKind)
114-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package httpconv provides OpenTelemetry semantic convetions for the net/http
16+
// package from the standard library.
17+
package httpconv // import "go.opentelemetry.io/otel/semconv/{{.TagVer}}/httpconv"
18+
19+
import (
20+
"net/http"
21+
22+
"go.opentelemetry.io/otel/attribute"
23+
"go.opentelemetry.io/otel/codes"
24+
"go.opentelemetry.io/otel/semconv/internal/v2"
25+
semconv "go.opentelemetry.io/otel/semconv/{{.TagVer}}"
26+
)
27+
28+
var (
29+
nc = &internal.NetConv{
30+
NetHostNameKey: semconv.NetHostNameKey,
31+
NetHostPortKey: semconv.NetHostPortKey,
32+
NetPeerNameKey: semconv.NetPeerNameKey,
33+
NetPeerPortKey: semconv.NetPeerPortKey,
34+
NetSockPeerAddrKey: semconv.NetSockPeerAddrKey,
35+
NetSockPeerPortKey: semconv.NetSockPeerPortKey,
36+
NetTransportOther: semconv.NetTransportOther,
37+
NetTransportTCP: semconv.NetTransportTCP,
38+
NetTransportUDP: semconv.NetTransportUDP,
39+
NetTransportInProc: semconv.NetTransportInProc,
40+
}
41+
42+
hc = &internal.HTTPConv{
43+
NetConv: nc,
44+
45+
EnduserIDKey: semconv.EnduserIDKey,
46+
HTTPClientIPKey: semconv.HTTPClientIPKey,
47+
HTTPFlavorKey: semconv.HTTPFlavorKey,
48+
HTTPMethodKey: semconv.HTTPMethodKey,
49+
HTTPRequestContentLengthKey: semconv.HTTPRequestContentLengthKey,
50+
HTTPResponseContentLengthKey: semconv.HTTPResponseContentLengthKey,
51+
HTTPRouteKey: semconv.HTTPRouteKey,
52+
HTTPSchemeHTTP: semconv.HTTPSchemeHTTP,
53+
HTTPSchemeHTTPS: semconv.HTTPSchemeHTTPS,
54+
HTTPStatusCodeKey: semconv.HTTPStatusCodeKey,
55+
HTTPTargetKey: semconv.HTTPTargetKey,
56+
HTTPURLKey: semconv.HTTPURLKey,
57+
HTTPUserAgentKey: semconv.HTTPUserAgentKey,
58+
}
59+
)
60+
61+
// ClientResponse returns attributes for an HTTP response received by a client
62+
// from a server. It will return the following attributes if the related values
63+
// are defined in resp: "http.status.code", "http.response_content_length".
64+
//
65+
// This does not add all OpenTelemetry required attributes for an HTTP event,
66+
// it assumes ClientRequest was used to create the span with a complete set of
67+
// attributes. If a complete set of attributes can be generated using the
68+
// request contained in resp. For example:
69+
//
70+
// append(ClientResponse(resp), ClientRequest(resp.Request)...)
71+
func ClientResponse(resp http.Response) []attribute.KeyValue {
72+
return hc.ClientResponse(resp)
73+
}
74+
75+
// ClientRequest returns attributes for an HTTP request made by a client. The
76+
// following attributes are always returned: "http.url", "http.flavor",
77+
// "http.method", "net.peer.name". The following attributes are returned if the
78+
// related values are defined in req: "net.peer.port", "http.user_agent",
79+
// "http.request_content_length", "enduser.id".
80+
func ClientRequest(req *http.Request) []attribute.KeyValue {
81+
return hc.ClientRequest(req)
82+
}
83+
84+
// ClientStatus returns a span status code and message for an HTTP status code
85+
// value received by a client.
86+
func ClientStatus(code int) (codes.Code, string) {
87+
return hc.ClientStatus(code)
88+
}
89+
90+
// ServerRequest returns attributes for an HTTP request received by a server.
91+
// The following attributes are always returned: "http.method", "http.scheme",
92+
// "http.flavor", "http.target", "net.host.name". The following attributes are
93+
// returned if they related values are defined in req: "net.host.port",
94+
// "net.sock.peer.addr", "net.sock.peer.port", "http.user_agent", "enduser.id",
95+
// "http.client_ip".
96+
func ServerRequest(req *http.Request) []attribute.KeyValue {
97+
return hc.ServerRequest(req)
98+
}
99+
100+
// ServerStatus returns a span status code and message for an HTTP status code
101+
// value returned by a server. Status codes in the 400-499 range are not
102+
// returned as errors.
103+
func ServerStatus(code int) (codes.Code, string) {
104+
return hc.ServerStatus(code)
105+
}
106+
107+
// RequestHeader returns the contents of h as attributes.
108+
//
109+
// Instrumentation should require an explicit configuration of which headers to
110+
// captured and then prune what they pass here. Including all headers can be a
111+
// security risk - explicit configuration helps avoid leaking sensitive
112+
// information.
113+
//
114+
// The User-Agent header is already captured in the http.user_agent attribute
115+
// from ClientRequest and ServerRequest. Instrumentation may provide an option
116+
// to capture that header here even though it is not recommended. Otherwise,
117+
// instrumentation should filter that out of what is passed.
118+
func RequestHeader(h http.Header) []attribute.KeyValue {
119+
return hc.RequestHeader(h)
120+
}
121+
122+
// ResponseHeader returns the contents of h as attributes.
123+
//
124+
// Instrumentation should require an explicit configuration of which headers to
125+
// captured and then prune what they pass here. Including all headers can be a
126+
// security risk - explicit configuration helps avoid leaking sensitive
127+
// information.
128+
//
129+
// The User-Agent header is already captured in the http.user_agent attribute
130+
// from ClientRequest and ServerRequest. Instrumentation may provide an option
131+
// to capture that header here even though it is not recommended. Otherwise,
132+
// instrumentation should filter that out of what is passed.
133+
func ResponseHeader(h http.Header) []attribute.KeyValue {
134+
return hc.ResponseHeader(h)
135+
}

0 commit comments

Comments
 (0)