forked from open-telemetry/opentelemetry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add semantic conventions generation Make target (open-telemetry#2758)
* No wrap RELEASING Semantic Convention Generation section * Initial generator * Update template render * Add exception and schema templates * Add semconv/internal http unification * Add http template * Add licenses header * Embed the templates * Update static version in schema tmpl * Add semconv-generate target to Makefile Use this target to generate versions of the semconv packages. * Generate semconv packages * Update RELEASING to use make semconv-generate * Add comments to semconvkit * Make SemVer a method instead of a field * Remove semconv/v* from codecov * Fix lint for semconvkit main.go * Fix documentation of validateHTTPStatusCode Co-authored-by: Chester Cheung <[email protected]>
- Loading branch information
1 parent
33a4673
commit db7fd1b
Showing
16 changed files
with
809 additions
and
4,609 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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 semconvkit is used to generate opentelemetry-go specific semantic | ||
// convention code. It is expected to be used in with the semconvgen utility | ||
// (go.opentelemetry.io/build-tools/semconvgen) to completely generate | ||
// versioned sub-packages of go.opentelemetry.io/otel/semconv. | ||
package main | ||
|
||
import ( | ||
"embed" | ||
"flag" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
var ( | ||
out = flag.String("output", "./", "output directory") | ||
tag = flag.String("tag", "", "OpenTelemetry tagged version") | ||
|
||
//go:embed templates/*.tmpl | ||
rootFS embed.FS | ||
) | ||
|
||
// SemanticConventions are information about the semantic conventions being | ||
// generated. | ||
type SemanticConventions struct { | ||
// TagVer is the tagged version (i.e. v1.7.0 and not 1.7.0). | ||
TagVer string | ||
} | ||
|
||
func (sc SemanticConventions) SemVer() string { | ||
return strings.TrimPrefix(*tag, "v") | ||
} | ||
|
||
// render renders all templates to the dest directory using the data. | ||
func render(dest string, data *SemanticConventions) error { | ||
tmpls, err := template.ParseFS(rootFS, "templates/*.tmpl") | ||
if err != nil { | ||
return err | ||
} | ||
for _, tmpl := range tmpls.Templates() { | ||
target := filepath.Join(dest, strings.TrimSuffix(tmpl.Name(), ".tmpl")) | ||
wr, err := os.Create(target) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = tmpl.Execute(wr, data) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
if *tag == "" { | ||
log.Fatalf("invalid tag: %q", *tag) | ||
} | ||
|
||
sc := &SemanticConventions{TagVer: *tag} | ||
|
||
if err := render(*out, sc); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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. | ||
// | ||
// OpenTelemetry semantic conventions are agreed standardized naming | ||
// patterns for OpenTelemetry things. This package represents the conventions | ||
// as of the {{.TagVer}} version of the OpenTelemetry specification. | ||
package semconv // import "go.opentelemetry.io/otel/semconv/{{.TagVer}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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 // import "go.opentelemetry.io/otel/semconv/{{.TagVer}}" | ||
|
||
const ( | ||
// ExceptionEventName is the name of the Span event representing an exception. | ||
ExceptionEventName = "exception" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// 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 // import "go.opentelemetry.io/otel/semconv/{{.TagVer}}" | ||
|
||
import ( | ||
"net/http" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/codes" | ||
"go.opentelemetry.io/otel/semconv/internal" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
// HTTP scheme attributes. | ||
var ( | ||
HTTPSchemeHTTP = HTTPSchemeKey.String("http") | ||
HTTPSchemeHTTPS = HTTPSchemeKey.String("https") | ||
) | ||
|
||
var sc = &internal.SemanticConventions{ | ||
EnduserIDKey: EnduserIDKey, | ||
HTTPClientIPKey: HTTPClientIPKey, | ||
HTTPFlavorKey: HTTPFlavorKey, | ||
HTTPHostKey: HTTPHostKey, | ||
HTTPMethodKey: HTTPMethodKey, | ||
HTTPRequestContentLengthKey: HTTPRequestContentLengthKey, | ||
HTTPRouteKey: HTTPRouteKey, | ||
HTTPSchemeHTTP: HTTPSchemeHTTP, | ||
HTTPSchemeHTTPS: HTTPSchemeHTTPS, | ||
HTTPServerNameKey: HTTPServerNameKey, | ||
HTTPStatusCodeKey: HTTPStatusCodeKey, | ||
HTTPTargetKey: HTTPTargetKey, | ||
HTTPURLKey: HTTPURLKey, | ||
HTTPUserAgentKey: HTTPUserAgentKey, | ||
NetHostIPKey: NetHostIPKey, | ||
NetHostNameKey: NetHostNameKey, | ||
NetHostPortKey: NetHostPortKey, | ||
NetPeerIPKey: NetPeerIPKey, | ||
NetPeerNameKey: NetPeerNameKey, | ||
NetPeerPortKey: NetPeerPortKey, | ||
NetTransportIP: NetTransportIP, | ||
NetTransportOther: NetTransportOther, | ||
NetTransportTCP: NetTransportTCP, | ||
NetTransportUDP: NetTransportUDP, | ||
NetTransportUnix: NetTransportUnix, | ||
} | ||
|
||
// NetAttributesFromHTTPRequest generates attributes of the net | ||
// namespace as specified by the OpenTelemetry specification for a | ||
// span. The network parameter is a string that net.Dial function | ||
// from standard library can understand. | ||
func NetAttributesFromHTTPRequest(network string, request *http.Request) []attribute.KeyValue { | ||
return sc.NetAttributesFromHTTPRequest(network, request) | ||
} | ||
|
||
// EndUserAttributesFromHTTPRequest generates attributes of the | ||
// enduser namespace as specified by the OpenTelemetry specification | ||
// for a span. | ||
func EndUserAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue { | ||
return sc.EndUserAttributesFromHTTPRequest(request) | ||
} | ||
|
||
// HTTPClientAttributesFromHTTPRequest generates attributes of the | ||
// http namespace as specified by the OpenTelemetry specification for | ||
// a span on the client side. | ||
func HTTPClientAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue { | ||
return sc.HTTPClientAttributesFromHTTPRequest(request) | ||
} | ||
|
||
// HTTPServerMetricAttributesFromHTTPRequest generates low-cardinality attributes | ||
// to be used with server-side HTTP metrics. | ||
func HTTPServerMetricAttributesFromHTTPRequest(serverName string, request *http.Request) []attribute.KeyValue { | ||
return sc.HTTPServerMetricAttributesFromHTTPRequest(serverName, request) | ||
} | ||
|
||
// HTTPServerAttributesFromHTTPRequest generates attributes of the | ||
// http namespace as specified by the OpenTelemetry specification for | ||
// a span on the server side. Currently, only basic authentication is | ||
// supported. | ||
func HTTPServerAttributesFromHTTPRequest(serverName, route string, request *http.Request) []attribute.KeyValue { | ||
return sc.HTTPServerAttributesFromHTTPRequest(serverName, route, request) | ||
} | ||
|
||
// HTTPAttributesFromHTTPStatusCode generates attributes of the http | ||
// namespace as specified by the OpenTelemetry specification for a | ||
// span. | ||
func HTTPAttributesFromHTTPStatusCode(code int) []attribute.KeyValue { | ||
return sc.HTTPAttributesFromHTTPStatusCode(code) | ||
} | ||
|
||
// SpanStatusFromHTTPStatusCode generates a status code and a message | ||
// as specified by the OpenTelemetry specification for a span. | ||
func SpanStatusFromHTTPStatusCode(code int) (codes.Code, string) { | ||
return internal.SpanStatusFromHTTPStatusCode(code) | ||
} | ||
|
||
// SpanStatusFromHTTPStatusCodeAndSpanKind generates a status code and a message | ||
// as specified by the OpenTelemetry specification for a span. | ||
// Exclude 4xx for SERVER to set the appropriate status. | ||
func SpanStatusFromHTTPStatusCodeAndSpanKind(code int, spanKind trace.SpanKind) (codes.Code, string) { | ||
return internal.SpanStatusFromHTTPStatusCodeAndSpanKind(code, spanKind) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// 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 // import "go.opentelemetry.io/otel/semconv/{{.TagVer}}" | ||
|
||
// SchemaURL is the schema URL that matches the version of the semantic conventions | ||
// that this package defines. Semconv packages starting from v1.4.0 must declare | ||
// non-empty schema URL in the form https://opentelemetry.io/schemas/<version> | ||
const SchemaURL = "https://opentelemetry.io/schemas/{{.SemVer}}" |
Oops, something went wrong.