Skip to content

Commit

Permalink
otelhttptrace: remove references to semconv v1.24
Browse files Browse the repository at this point in the history
  • Loading branch information
dotwaffle committed May 19, 2024
1 parent a1001cf commit 4876128
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
28 changes: 20 additions & 8 deletions instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
"go.opentelemetry.io/otel/trace"
)

Expand All @@ -40,6 +39,19 @@ var (
HTTPDNSAddrs = attribute.Key("http.dns.addrs")
)

// TLS attributes.
//
// From https://opentelemetry.io/docs/specs/semconv/attributes-registry/tls/ but only present from semconv v1.24.
var (
TLSCipher = attribute.Key("tls.cipher")
TLSProtocolVersion = attribute.Key("tls.protocol.version")
TLSResumed = attribute.Key("tls.resumed")
TLSServerCertificateChain = attribute.Key("tls.server.certificate_chain")
TLSServerHashSha256 = attribute.Key("tls.server.hash.sha256")
TLSServerNotAfter = attribute.Key("tls.server.not_after")
TLSServerNotBefore = attribute.Key("tls.server.not_before")
)

var hookMap = map[string]string{
"http.dns": "http.getconn",
"http.connect": "http.getconn",
Expand Down Expand Up @@ -323,9 +335,9 @@ func (ct *clientTracer) tlsHandshakeStart() {
func (ct *clientTracer) tlsHandshakeDone(state tls.ConnectionState, err error) {
attrs := make([]attribute.KeyValue, 0, 7)
attrs = append(attrs,
semconv.TLSCipher(tls.CipherSuiteName(state.CipherSuite)),
semconv.TLSProtocolVersion(tls.VersionName(state.Version)),
semconv.TLSResumed(state.DidResume),
TLSCipher.String(tls.CipherSuiteName(state.CipherSuite)),
TLSProtocolVersion.String(tls.VersionName(state.Version)),
TLSResumed.Bool(state.DidResume),
)

if len(state.PeerCertificates) > 0 {
Expand All @@ -336,10 +348,10 @@ func (ct *clientTracer) tlsHandshakeDone(state tls.ConnectionState, err error) {

leafCert := state.PeerCertificates[0]
attrs = append(attrs,
semconv.TLSServerCertificateChain(certChain...),
semconv.TLSServerHashSha256(fmt.Sprintf("%X", sha256.Sum256(leafCert.Raw))),
semconv.TLSServerNotAfter(leafCert.NotAfter.UTC().Format(time.RFC3339)),
semconv.TLSServerNotBefore(leafCert.NotBefore.UTC().Format(time.RFC3339)),
TLSServerCertificateChain.StringSlice(certChain),
TLSServerHashSha256.String(fmt.Sprintf("%X", sha256.Sum256(leafCert.Raw))),
TLSServerNotAfter.String(leafCert.NotAfter.UTC().Format(time.RFC3339)),
TLSServerNotBefore.String(leafCert.NotBefore.UTC().Format(time.RFC3339)),
)
}
ct.end("http.tls", err, attrs...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
semconv "go.opentelemetry.io/otel/semconv/v1.20.0"
"go.opentelemetry.io/otel/trace"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/baggage"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
semconv "go.opentelemetry.io/otel/semconv/v1.20.0"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
)

func getSpanFromRecorder(sr *tracetest.SpanRecorder, name string) (trace.ReadOnlySpan, bool) {
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestHTTPRequestWithClientTrace(t *testing.T) {
}
attrs = slices.DeleteFunc(attrs, func(a attribute.KeyValue) bool {
// Skip keys that are unable to be detected beforehand.
if a.Key == semconv.TLSCipherKey || a.Key == semconv.TLSProtocolVersionKey {
if a.Key == otelhttptrace.TLSCipher || a.Key == otelhttptrace.TLSProtocolVersion {
return true
}
return false
Expand Down

0 comments on commit 4876128

Please sign in to comment.