Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add semantic convention for specification 1.4.0 #1890

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions semconv/v1_4_0/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package semconv implements OpenTelemetry semantic conventions start from specification
// version 1.4.0 and until the next version that introduced any changes.
Comment on lines +15 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Package semconv implements OpenTelemetry semantic conventions start from specification
// version 1.4.0 and until the next version that introduced any changes.
// Package semconv/v1_4_0 implements v1.4.0 of the OpenTelemetry semantic conventions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that valid? Or should it be "Package v1_4_0 implements..."?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure. I was going off this https://pkg.go.dev/golang.org/x/sys/unix

The sys/unix package provides...

I'm go with the other way as well.

//
// This package is currently in a pre-GA phase. Backwards incompatible changes
// may be introduced in subsequent minor version releases as we work to track
// the evolving OpenTelemetry specification and user feedback.
//
// OpenTelemetry semantic conventions are agreed standardized naming
// patterns for OpenTelemetry things. This package aims to be the
// centralized place to interact with these conventions.
//
// Example usage:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aneurysm9 @MrAlias see this example.

//
// import semconv "go.opentelemetry.io/otel/semconv/v1_4_0"
// ...
// // Get a Tracer associcated with the Schema URL matching the semantic conventions
// // that we want to use.
// tracer := provider.Tracer("example_library", trace.WithSchemaURL(semconv.SchemaURL))
// ...
// // Crate a Span.
// var span trace.Span
// _, span = tracer.Start(
// context.Background(),
// "operation",
// // Note that here we use the semantic conventon for HostName that matches
// // the Schema URL that we used in the Tracer() call.
// trace.WithAttributes(semconv.HostNameKey.String("example.com")),
// )
// span.End()
//
package v1_4_0

// Note: semantic conventions are immutable. They can only change if a new specification
// version is introduced. If you need to change a semantic convention definition in this
// package it means there is a new specification version that introduced the change.
// In that case copy this package, give it a new name that corresponds to the new version
// number and modify the semantic convention definitions.
// Important: make sure to update SchemaURL string correspondingly.
41 changes: 41 additions & 0 deletions semconv/v1_4_0/exception.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1_4_0

import (
"go.opentelemetry.io/otel/semconv"
)

// Semantic conventions for exception attribute keys.
const (
// The Go type containing the error or exception.
ExceptionTypeKey = semconv.ExceptionEscapedKey

// The exception message.
ExceptionMessageKey = semconv.ExceptionMessageKey

// A stacktrace as a string. This most commonly will come from
// "runtime/debug".Stack.
ExceptionStacktraceKey = semconv.ExceptionStacktraceKey

// If the exception event is recorded at a point where it is known
// that the exception is escaping the scope of the span this
// attribute is set to true.
ExceptionEscapedKey = semconv.ExceptionEscapedKey
)

const (
// ExceptionEventName is the name of the Span event representing an exception.
ExceptionEventName = semconv.ExceptionEventName
)
51 changes: 51 additions & 0 deletions semconv/v1_4_0/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v1_4_0

import (
"net/http"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/semconv"
)

func NetAttributesFromHTTPRequest(network string, request *http.Request) []attribute.KeyValue {
return semconv.NetAttributesFromHTTPRequest(network, request)
}

func EndUserAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue {
return semconv.EndUserAttributesFromHTTPRequest(request)
}

func HTTPClientAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue {
return semconv.HTTPClientAttributesFromHTTPRequest(request)
}

func HTTPServerMetricAttributesFromHTTPRequest(serverName string, request *http.Request) []attribute.KeyValue {
return semconv.HTTPServerMetricAttributesFromHTTPRequest(serverName, request)
}

func HTTPServerAttributesFromHTTPRequest(serverName, route string, request *http.Request) []attribute.KeyValue {
return semconv.HTTPServerAttributesFromHTTPRequest(serverName, route, request)
}

func HTTPAttributesFromHTTPStatusCode(code int) []attribute.KeyValue {
return semconv.HTTPAttributesFromHTTPStatusCode(code)
}

func SpanStatusFromHTTPStatusCode(code int) (codes.Code, string) {
return semconv.SpanStatusFromHTTPStatusCode(code)
}
Loading