├── .gitattributes ├── schema ├── v1.0 │ ├── testdata │ │ ├── invalid-schema-url.yaml │ │ └── unsupported-file-format.yaml │ ├── types │ │ └── types.go │ └── ast │ │ ├── logs.go │ │ ├── common.go │ │ └── metrics.go ├── README.md └── go.sum ├── .gitmodules ├── exporters ├── jaeger │ ├── internal │ │ ├── gen-go │ │ │ ├── agent │ │ │ │ ├── GoUnusedProtection__.go │ │ │ │ └── agent-consts.go │ │ │ ├── jaeger │ │ │ │ ├── GoUnusedProtection__.go │ │ │ │ └── jaeger-consts.go │ │ │ └── zipkincore │ │ │ │ ├── GoUnusedProtection__.go │ │ │ │ └── zipkincore-consts.go │ │ └── third_party │ │ │ └── thrift │ │ │ ├── NOTICE │ │ │ └── lib │ │ │ └── go │ │ │ └── thrift │ │ │ ├── context.go │ │ │ ├── protocol_factory.go │ │ │ ├── messagetype.go │ │ │ ├── socket_windows_conn.go │ │ │ ├── server.go │ │ │ ├── server_transport.go │ │ │ ├── transport_factory.go │ │ │ └── type.go │ ├── doc.go │ ├── assertsocketbuffersize_windows_test.go │ ├── assertsocketbuffersize_test.go │ └── env.go ├── prometheus │ ├── README.md │ ├── sanitize.go │ └── sanitize_test.go ├── zipkin │ ├── doc.go │ └── env.go ├── stdout │ ├── stdouttrace │ │ └── doc.go │ └── stdoutmetric │ │ ├── doc.go │ │ └── exporter.go └── otlp │ ├── otlptrace │ ├── otlptracehttp │ │ ├── doc.go │ │ └── exporter.go │ ├── internal │ │ ├── tracetransform │ │ │ ├── resource.go │ │ │ ├── instrumentation.go │ │ │ └── resource_test.go │ │ └── otlpconfig │ │ │ ├── tls.go │ │ │ └── optiontypes.go │ └── otlptracegrpc │ │ └── exporter.go │ ├── otlpmetric │ ├── otlpmetrichttp │ │ ├── doc.go │ │ └── exporter.go │ ├── internal │ │ ├── metrictransform │ │ │ ├── resource.go │ │ │ └── resource_test.go │ │ └── otlpconfig │ │ │ └── tls.go │ ├── otlpmetricgrpc │ │ └── exporter.go │ └── options.go │ └── internal │ └── retry │ └── go.sum ├── .markdown-link.json ├── .gitignore ├── .markdownlint.yaml ├── .github ├── codecov.yaml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── gosec.yml │ ├── dependabot.yml │ ├── codeql-analysis.yml │ ├── changelog.yml │ └── markdown.yml ├── CODEOWNERS ├── metric ├── number │ ├── kind_string.go │ └── doc.go ├── unit │ ├── unit.go │ └── doc.go ├── sdkapi │ ├── instrumentkind_string.go │ ├── descriptor_test.go │ ├── sdkapi_test.go │ └── instrumentkind_test.go ├── noop_test.go ├── noop.go ├── metrictest │ └── alignment_test.go ├── global │ └── metric_test.go └── go.sum ├── internal ├── matchers │ ├── package.go │ ├── temporal_matcher.go │ └── expecter.go ├── global │ ├── internal_logging_test.go │ ├── benchmark_test.go │ └── state_test.go ├── internaltest │ └── errors.go ├── metric │ ├── registry │ │ └── doc.go │ ├── global │ │ ├── internal_test.go │ │ ├── state_test.go │ │ └── benchmark_test.go │ └── go.sum ├── trace │ └── noop │ │ └── noop.go ├── tools │ └── tools.go ├── rawhelpers.go └── baggage │ └── baggage.go ├── example ├── otel-collector │ └── k8s │ │ ├── namespace.yaml │ │ ├── jaeger.yaml │ │ ├── prometheus-service.yaml │ │ └── prometheus-monitor.yaml ├── zipkin │ ├── Dockerfile │ ├── README.md │ └── docker-compose.yml ├── fib │ ├── fib.go │ └── go.sum ├── namedtracer │ ├── foo │ │ └── foo.go │ └── go.sum ├── passthrough │ ├── README.md │ └── go.sum └── jaeger │ └── go.sum ├── bridge ├── opentracing │ ├── internal │ │ └── doc.go │ ├── migration │ │ └── defer.go │ ├── go.sum │ └── util.go └── opencensus │ ├── internal │ ├── handler.go │ ├── oc2otel │ │ ├── span_context.go │ │ ├── attributes.go │ │ ├── tracer_start_options.go │ │ ├── attributes_test.go │ │ └── tracer_start_options_test.go │ └── otel2oc │ │ └── span_context.go │ └── doc.go ├── attribute ├── doc.go └── type_string.go ├── version.go ├── sdk ├── metric │ ├── export │ │ └── aggregation │ │ │ └── temporality_string.go │ ├── atomicfields.go │ ├── controller │ │ ├── basic │ │ │ └── config_test.go │ │ └── time │ │ │ └── time.go │ ├── alignment_test.go │ └── processor │ │ └── basic │ │ └── config.go ├── resource │ ├── export_os_release_darwin_test.go │ ├── export_unix_test.go │ ├── export_common_unix_test.go │ ├── export_windows_test.go │ ├── os_unsupported.go │ ├── doc.go │ └── export_test.go ├── trace │ ├── doc.go │ ├── util_test.go │ ├── evictedqueue.go │ ├── event.go │ └── link.go ├── instrumentation │ └── library.go ├── internal │ ├── internal.go │ └── sanitize.go └── export │ └── metric │ └── go.sum ├── semconv ├── v1.4.0 │ ├── exception.go │ ├── doc.go │ └── schema.go ├── v1.5.0 │ ├── exception.go │ ├── doc.go │ └── schema.go ├── v1.6.1 │ ├── exception.go │ ├── doc.go │ └── schema.go └── v1.7.0 │ ├── exception.go │ ├── doc.go │ └── schema.go ├── .golangci.yml ├── baggage ├── doc.go ├── context_test.go └── context.go ├── internal_logging_test.go ├── internal_logging.go ├── codes └── doc.go ├── propagation ├── trace_context_example_test.go └── doc.go ├── trace ├── nonrecording.go └── go.sum ├── version_test.go ├── propagation.go ├── trace_test.go ├── get_main_pkgs.sh ├── website_docs └── _index.md ├── error_handler.go ├── doc.go ├── go.sum └── trace.go /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | *.{cmd,[cC][mM][dD]} text eol=crlf 3 | *.{bat,[bB][aA][tT]} text eol=crlf 4 | -------------------------------------------------------------------------------- /schema/v1.0/testdata/invalid-schema-url.yaml: -------------------------------------------------------------------------------- 1 | file_format: 1.0.0 2 | 3 | schema_url: http://invalid url 4 | 5 | versions: 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "opentelemetry-proto"] 2 | path = exporters/otlp/internal/opentelemetry-proto 3 | url = https://github.com/open-telemetry/opentelemetry-proto 4 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/gen-go/agent/GoUnusedProtection__.go: -------------------------------------------------------------------------------- 1 | // Code generated by Thrift Compiler (0.14.1). DO NOT EDIT. 2 | 3 | package agent 4 | 5 | var GoUnusedProtection__ int; 6 | 7 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/gen-go/jaeger/GoUnusedProtection__.go: -------------------------------------------------------------------------------- 1 | // Code generated by Thrift Compiler (0.14.1). DO NOT EDIT. 2 | 3 | package jaeger 4 | 5 | var GoUnusedProtection__ int; 6 | 7 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/gen-go/zipkincore/GoUnusedProtection__.go: -------------------------------------------------------------------------------- 1 | // Code generated by Thrift Compiler (0.14.1). DO NOT EDIT. 2 | 3 | package zipkincore 4 | 5 | var GoUnusedProtection__ int; 6 | 7 | -------------------------------------------------------------------------------- /exporters/prometheus/README.md: -------------------------------------------------------------------------------- 1 | # OpenTelemetry-Go Prometheus Exporter 2 | 3 | OpenTelemetry Prometheus exporter 4 | 5 | ## Installation 6 | 7 | ``` 8 | go get -u go.opentelemetry.io/otel/exporters/prometheus 9 | ``` 10 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/third_party/thrift/NOTICE: -------------------------------------------------------------------------------- 1 | Apache Thrift 2 | Copyright (C) 2006 - 2019, The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /schema/v1.0/testdata/unsupported-file-format.yaml: -------------------------------------------------------------------------------- 1 | file_format: 1.1.0 2 | 3 | versions: 4 | 1.1.0: 5 | all: 6 | changes: 7 | - rename_attributes: 8 | k8s.cluster.name: kubernetes.cluster.name 9 | 1.0.0: 10 | -------------------------------------------------------------------------------- /.markdown-link.json: -------------------------------------------------------------------------------- 1 | { 2 | "ignorePatterns": [ 3 | { 4 | "pattern": "^http(s)?://localhost" 5 | } 6 | ], 7 | "replacementPatterns": [ 8 | { 9 | "pattern": "^/registry", 10 | "replacement": "https://opentelemetry.io/registry" 11 | } 12 | ], 13 | "retryOn429": true, 14 | "retryCount": 5, 15 | "fallbackRetryDelay": "30s" 16 | } 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Thumbs.db 3 | 4 | .tools/ 5 | .idea/ 6 | .vscode/ 7 | *.iml 8 | *.so 9 | coverage.* 10 | 11 | gen/ 12 | 13 | /example/fib/fib 14 | /example/jaeger/jaeger 15 | /example/namedtracer/namedtracer 16 | /example/opencensus/opencensus 17 | /example/passthrough/passthrough 18 | /example/prometheus/prometheus 19 | /example/prom-collector/prom-collector 20 | /example/zipkin/zipkin 21 | /example/otel-collector/otel-collector 22 | -------------------------------------------------------------------------------- /.markdownlint.yaml: -------------------------------------------------------------------------------- 1 | # Default state for all rules 2 | default: true 3 | 4 | # ul-style 5 | MD004: false 6 | 7 | # hard-tabs 8 | MD010: false 9 | 10 | # line-length 11 | MD013: false 12 | 13 | # no-duplicate-header 14 | MD024: 15 | siblings_only: true 16 | 17 | #single-title 18 | MD025: false 19 | 20 | # ol-prefix 21 | MD029: 22 | style: ordered 23 | 24 | # no-inline-html 25 | MD033: false 26 | 27 | # fenced-code-language 28 | MD040: false 29 | 30 | -------------------------------------------------------------------------------- /.github/codecov.yaml: -------------------------------------------------------------------------------- 1 | codecov: 2 | require_ci_to_pass: yes 3 | 4 | ignore: 5 | - "exporters/jaeger/internal/gen-go/**/*" 6 | - "exporters/jaeger/internal/third_party/**/*" 7 | 8 | coverage: 9 | precision: 1 10 | round: down 11 | range: "70...100" 12 | status: 13 | project: 14 | default: 15 | target: auto 16 | threshold: 0.5% 17 | 18 | comment: 19 | layout: "reach,diff,flags,tree" 20 | behavior: default 21 | require_changes: yes 22 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/gen-go/jaeger/jaeger-consts.go: -------------------------------------------------------------------------------- 1 | // Code generated by Thrift Compiler (0.14.1). DO NOT EDIT. 2 | 3 | package jaeger 4 | 5 | import ( 6 | "bytes" 7 | "context" 8 | "fmt" 9 | "time" 10 | 11 | "go.opentelemetry.io/otel/exporters/jaeger/internal/third_party/thrift/lib/go/thrift" 12 | ) 13 | 14 | // (needed to ensure safety because of naive import list construction.) 15 | var _ = thrift.ZERO 16 | var _ = fmt.Printf 17 | var _ = context.Background 18 | var _ = time.Now 19 | var _ = bytes.Equal 20 | 21 | func init() { 22 | } 23 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | ##################################################### 2 | # 3 | # List of approvers for this repository 4 | # 5 | ##################################################### 6 | # 7 | # Learn about membership in OpenTelemetry community: 8 | # https://github.com/open-telemetry/community/blob/main/community-membership.md 9 | # 10 | # 11 | # Learn about CODEOWNERS file format: 12 | # https://help.github.com/en/articles/about-code-owners 13 | # 14 | 15 | * @jmacd @MrAlias @Aneurysm9 @evantorrie @XSAM @dashpole @paivagustavo @MadVikingGod @pellared 16 | 17 | CODEOWNERS @MrAlias @Aneurysm9 @MadVikingGod 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report of invalid behavior to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Description 11 | 12 | A clear and concise description of what the bug is. 13 | 14 | ### Environment 15 | 16 | - OS: [e.g. iOS] 17 | - Architecture: [e.g. x86, i386] 18 | - Go Version: [e.g. 1.15] 19 | - opentelemetry-go version: [e.g. v0.14.0, 3c7face] 20 | 21 | ### Steps To Reproduce 22 | 23 | 1. Use the configuration '...' 24 | 2. Run '...' 25 | 3. See error 26 | 27 | ### Expected behavior 28 | 29 | A clear and concise description of what you expected to happen. 30 | -------------------------------------------------------------------------------- /metric/number/kind_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=Kind"; DO NOT EDIT. 2 | 3 | package number 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[Int64Kind-0] 12 | _ = x[Float64Kind-1] 13 | } 14 | 15 | const _Kind_name = "Int64KindFloat64Kind" 16 | 17 | var _Kind_index = [...]uint8{0, 9, 20} 18 | 19 | func (i Kind) String() string { 20 | if i < 0 || i >= Kind(len(_Kind_index)-1) { 21 | return "Kind(" + strconv.FormatInt(int64(i), 10) + ")" 22 | } 23 | return _Kind_name[_Kind_index[i]:_Kind_index[i+1]] 24 | } 25 | -------------------------------------------------------------------------------- /internal/matchers/package.go: -------------------------------------------------------------------------------- 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 matchers // import "go.opentelemetry.io/otel/internal/matchers" 16 | -------------------------------------------------------------------------------- /example/otel-collector/k8s/namespace.yaml: -------------------------------------------------------------------------------- 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 | apiVersion: v1 16 | kind: Namespace 17 | metadata: 18 | name: observability 19 | -------------------------------------------------------------------------------- /bridge/opentracing/internal/doc.go: -------------------------------------------------------------------------------- 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 internal // import "go.opentelemetry.io/otel/bridge/opentracing/internal" 16 | -------------------------------------------------------------------------------- /example/otel-collector/k8s/jaeger.yaml: -------------------------------------------------------------------------------- 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 | apiVersion: jaegertracing.io/v1 16 | kind: Jaeger 17 | metadata: 18 | name: jaeger 19 | namespace: observability -------------------------------------------------------------------------------- /exporters/jaeger/internal/gen-go/agent/agent-consts.go: -------------------------------------------------------------------------------- 1 | // Code generated by Thrift Compiler (0.14.1). DO NOT EDIT. 2 | 3 | package agent 4 | 5 | import ( 6 | "bytes" 7 | "context" 8 | "fmt" 9 | "time" 10 | 11 | "go.opentelemetry.io/otel/exporters/jaeger/internal/gen-go/jaeger" 12 | "go.opentelemetry.io/otel/exporters/jaeger/internal/gen-go/zipkincore" 13 | "go.opentelemetry.io/otel/exporters/jaeger/internal/third_party/thrift/lib/go/thrift" 14 | ) 15 | 16 | // (needed to ensure safety because of naive import list construction.) 17 | var _ = thrift.ZERO 18 | var _ = fmt.Printf 19 | var _ = context.Background 20 | var _ = time.Now 21 | var _ = bytes.Equal 22 | 23 | var _ = jaeger.GoUnusedProtection__ 24 | var _ = zipkincore.GoUnusedProtection__ 25 | 26 | func init() { 27 | } 28 | -------------------------------------------------------------------------------- /attribute/doc.go: -------------------------------------------------------------------------------- 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 attribute provides key and value attributes. 16 | package attribute // import "go.opentelemetry.io/otel/attribute" 17 | -------------------------------------------------------------------------------- /exporters/jaeger/doc.go: -------------------------------------------------------------------------------- 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 jaeger contains an OpenTelemetry tracing exporter for Jaeger. 16 | package jaeger // import "go.opentelemetry.io/otel/exporters/jaeger" 17 | -------------------------------------------------------------------------------- /exporters/zipkin/doc.go: -------------------------------------------------------------------------------- 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 zipkin contains an OpenTelemetry tracing exporter for Zipkin. 16 | package zipkin // import "go.opentelemetry.io/otel/exporters/zipkin" 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Problem Statement 11 | 12 | A clear and concise description of what the problem is. 13 | Ex. I'm always frustrated when [...] 14 | 15 | ### Proposed Solution 16 | 17 | A clear and concise description of what you want to happen. 18 | 19 | #### Alternatives 20 | 21 | A clear and concise description of any alternative solutions or features you've considered. 22 | 23 | #### Prior Art 24 | 25 | A clear and concise list of any similar and existing solutions from other projects that provide context to possible solutions. 26 | 27 | ### Additional Context 28 | 29 | Add any other context or screenshots about the feature request here. 30 | -------------------------------------------------------------------------------- /version.go: -------------------------------------------------------------------------------- 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 otel // import "go.opentelemetry.io/otel" 16 | 17 | // Version is the current release version of OpenTelemetry in use. 18 | func Version() string { 19 | return "1.3.0" 20 | } 21 | -------------------------------------------------------------------------------- /sdk/metric/export/aggregation/temporality_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=Temporality"; DO NOT EDIT. 2 | 3 | package aggregation 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[CumulativeTemporality-1] 12 | _ = x[DeltaTemporality-2] 13 | } 14 | 15 | const _Temporality_name = "CumulativeTemporalityDeltaTemporality" 16 | 17 | var _Temporality_index = [...]uint8{0, 21, 37} 18 | 19 | func (i Temporality) String() string { 20 | i -= 1 21 | if i >= Temporality(len(_Temporality_index)-1) { 22 | return "Temporality(" + strconv.FormatInt(int64(i+1), 10) + ")" 23 | } 24 | return _Temporality_name[_Temporality_index[i]:_Temporality_index[i+1]] 25 | } 26 | -------------------------------------------------------------------------------- /.github/workflows/gosec.yml: -------------------------------------------------------------------------------- 1 | name: Run Gosec 2 | on: 3 | workflow_dispatch: 4 | schedule: 5 | # ┌───────────── minute (0 - 59) 6 | # │ ┌───────────── hour (0 - 23) 7 | # │ │ ┌───────────── day of the month (1 - 31) 8 | # │ │ │ ┌───────────── month (1 - 12 or JAN-DEC) 9 | # │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT) 10 | # │ │ │ │ │ 11 | # │ │ │ │ │ 12 | # │ │ │ │ │ 13 | # * * * * * 14 | - cron: '30 2 * * *' 15 | jobs: 16 | tests: 17 | runs-on: ubuntu-latest 18 | env: 19 | GO111MODULE: on 20 | steps: 21 | - name: Checkout Source 22 | uses: actions/checkout@v2 23 | - name: Run Gosec Security Scanner 24 | uses: securego/gosec@master 25 | with: 26 | args: ./... 27 | 28 | -------------------------------------------------------------------------------- /sdk/resource/export_os_release_darwin_test.go: -------------------------------------------------------------------------------- 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 resource // import "go.opentelemetry.io/otel/sdk/resource" 16 | 17 | var ( 18 | ParsePlistFile = parsePlistFile 19 | BuildOSRelease = buildOSRelease 20 | ) 21 | -------------------------------------------------------------------------------- /example/zipkin/Dockerfile: -------------------------------------------------------------------------------- 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 | FROM golang:1.16-alpine 15 | COPY . /go/src/github.com/open-telemetry/opentelemetry-go/ 16 | WORKDIR /go/src/github.com/open-telemetry/opentelemetry-go/example/zipkin/ 17 | RUN go install ./main.go 18 | CMD ["/go/bin/main"] 19 | -------------------------------------------------------------------------------- /semconv/v1.4.0/exception.go: -------------------------------------------------------------------------------- 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 semconv // import "go.opentelemetry.io/otel/semconv/v1.4.0" 16 | 17 | const ( 18 | // ExceptionEventName is the name of the Span event representing an exception. 19 | ExceptionEventName = "exception" 20 | ) 21 | -------------------------------------------------------------------------------- /semconv/v1.5.0/exception.go: -------------------------------------------------------------------------------- 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 semconv // import "go.opentelemetry.io/otel/semconv/v1.5.0" 16 | 17 | const ( 18 | // ExceptionEventName is the name of the Span event representing an exception. 19 | ExceptionEventName = "exception" 20 | ) 21 | -------------------------------------------------------------------------------- /semconv/v1.6.1/exception.go: -------------------------------------------------------------------------------- 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 semconv // import "go.opentelemetry.io/otel/semconv/v1.6.1" 16 | 17 | const ( 18 | // ExceptionEventName is the name of the Span event representing an exception. 19 | ExceptionEventName = "exception" 20 | ) 21 | -------------------------------------------------------------------------------- /semconv/v1.7.0/exception.go: -------------------------------------------------------------------------------- 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 semconv // import "go.opentelemetry.io/otel/semconv/v1.7.0" 16 | 17 | const ( 18 | // ExceptionEventName is the name of the Span event representing an exception. 19 | ExceptionEventName = "exception" 20 | ) 21 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | # See https://github.com/golangci/golangci-lint#config-file 2 | run: 3 | issues-exit-code: 1 #Default 4 | tests: true #Default 5 | 6 | linters: 7 | enable: 8 | - misspell 9 | - goimports 10 | - revive 11 | - gofmt 12 | 13 | issues: 14 | exclude-rules: 15 | # helpers in tests often (rightfully) pass a *testing.T as their first argument 16 | - path: _test\.go 17 | text: "context.Context should be the first parameter of a function" 18 | linters: 19 | - revive 20 | # Yes, they are, but it's okay in a test 21 | - path: _test\.go 22 | text: "exported func.*returns unexported type.*which can be annoying to use" 23 | linters: 24 | - revive 25 | 26 | linters-settings: 27 | misspell: 28 | locale: US 29 | ignore-words: 30 | - cancelled 31 | goimports: 32 | local-prefixes: go.opentelemetry.io 33 | -------------------------------------------------------------------------------- /exporters/stdout/stdouttrace/doc.go: -------------------------------------------------------------------------------- 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 stdout contains an OpenTelemetry exporter for tracing 16 | // telemetry to be written to an output destination as JSON. 17 | package stdouttrace // import "go.opentelemetry.io/otel/exporters/stdout/stdouttrace" 18 | -------------------------------------------------------------------------------- /.github/workflows/dependabot.yml: -------------------------------------------------------------------------------- 1 | name: Dependabot-Tidier 2 | on: 3 | pull_request: 4 | types: [ labeled ] 5 | 6 | jobs: 7 | mod_tidier: 8 | if: ${{ contains(github.event.pull_request.labels.*.name, 'dependencies') }} 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | with: 13 | ref: ${{ github.head_ref }} 14 | - uses: actions/setup-go@v2.1.5 15 | with: 16 | go-version: '^1.16.0' 17 | - uses: evantorrie/mott-the-tidier@v1-beta 18 | id: modtidy 19 | with: 20 | gomods: '**/go.mod' 21 | gomodsum_only: true 22 | - uses: stefanzweifel/git-auto-commit-action@v4 23 | id: autocommit 24 | with: 25 | commit_message: Auto-fix go.sum changes in dependent modules 26 | - name: changes 27 | run: | 28 | echo "Changes detected: ${{ steps.autocommit.outputs.changes_detected }}" 29 | -------------------------------------------------------------------------------- /metric/unit/unit.go: -------------------------------------------------------------------------------- 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 unit // import "go.opentelemetry.io/otel/metric/unit" 16 | 17 | type Unit string 18 | 19 | // Units defined by OpenTelemetry. 20 | const ( 21 | Dimensionless Unit = "1" 22 | Bytes Unit = "By" 23 | Milliseconds Unit = "ms" 24 | ) 25 | -------------------------------------------------------------------------------- /exporters/otlp/otlptrace/otlptracehttp/doc.go: -------------------------------------------------------------------------------- 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 | /* 16 | Package otlptracehttp a client that sends traces to the collector using HTTP 17 | with binary protobuf payloads. 18 | */ 19 | package otlptracehttp // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" 20 | -------------------------------------------------------------------------------- /baggage/doc.go: -------------------------------------------------------------------------------- 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 | /* 16 | Package baggage provides functionality for storing and retrieving 17 | baggage items in Go context. For propagating the baggage, see the 18 | go.opentelemetry.io/otel/propagation package. 19 | */ 20 | package baggage // import "go.opentelemetry.io/otel/baggage" 21 | -------------------------------------------------------------------------------- /internal/global/internal_logging_test.go: -------------------------------------------------------------------------------- 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 global 16 | 17 | import ( 18 | "log" 19 | "os" 20 | "testing" 21 | 22 | "github.com/go-logr/stdr" 23 | ) 24 | 25 | func TestRace(t *testing.T) { 26 | go SetLogger(stdr.New(log.New(os.Stderr, "", 0))) 27 | go Info("") 28 | } 29 | -------------------------------------------------------------------------------- /sdk/trace/doc.go: -------------------------------------------------------------------------------- 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 | /* 16 | Package trace contains support for OpenTelemetry distributed tracing. 17 | 18 | The following assumes a basic familiarity with OpenTelemetry concepts. 19 | See https://opentelemetry.io. 20 | */ 21 | package trace // import "go.opentelemetry.io/otel/sdk/trace" 22 | -------------------------------------------------------------------------------- /attribute/type_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=Type"; DO NOT EDIT. 2 | 3 | package attribute 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[INVALID-0] 12 | _ = x[BOOL-1] 13 | _ = x[INT64-2] 14 | _ = x[FLOAT64-3] 15 | _ = x[STRING-4] 16 | _ = x[BOOLSLICE-5] 17 | _ = x[INT64SLICE-6] 18 | _ = x[FLOAT64SLICE-7] 19 | _ = x[STRINGSLICE-8] 20 | } 21 | 22 | const _Type_name = "INVALIDBOOLINT64FLOAT64STRINGBOOLSLICEINT64SLICEFLOAT64SLICESTRINGSLICE" 23 | 24 | var _Type_index = [...]uint8{0, 7, 11, 16, 23, 29, 38, 48, 60, 71} 25 | 26 | func (i Type) String() string { 27 | if i < 0 || i >= Type(len(_Type_index)-1) { 28 | return "Type(" + strconv.FormatInt(int64(i), 10) + ")" 29 | } 30 | return _Type_name[_Type_index[i]:_Type_index[i+1]] 31 | } 32 | -------------------------------------------------------------------------------- /bridge/opencensus/internal/handler.go: -------------------------------------------------------------------------------- 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 internal // import "go.opentelemetry.io/otel/bridge/opencensus/internal" 16 | 17 | import "go.opentelemetry.io/otel" 18 | 19 | // Handle is the package level function to handle errors. It can be 20 | // overwritten for testing. 21 | var Handle = otel.Handle 22 | -------------------------------------------------------------------------------- /internal_logging_test.go: -------------------------------------------------------------------------------- 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 otel_test 16 | 17 | import ( 18 | "log" 19 | "os" 20 | 21 | "github.com/go-logr/stdr" 22 | 23 | "go.opentelemetry.io/otel" 24 | ) 25 | 26 | func ExampleSetLogger() { 27 | logger := stdr.New(log.New(os.Stdout, "", log.LstdFlags|log.Lshortfile)) 28 | otel.SetLogger(logger) 29 | } 30 | -------------------------------------------------------------------------------- /sdk/trace/util_test.go: -------------------------------------------------------------------------------- 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 trace_test 16 | 17 | import ( 18 | "testing" 19 | 20 | sdktrace "go.opentelemetry.io/otel/sdk/trace" 21 | ) 22 | 23 | func basicTracerProvider(t *testing.T) *sdktrace.TracerProvider { 24 | tp := sdktrace.NewTracerProvider(sdktrace.WithSampler(sdktrace.AlwaysSample())) 25 | return tp 26 | } 27 | -------------------------------------------------------------------------------- /internal/internaltest/errors.go: -------------------------------------------------------------------------------- 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 internaltest // import "go.opentelemetry.io/otel/internal/internaltest" 16 | 17 | type TestError string 18 | 19 | var _ error = TestError("") 20 | 21 | func NewTestError(s string) error { 22 | return TestError(s) 23 | } 24 | 25 | func (e TestError) Error() string { 26 | return string(e) 27 | } 28 | -------------------------------------------------------------------------------- /internal_logging.go: -------------------------------------------------------------------------------- 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 otel // import "go.opentelemetry.io/otel" 16 | 17 | import ( 18 | "github.com/go-logr/logr" 19 | 20 | "go.opentelemetry.io/otel/internal/global" 21 | ) 22 | 23 | // SetLogger configures the logger used internally to opentelemetry. 24 | func SetLogger(logger logr.Logger) { 25 | global.SetLogger(logger) 26 | } 27 | -------------------------------------------------------------------------------- /codes/doc.go: -------------------------------------------------------------------------------- 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 | /* 16 | Package codes defines the canonical error codes used by OpenTelemetry. 17 | 18 | It conforms to [the OpenTelemetry 19 | specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#statuscanonicalcode). 20 | */ 21 | package codes // import "go.opentelemetry.io/otel/codes" 22 | -------------------------------------------------------------------------------- /propagation/trace_context_example_test.go: -------------------------------------------------------------------------------- 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 propagation_test 16 | 17 | import ( 18 | "go.opentelemetry.io/otel" 19 | "go.opentelemetry.io/otel/propagation" 20 | ) 21 | 22 | func ExampleTraceContext() { 23 | tc := propagation.TraceContext{} 24 | // Register the TraceContext propagator globally. 25 | otel.SetTextMapPropagator(tc) 26 | } 27 | -------------------------------------------------------------------------------- /internal/matchers/temporal_matcher.go: -------------------------------------------------------------------------------- 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 matchers // import "go.opentelemetry.io/otel/internal/matchers" 16 | 17 | type TemporalMatcher byte 18 | 19 | //nolint:revive // ignoring missing comments for unexported constants in an internal package 20 | const ( 21 | Before TemporalMatcher = iota 22 | BeforeOrSameTime 23 | After 24 | AfterOrSameTime 25 | ) 26 | -------------------------------------------------------------------------------- /metric/unit/doc.go: -------------------------------------------------------------------------------- 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 unit provides units. 16 | // 17 | // This package is currently in a pre-GA phase. Backwards incompatible changes 18 | // may be introduced in subsequent minor version releases as we work to track 19 | // the evolving OpenTelemetry specification and user feedback. 20 | package unit // import "go.opentelemetry.io/otel/metric/unit" 21 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/third_party/thrift/lib/go/thrift/context.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | import "context" 23 | 24 | var defaultCtx = context.Background() 25 | -------------------------------------------------------------------------------- /semconv/v1.4.0/doc.go: -------------------------------------------------------------------------------- 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 semconv implements OpenTelemetry semantic conventions. 16 | // 17 | // OpenTelemetry semantic conventions are agreed standardized naming 18 | // patterns for OpenTelemetry things. This package represents the conventions 19 | // as of the v1.4.0 version of the OpenTelemetry specification. 20 | package semconv // import "go.opentelemetry.io/otel/semconv/v1.4.0" 21 | -------------------------------------------------------------------------------- /semconv/v1.5.0/doc.go: -------------------------------------------------------------------------------- 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 semconv implements OpenTelemetry semantic conventions. 16 | // 17 | // OpenTelemetry semantic conventions are agreed standardized naming 18 | // patterns for OpenTelemetry things. This package represents the conventions 19 | // as of the v1.5.0 version of the OpenTelemetry specification. 20 | package semconv // import "go.opentelemetry.io/otel/semconv/v1.5.0" 21 | -------------------------------------------------------------------------------- /semconv/v1.6.1/doc.go: -------------------------------------------------------------------------------- 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 semconv implements OpenTelemetry semantic conventions. 16 | // 17 | // OpenTelemetry semantic conventions are agreed standardized naming 18 | // patterns for OpenTelemetry things. This package represents the conventions 19 | // as of the v1.6.1 version of the OpenTelemetry specification. 20 | package semconv // import "go.opentelemetry.io/otel/semconv/v1.6.1" 21 | -------------------------------------------------------------------------------- /semconv/v1.7.0/doc.go: -------------------------------------------------------------------------------- 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 semconv implements OpenTelemetry semantic conventions. 16 | // 17 | // OpenTelemetry semantic conventions are agreed standardized naming 18 | // patterns for OpenTelemetry things. This package represents the conventions 19 | // as of the v1.7.0 version of the OpenTelemetry specification. 20 | package semconv // import "go.opentelemetry.io/otel/semconv/v1.7.0" 21 | -------------------------------------------------------------------------------- /sdk/metric/atomicfields.go: -------------------------------------------------------------------------------- 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 metric // import "go.opentelemetry.io/otel/sdk/metric" 16 | 17 | import "unsafe" 18 | 19 | // Deprecated: will be removed soon. 20 | func AtomicFieldOffsets() map[string]uintptr { 21 | return map[string]uintptr{ 22 | "record.refMapped.value": unsafe.Offsetof(record{}.refMapped.value), 23 | "record.updateCount": unsafe.Offsetof(record{}.updateCount), 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /semconv/v1.4.0/schema.go: -------------------------------------------------------------------------------- 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 semconv // import "go.opentelemetry.io/otel/semconv/v1.4.0" 16 | 17 | // SchemaURL is the schema URL that matches the version of the semantic conventions 18 | // that this package defines. Semconv packages starting from v1.4.0 must declare 19 | // non-empty schema URL in the form https://opentelemetry.io/schemas/ 20 | const SchemaURL = "https://opentelemetry.io/schemas/v1.4.0" 21 | -------------------------------------------------------------------------------- /semconv/v1.5.0/schema.go: -------------------------------------------------------------------------------- 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 semconv // import "go.opentelemetry.io/otel/semconv/v1.5.0" 16 | 17 | // SchemaURL is the schema URL that matches the version of the semantic conventions 18 | // that this package defines. Semconv packages starting from v1.4.0 must declare 19 | // non-empty schema URL in the form https://opentelemetry.io/schemas/ 20 | const SchemaURL = "https://opentelemetry.io/schemas/v1.5.0" 21 | -------------------------------------------------------------------------------- /semconv/v1.6.1/schema.go: -------------------------------------------------------------------------------- 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 semconv // import "go.opentelemetry.io/otel/semconv/v1.6.1" 16 | 17 | // SchemaURL is the schema URL that matches the version of the semantic conventions 18 | // that this package defines. Semconv packages starting from v1.4.0 must declare 19 | // non-empty schema URL in the form https://opentelemetry.io/schemas/ 20 | const SchemaURL = "https://opentelemetry.io/schemas/v1.6.1" 21 | -------------------------------------------------------------------------------- /semconv/v1.7.0/schema.go: -------------------------------------------------------------------------------- 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 semconv // import "go.opentelemetry.io/otel/semconv/v1.7.0" 16 | 17 | // SchemaURL is the schema URL that matches the version of the semantic conventions 18 | // that this package defines. Semconv packages starting from v1.4.0 must declare 19 | // non-empty schema URL in the form https://opentelemetry.io/schemas/ 20 | const SchemaURL = "https://opentelemetry.io/schemas/v1.7.0" 21 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/gen-go/zipkincore/zipkincore-consts.go: -------------------------------------------------------------------------------- 1 | // Code generated by Thrift Compiler (0.14.1). DO NOT EDIT. 2 | 3 | package zipkincore 4 | 5 | import ( 6 | "bytes" 7 | "context" 8 | "fmt" 9 | "time" 10 | 11 | "go.opentelemetry.io/otel/exporters/jaeger/internal/third_party/thrift/lib/go/thrift" 12 | ) 13 | 14 | // (needed to ensure safety because of naive import list construction.) 15 | var _ = thrift.ZERO 16 | var _ = fmt.Printf 17 | var _ = context.Background 18 | var _ = time.Now 19 | var _ = bytes.Equal 20 | 21 | const CLIENT_SEND = "cs" 22 | const CLIENT_RECV = "cr" 23 | const SERVER_SEND = "ss" 24 | const SERVER_RECV = "sr" 25 | const MESSAGE_SEND = "ms" 26 | const MESSAGE_RECV = "mr" 27 | const WIRE_SEND = "ws" 28 | const WIRE_RECV = "wr" 29 | const CLIENT_SEND_FRAGMENT = "csf" 30 | const CLIENT_RECV_FRAGMENT = "crf" 31 | const SERVER_SEND_FRAGMENT = "ssf" 32 | const SERVER_RECV_FRAGMENT = "srf" 33 | const LOCAL_COMPONENT = "lc" 34 | const CLIENT_ADDR = "ca" 35 | const SERVER_ADDR = "sa" 36 | const MESSAGE_ADDR = "ma" 37 | 38 | func init() { 39 | } 40 | -------------------------------------------------------------------------------- /schema/v1.0/types/types.go: -------------------------------------------------------------------------------- 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 types // import "go.opentelemetry.io/otel/schema/v1.0/types" 16 | 17 | // TelemetryVersion is a version number key in the schema file (e.g. "1.7.0") 18 | type TelemetryVersion string 19 | 20 | // SpanName is span name string. 21 | type SpanName string 22 | 23 | // EventName is an event name string. 24 | type EventName string 25 | 26 | // MetricName is a metric name string. 27 | type MetricName string 28 | -------------------------------------------------------------------------------- /example/zipkin/README.md: -------------------------------------------------------------------------------- 1 | # Zipkin Exporter Example 2 | 3 | Send an example span to a [Zipkin](https://zipkin.io/) service. 4 | These instructions expect you have [docker-compose](https://docs.docker.com/compose/) installed. 5 | 6 | Bring up the `zipkin-collector` service and example `zipkin-client` service to send an example trace: 7 | 8 | ```sh 9 | docker-compose up --detach zipkin-collector zipkin-client 10 | ``` 11 | 12 | The `zipkin-client` service sends just one trace and exits. Retrieve the `traceId` generated by the `zipkin-client` service; should be the last line in the logs: 13 | 14 | ```sh 15 | docker-compose logs --tail=1 zipkin-client 16 | ``` 17 | 18 | With the `traceId` you can view the trace from the `zipkin-collector` service UI hosted on port `9411`, e.g. with `traceId` of `f5695ba3b2ed00ea583fa4fa0badbeef`: [http://localhost:9411/zipkin/traces/f5695ba3b2ed00ea583fa4fa0badbeef](http://localhost:9411/zipkin/traces/f5695ba3b2ed00ea583fa4fa0badbeef) 19 | 20 | Shut down the services when you are finished with the example: 21 | 22 | ```sh 23 | docker-compose down 24 | ``` 25 | -------------------------------------------------------------------------------- /metric/number/doc.go: -------------------------------------------------------------------------------- 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 | /* 16 | Package number provides a number abstraction for instruments that 17 | either support int64 or float64 input values. 18 | 19 | This package is currently in a pre-GA phase. Backwards incompatible changes 20 | may be introduced in subsequent minor version releases as we work to track the 21 | evolving OpenTelemetry specification and user feedback. 22 | */ 23 | package number // import "go.opentelemetry.io/otel/metric/number" 24 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL Analysis" 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | # ┌───────────── minute (0 - 59) 7 | # │ ┌───────────── hour (0 - 23) 8 | # │ │ ┌───────────── day of the month (1 - 31) 9 | # │ │ │ ┌───────────── month (1 - 12 or JAN-DEC) 10 | # │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT) 11 | # │ │ │ │ │ 12 | # │ │ │ │ │ 13 | # │ │ │ │ │ 14 | # * * * * * 15 | - cron: '30 1 * * *' 16 | 17 | jobs: 18 | CodeQL-Build: 19 | runs-on: ubuntu-latest 20 | 21 | steps: 22 | - name: Checkout repository 23 | uses: actions/checkout@v2 24 | 25 | # Initializes the CodeQL tools for scanning. 26 | - name: Initialize CodeQL 27 | uses: github/codeql-action/init@v1 28 | with: 29 | languages: go 30 | 31 | - name: Autobuild 32 | uses: github/codeql-action/autobuild@v1 33 | 34 | - name: Perform CodeQL Analysis 35 | uses: github/codeql-action/analyze@v1 36 | 37 | -------------------------------------------------------------------------------- /schema/v1.0/ast/logs.go: -------------------------------------------------------------------------------- 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 ast // import "go.opentelemetry.io/otel/schema/v1.0/ast" 16 | 17 | // Logs corresponds to a section representing a list of changes that happened 18 | // to logs schema in a particular version. 19 | type Logs struct { 20 | Changes []LogsChange 21 | } 22 | 23 | // LogsChange corresponds to a section representing logs change. 24 | type LogsChange struct { 25 | RenameAttributes *RenameAttributes `yaml:"rename_attributes"` 26 | } 27 | -------------------------------------------------------------------------------- /internal/matchers/expecter.go: -------------------------------------------------------------------------------- 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 matchers // import "go.opentelemetry.io/otel/internal/matchers" 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | type Expecter struct { 22 | t *testing.T 23 | } 24 | 25 | func NewExpecter(t *testing.T) *Expecter { 26 | return &Expecter{ 27 | t: t, 28 | } 29 | } 30 | 31 | func (a *Expecter) Expect(actual interface{}) *Expectation { 32 | return &Expectation{ 33 | t: a.t, 34 | actual: actual, 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /example/fib/fib.go: -------------------------------------------------------------------------------- 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 main 16 | 17 | import "fmt" 18 | 19 | // Fibonacci returns the n-th fibonacci number. 20 | func Fibonacci(n uint) (uint64, error) { 21 | if n <= 1 { 22 | return uint64(n), nil 23 | } 24 | 25 | if n > 93 { 26 | return 0, fmt.Errorf("unsupported fibonacci number %d: too large", n) 27 | } 28 | 29 | var n2, n1 uint64 = 0, 1 30 | for i := uint(2); i < n; i++ { 31 | n2, n1 = n1, n1+n2 32 | } 33 | 34 | return n2 + n1, nil 35 | } 36 | -------------------------------------------------------------------------------- /trace/nonrecording.go: -------------------------------------------------------------------------------- 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 trace // import "go.opentelemetry.io/otel/trace" 16 | 17 | // nonRecordingSpan is a minimal implementation of a Span that wraps a 18 | // SpanContext. It performs no operations other than to return the wrapped 19 | // SpanContext. 20 | type nonRecordingSpan struct { 21 | noopSpan 22 | 23 | sc SpanContext 24 | } 25 | 26 | // SpanContext returns the wrapped SpanContext. 27 | func (s nonRecordingSpan) SpanContext() SpanContext { return s.sc } 28 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/third_party/thrift/lib/go/thrift/protocol_factory.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // Factory interface for constructing protocol instances. 23 | type TProtocolFactory interface { 24 | GetProtocol(trans TTransport) TProtocol 25 | } 26 | -------------------------------------------------------------------------------- /propagation/doc.go: -------------------------------------------------------------------------------- 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 | /* 16 | Package propagation contains OpenTelemetry context propagators. 17 | 18 | OpenTelemetry propagators are used to extract and inject context data from and 19 | into messages exchanged by applications. The propagator supported by this 20 | package is the W3C Trace Context encoding 21 | (https://www.w3.org/TR/trace-context/), and W3C Baggage 22 | (https://www.w3.org/TR/baggage/). 23 | */ 24 | package propagation // import "go.opentelemetry.io/otel/propagation" 25 | -------------------------------------------------------------------------------- /exporters/stdout/stdoutmetric/doc.go: -------------------------------------------------------------------------------- 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 stdout contains an OpenTelemetry exporter for metric telemetry 16 | // to be written to an output destination as JSON. 17 | // 18 | // This package is currently in a pre-GA phase. Backwards incompatible changes 19 | // may be introduced in subsequent minor version releases as we work to track 20 | // the evolving OpenTelemetry specification and user feedback. 21 | package stdoutmetric // import "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric" 22 | -------------------------------------------------------------------------------- /exporters/zipkin/env.go: -------------------------------------------------------------------------------- 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 zipkin // import "go.opentelemetry.io/otel/exporters/zipkin" 16 | 17 | import "os" 18 | 19 | // Environment variable names 20 | const ( 21 | // Endpoint for Zipkin collector 22 | envEndpoint = "OTEL_EXPORTER_ZIPKIN_ENDPOINT" 23 | ) 24 | 25 | // envOr returns an env variable's value if it is exists or the default if not 26 | func envOr(key, defaultValue string) string { 27 | if v, ok := os.LookupEnv(key); ok && v != "" { 28 | return v 29 | } 30 | return defaultValue 31 | } 32 | -------------------------------------------------------------------------------- /schema/README.md: -------------------------------------------------------------------------------- 1 | # Telemetry Schema Files 2 | 3 | The `schema` module contains packages that help to parse and validate 4 | [schema files](https://github.com/open-telemetry/oteps/blob/main/text/0152-telemetry-schemas.md). 5 | 6 | Each `major.minor` schema file format version is implemented as a separate package, with 7 | the name of the package in the `vmajor.minor` form. 8 | 9 | To parse a schema file, first decide what file format version you want to parse, 10 | then import the corresponding package and use the `Parse` or `ParseFile` functions 11 | like this: 12 | 13 | ```go 14 | import schema "go.opentelemetry.io/otel/schema/v1.0" 15 | 16 | // Load the schema from a file in v1.0.x file format. 17 | func loadSchemaFromFile() error { 18 | telSchema, err := schema.ParseFile("schema-file.yaml") 19 | if err != nil { 20 | return err 21 | } 22 | // Use telSchema struct here. 23 | } 24 | 25 | // Alternatively use schema.Parse to read the schema file from io.Reader. 26 | func loadSchemaFromReader(r io.Reader) error { 27 | telSchema, err := schema.Parse(r) 28 | if err != nil { 29 | return err 30 | } 31 | // Use telSchema struct here. 32 | } 33 | ``` 34 | -------------------------------------------------------------------------------- /sdk/resource/export_unix_test.go: -------------------------------------------------------------------------------- 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 | //go:build aix || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos 16 | // +build aix dragonfly freebsd linux netbsd openbsd solaris zos 17 | 18 | package resource // import "go.opentelemetry.io/otel/sdk/resource" 19 | 20 | var ( 21 | ParseOSReleaseFile = parseOSReleaseFile 22 | Skip = skip 23 | Parse = parse 24 | Unquote = unquote 25 | Unescape = unescape 26 | BuildOSRelease = buildOSRelease 27 | ) 28 | -------------------------------------------------------------------------------- /example/otel-collector/k8s/prometheus-service.yaml: -------------------------------------------------------------------------------- 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 | apiVersion: monitoring.coreos.com/v1 16 | kind: ServiceMonitor 17 | metadata: 18 | labels: 19 | serviceapp: otel-collector 20 | name: otel-collector 21 | namespace: observability 22 | spec: 23 | endpoints: 24 | - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token 25 | interval: 30s 26 | port: metrics 27 | namespaceSelector: 28 | matchNames: 29 | - observability 30 | selector: 31 | matchLabels: 32 | app: opentelemetry 33 | -------------------------------------------------------------------------------- /exporters/otlp/otlpmetric/otlpmetrichttp/doc.go: -------------------------------------------------------------------------------- 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 | /* 16 | Package otlpmetrichttp provides a client that sends metrics to the collector 17 | using HTTP with binary protobuf payloads. 18 | 19 | This package is currently in a pre-GA phase. Backwards incompatible changes 20 | may be introduced in subsequent minor version releases as we work to track the 21 | evolving OpenTelemetry specification and user feedback. 22 | */ 23 | package otlpmetrichttp // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" 24 | -------------------------------------------------------------------------------- /metric/sdkapi/instrumentkind_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=InstrumentKind"; DO NOT EDIT. 2 | 3 | package sdkapi 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[HistogramInstrumentKind-0] 12 | _ = x[GaugeObserverInstrumentKind-1] 13 | _ = x[CounterInstrumentKind-2] 14 | _ = x[UpDownCounterInstrumentKind-3] 15 | _ = x[CounterObserverInstrumentKind-4] 16 | _ = x[UpDownCounterObserverInstrumentKind-5] 17 | } 18 | 19 | const _InstrumentKind_name = "HistogramInstrumentKindGaugeObserverInstrumentKindCounterInstrumentKindUpDownCounterInstrumentKindCounterObserverInstrumentKindUpDownCounterObserverInstrumentKind" 20 | 21 | var _InstrumentKind_index = [...]uint8{0, 23, 50, 71, 98, 127, 162} 22 | 23 | func (i InstrumentKind) String() string { 24 | if i < 0 || i >= InstrumentKind(len(_InstrumentKind_index)-1) { 25 | return "InstrumentKind(" + strconv.FormatInt(int64(i), 10) + ")" 26 | } 27 | return _InstrumentKind_name[_InstrumentKind_index[i]:_InstrumentKind_index[i+1]] 28 | } 29 | -------------------------------------------------------------------------------- /internal/metric/registry/doc.go: -------------------------------------------------------------------------------- 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 | /* 16 | Package registry provides a non-standalone implementation of 17 | MeterProvider that adds uniqueness checking for instrument descriptors 18 | on top of other MeterProvider it wraps. 19 | 20 | This package is currently in a pre-GA phase. Backwards incompatible changes 21 | may be introduced in subsequent minor version releases as we work to track the 22 | evolving OpenTelemetry specification and user feedback. 23 | */ 24 | package registry // import "go.opentelemetry.io/otel/internal/metric/registry" 25 | -------------------------------------------------------------------------------- /exporters/otlp/otlptrace/internal/tracetransform/resource.go: -------------------------------------------------------------------------------- 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 tracetransform // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform" 16 | 17 | import ( 18 | "go.opentelemetry.io/otel/sdk/resource" 19 | resourcepb "go.opentelemetry.io/proto/otlp/resource/v1" 20 | ) 21 | 22 | // Resource transforms a Resource into an OTLP Resource. 23 | func Resource(r *resource.Resource) *resourcepb.Resource { 24 | if r == nil { 25 | return nil 26 | } 27 | return &resourcepb.Resource{Attributes: ResourceAttributes(r)} 28 | } 29 | -------------------------------------------------------------------------------- /exporters/otlp/otlpmetric/internal/metrictransform/resource.go: -------------------------------------------------------------------------------- 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 metrictransform // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/metrictransform" 16 | 17 | import ( 18 | "go.opentelemetry.io/otel/sdk/resource" 19 | resourcepb "go.opentelemetry.io/proto/otlp/resource/v1" 20 | ) 21 | 22 | // Resource transforms a Resource into an OTLP Resource. 23 | func Resource(r *resource.Resource) *resourcepb.Resource { 24 | if r == nil { 25 | return nil 26 | } 27 | return &resourcepb.Resource{Attributes: ResourceAttributes(r)} 28 | } 29 | -------------------------------------------------------------------------------- /metric/noop_test.go: -------------------------------------------------------------------------------- 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 metric 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestNewNoopMeterProvider(t *testing.T) { 22 | got, want := NewNoopMeterProvider(), noopMeterProvider{} 23 | if got != want { 24 | t.Errorf("NewNoopMeterProvider() returned %#v, want %#v", got, want) 25 | } 26 | } 27 | 28 | func TestNoopMeterProviderMeter(t *testing.T) { 29 | mp := NewNoopMeterProvider() 30 | got, want := mp.Meter(""), Meter{} 31 | if got != want { 32 | t.Errorf("noopMeterProvider.Meter() returned %#v, want %#v", got, want) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /schema/v1.0/ast/common.go: -------------------------------------------------------------------------------- 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 ast // import "go.opentelemetry.io/otel/schema/v1.0/ast" 16 | 17 | // RenameAttributes corresponds to a section that describes attribute renaming. 18 | type RenameAttributes struct { 19 | AttributeMap AttributeMap `yaml:"attribute_map"` 20 | } 21 | 22 | // AttributeMap corresponds to a section representing a mapping of attribute names. 23 | // The keys are the old attribute name used in the previous version, the values are the 24 | // new attribute name starting from this version. 25 | type AttributeMap map[string]string 26 | -------------------------------------------------------------------------------- /internal/trace/noop/noop.go: -------------------------------------------------------------------------------- 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 noop provides noop tracing implementations for tracer and span. 16 | package noop // import "go.opentelemetry.io/otel/internal/trace/noop" 17 | 18 | import ( 19 | "context" 20 | 21 | "go.opentelemetry.io/otel/trace" 22 | ) 23 | 24 | var ( 25 | // Tracer is a noop tracer that starts noop spans. 26 | Tracer trace.Tracer 27 | 28 | // Span is a noop Span. 29 | Span trace.Span 30 | ) 31 | 32 | func init() { 33 | Tracer = trace.NewNoopTracerProvider().Tracer("") 34 | _, Span = Tracer.Start(context.Background(), "") 35 | } 36 | -------------------------------------------------------------------------------- /sdk/resource/export_common_unix_test.go: -------------------------------------------------------------------------------- 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 | //go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos 16 | // +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zos 17 | 18 | package resource // import "go.opentelemetry.io/otel/sdk/resource" 19 | 20 | var ( 21 | Uname = uname 22 | CharsToString = charsToString 23 | GetFirstAvailableFile = getFirstAvailableFile 24 | ) 25 | 26 | var ( 27 | SetUnameProvider = setUnameProvider 28 | SetDefaultUnameProvider = setDefaultUnameProvider 29 | ) 30 | -------------------------------------------------------------------------------- /internal/global/benchmark_test.go: -------------------------------------------------------------------------------- 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 global_test 16 | 17 | import ( 18 | "context" 19 | "testing" 20 | 21 | "go.opentelemetry.io/otel" 22 | "go.opentelemetry.io/otel/internal/global" 23 | ) 24 | 25 | func BenchmarkStartEndSpanNoSDK(b *testing.B) { 26 | // Compare with BenchmarkStartEndSpan() in 27 | // ../../sdk/trace/benchmark_test.go. 28 | global.ResetForTest() 29 | t := otel.Tracer("Benchmark StartEndSpan") 30 | ctx := context.Background() 31 | b.ResetTimer() 32 | for i := 0; i < b.N; i++ { 33 | _, span := t.Start(ctx, "/foo") 34 | span.End() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sdk/resource/export_windows_test.go: -------------------------------------------------------------------------------- 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 resource // import "go.opentelemetry.io/otel/sdk/resource" 16 | 17 | var ( 18 | PlatformOSDescription = platformOSDescription 19 | ReadProductName = readProductName 20 | ReadDisplayVersion = readDisplayVersion 21 | ReadReleaseID = readReleaseID 22 | ReadCurrentMajorVersionNumber = readCurrentMajorVersionNumber 23 | ReadCurrentMinorVersionNumber = readCurrentMinorVersionNumber 24 | ReadCurrentBuildNumber = readCurrentBuildNumber 25 | ReadUBR = readUBR 26 | ) 27 | -------------------------------------------------------------------------------- /baggage/context_test.go: -------------------------------------------------------------------------------- 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 baggage 16 | 17 | import ( 18 | "context" 19 | "testing" 20 | 21 | "github.com/stretchr/testify/assert" 22 | 23 | "go.opentelemetry.io/otel/internal/baggage" 24 | ) 25 | 26 | func TestContext(t *testing.T) { 27 | ctx := context.Background() 28 | assert.Equal(t, Baggage{}, FromContext(ctx)) 29 | 30 | b := Baggage{list: baggage.List{"key": baggage.Item{Value: "val"}}} 31 | ctx = ContextWithBaggage(ctx, b) 32 | assert.Equal(t, b, FromContext(ctx)) 33 | 34 | ctx = ContextWithoutBaggage(ctx) 35 | assert.Equal(t, Baggage{}, FromContext(ctx)) 36 | } 37 | -------------------------------------------------------------------------------- /internal/tools/tools.go: -------------------------------------------------------------------------------- 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 | //go:build tools 16 | // +build tools 17 | 18 | package tools // import "go.opentelemetry.io/otel/internal/tools" 19 | 20 | import ( 21 | _ "github.com/client9/misspell/cmd/misspell" 22 | _ "github.com/gogo/protobuf/protoc-gen-gogofast" 23 | _ "github.com/golangci/golangci-lint/cmd/golangci-lint" 24 | _ "github.com/itchyny/gojq" 25 | _ "github.com/jcchavezs/porto/cmd/porto" 26 | _ "github.com/wadey/gocovmerge" 27 | _ "go.opentelemetry.io/build-tools/multimod" 28 | _ "go.opentelemetry.io/build-tools/semconvgen" 29 | _ "golang.org/x/tools/cmd/stringer" 30 | ) 31 | -------------------------------------------------------------------------------- /exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go: -------------------------------------------------------------------------------- 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 tracetransform // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform" 16 | 17 | import ( 18 | "go.opentelemetry.io/otel/sdk/instrumentation" 19 | commonpb "go.opentelemetry.io/proto/otlp/common/v1" 20 | ) 21 | 22 | func InstrumentationLibrary(il instrumentation.Library) *commonpb.InstrumentationLibrary { 23 | if il == (instrumentation.Library{}) { 24 | return nil 25 | } 26 | return &commonpb.InstrumentationLibrary{ 27 | Name: il.Name, 28 | Version: il.Version, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /metric/noop.go: -------------------------------------------------------------------------------- 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 metric // import "go.opentelemetry.io/otel/metric" 16 | 17 | type noopMeterProvider struct{} 18 | 19 | // NewNoopMeterProvider returns an implementation of MeterProvider that 20 | // performs no operations. The Meter and Instrument created from the returned 21 | // MeterProvider also perform no operations. 22 | func NewNoopMeterProvider() MeterProvider { 23 | return noopMeterProvider{} 24 | } 25 | 26 | var _ MeterProvider = noopMeterProvider{} 27 | 28 | func (noopMeterProvider) Meter(instrumentationName string, opts ...MeterOption) Meter { 29 | return Meter{} 30 | } 31 | -------------------------------------------------------------------------------- /exporters/stdout/stdoutmetric/exporter.go: -------------------------------------------------------------------------------- 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 stdoutmetric // import "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric" 16 | 17 | import "go.opentelemetry.io/otel/sdk/metric/export" 18 | 19 | type Exporter struct { 20 | metricExporter 21 | } 22 | 23 | var ( 24 | _ export.Exporter = &Exporter{} 25 | ) 26 | 27 | // New creates an Exporter with the passed options. 28 | func New(options ...Option) (*Exporter, error) { 29 | cfg, err := newConfig(options...) 30 | if err != nil { 31 | return nil, err 32 | } 33 | return &Exporter{ 34 | metricExporter: metricExporter{cfg}, 35 | }, nil 36 | } 37 | -------------------------------------------------------------------------------- /sdk/trace/evictedqueue.go: -------------------------------------------------------------------------------- 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 trace // import "go.opentelemetry.io/otel/sdk/trace" 16 | 17 | type evictedQueue struct { 18 | queue []interface{} 19 | capacity int 20 | droppedCount int 21 | } 22 | 23 | func newEvictedQueue(capacity int) *evictedQueue { 24 | eq := &evictedQueue{ 25 | capacity: capacity, 26 | queue: make([]interface{}, 0), 27 | } 28 | 29 | return eq 30 | } 31 | 32 | func (eq *evictedQueue) add(value interface{}) { 33 | if len(eq.queue) == eq.capacity { 34 | eq.queue = eq.queue[1:] 35 | eq.droppedCount++ 36 | } 37 | eq.queue = append(eq.queue, value) 38 | } 39 | -------------------------------------------------------------------------------- /version_test.go: -------------------------------------------------------------------------------- 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 otel_test 16 | 17 | import ( 18 | "regexp" 19 | "testing" 20 | 21 | "github.com/stretchr/testify/assert" 22 | 23 | "go.opentelemetry.io/otel" 24 | ) 25 | 26 | // regex taken from https://github.com/Masterminds/semver/tree/v3.1.1 27 | var versionRegex = regexp.MustCompile(`^v?([0-9]+)(\.[0-9]+)?(\.[0-9]+)?` + 28 | `(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?` + 29 | `(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$`) 30 | 31 | func TestVersionSemver(t *testing.T) { 32 | v := otel.Version() 33 | assert.NotNil(t, versionRegex.FindStringSubmatch(v), "version is not semver: %s", v) 34 | } 35 | -------------------------------------------------------------------------------- /bridge/opencensus/internal/oc2otel/span_context.go: -------------------------------------------------------------------------------- 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 oc2otel // import "go.opentelemetry.io/otel/bridge/opencensus/internal/oc2otel" 16 | 17 | import ( 18 | octrace "go.opencensus.io/trace" 19 | 20 | "go.opentelemetry.io/otel/trace" 21 | ) 22 | 23 | func SpanContext(sc octrace.SpanContext) trace.SpanContext { 24 | var traceFlags trace.TraceFlags 25 | if sc.IsSampled() { 26 | traceFlags = trace.FlagsSampled 27 | } 28 | return trace.NewSpanContext(trace.SpanContextConfig{ 29 | TraceID: trace.TraceID(sc.TraceID), 30 | SpanID: trace.SpanID(sc.SpanID), 31 | TraceFlags: traceFlags, 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /exporters/otlp/internal/retry/go.sum: -------------------------------------------------------------------------------- 1 | github.com/cenkalti/backoff/v4 v4.1.2 h1:6Yo7N8UP2K6LWZnW94DLVSSrbobcWdVzAYOisuDPIFo= 2 | github.com/cenkalti/backoff/v4 v4.1.2/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= 3 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 4 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 5 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 6 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 7 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 8 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 9 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 10 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 11 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 12 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 13 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 14 | -------------------------------------------------------------------------------- /bridge/opencensus/internal/otel2oc/span_context.go: -------------------------------------------------------------------------------- 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 otel2oc // import "go.opentelemetry.io/otel/bridge/opencensus/internal/otel2oc" 16 | 17 | import ( 18 | octrace "go.opencensus.io/trace" 19 | 20 | "go.opentelemetry.io/otel/trace" 21 | ) 22 | 23 | func SpanContext(sc trace.SpanContext) octrace.SpanContext { 24 | var to octrace.TraceOptions 25 | if sc.IsSampled() { 26 | // OpenCensus doesn't expose functions to directly set sampled 27 | to = 0x1 28 | } 29 | return octrace.SpanContext{ 30 | TraceID: octrace.TraceID(sc.TraceID()), 31 | SpanID: octrace.SpanID(sc.SpanID()), 32 | TraceOptions: to, 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /propagation.go: -------------------------------------------------------------------------------- 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 otel // import "go.opentelemetry.io/otel" 16 | 17 | import ( 18 | "go.opentelemetry.io/otel/internal/global" 19 | "go.opentelemetry.io/otel/propagation" 20 | ) 21 | 22 | // GetTextMapPropagator returns the global TextMapPropagator. If none has been 23 | // set, a No-Op TextMapPropagator is returned. 24 | func GetTextMapPropagator() propagation.TextMapPropagator { 25 | return global.TextMapPropagator() 26 | } 27 | 28 | // SetTextMapPropagator sets propagator as the global TextMapPropagator. 29 | func SetTextMapPropagator(propagator propagation.TextMapPropagator) { 30 | global.SetTextMapPropagator(propagator) 31 | } 32 | -------------------------------------------------------------------------------- /exporters/otlp/otlptrace/otlptracegrpc/exporter.go: -------------------------------------------------------------------------------- 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 otlptracegrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" 16 | 17 | import ( 18 | "context" 19 | 20 | "go.opentelemetry.io/otel/exporters/otlp/otlptrace" 21 | ) 22 | 23 | // New constructs a new Exporter and starts it. 24 | func New(ctx context.Context, opts ...Option) (*otlptrace.Exporter, error) { 25 | return otlptrace.New(ctx, NewClient(opts...)) 26 | } 27 | 28 | // NewUnstarted constructs a new Exporter and does not start it. 29 | func NewUnstarted(opts ...Option) *otlptrace.Exporter { 30 | return otlptrace.NewUnstarted(NewClient(opts...)) 31 | } 32 | -------------------------------------------------------------------------------- /exporters/otlp/otlptrace/otlptracehttp/exporter.go: -------------------------------------------------------------------------------- 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 otlptracehttp // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" 16 | 17 | import ( 18 | "context" 19 | 20 | "go.opentelemetry.io/otel/exporters/otlp/otlptrace" 21 | ) 22 | 23 | // New constructs a new Exporter and starts it. 24 | func New(ctx context.Context, opts ...Option) (*otlptrace.Exporter, error) { 25 | return otlptrace.New(ctx, NewClient(opts...)) 26 | } 27 | 28 | // NewUnstarted constructs a new Exporter and does not start it. 29 | func NewUnstarted(opts ...Option) *otlptrace.Exporter { 30 | return otlptrace.NewUnstarted(NewClient(opts...)) 31 | } 32 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/third_party/thrift/lib/go/thrift/messagetype.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // Message type constants in the Thrift protocol. 23 | type TMessageType int32 24 | 25 | const ( 26 | INVALID_TMESSAGE_TYPE TMessageType = 0 27 | CALL TMessageType = 1 28 | REPLY TMessageType = 2 29 | EXCEPTION TMessageType = 3 30 | ONEWAY TMessageType = 4 31 | ) 32 | -------------------------------------------------------------------------------- /exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go: -------------------------------------------------------------------------------- 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 otlpmetricgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" 16 | 17 | import ( 18 | "context" 19 | 20 | "go.opentelemetry.io/otel/exporters/otlp/otlpmetric" 21 | ) 22 | 23 | // New constructs a new Exporter and starts it. 24 | func New(ctx context.Context, opts ...Option) (*otlpmetric.Exporter, error) { 25 | return otlpmetric.New(ctx, NewClient(opts...)) 26 | } 27 | 28 | // NewUnstarted constructs a new Exporter and does not start it. 29 | func NewUnstarted(opts ...Option) *otlpmetric.Exporter { 30 | return otlpmetric.NewUnstarted(NewClient(opts...)) 31 | } 32 | -------------------------------------------------------------------------------- /exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go: -------------------------------------------------------------------------------- 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 otlpmetrichttp // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" 16 | 17 | import ( 18 | "context" 19 | 20 | "go.opentelemetry.io/otel/exporters/otlp/otlpmetric" 21 | ) 22 | 23 | // New constructs a new Exporter and starts it. 24 | func New(ctx context.Context, opts ...Option) (*otlpmetric.Exporter, error) { 25 | return otlpmetric.New(ctx, NewClient(opts...)) 26 | } 27 | 28 | // NewUnstarted constructs a new Exporter and does not start it. 29 | func NewUnstarted(opts ...Option) *otlpmetric.Exporter { 30 | return otlpmetric.NewUnstarted(NewClient(opts...)) 31 | } 32 | -------------------------------------------------------------------------------- /exporters/otlp/otlptrace/internal/otlpconfig/tls.go: -------------------------------------------------------------------------------- 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 otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/otlpconfig" 16 | 17 | import ( 18 | "crypto/tls" 19 | "crypto/x509" 20 | "errors" 21 | ) 22 | 23 | // CreateTLSConfig creates a tls.Config from a raw certificate bytes 24 | // to verify a server certificate. 25 | func CreateTLSConfig(certBytes []byte) (*tls.Config, error) { 26 | cp := x509.NewCertPool() 27 | if ok := cp.AppendCertsFromPEM(certBytes); !ok { 28 | return nil, errors.New("failed to append certificate to the cert pool") 29 | } 30 | 31 | return &tls.Config{ 32 | RootCAs: cp, 33 | }, nil 34 | } 35 | -------------------------------------------------------------------------------- /sdk/metric/controller/basic/config_test.go: -------------------------------------------------------------------------------- 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 basic 16 | 17 | import ( 18 | "testing" 19 | 20 | "github.com/stretchr/testify/assert" 21 | 22 | "go.opentelemetry.io/otel/attribute" 23 | "go.opentelemetry.io/otel/sdk/resource" 24 | ) 25 | 26 | func TestWithResource(t *testing.T) { 27 | r := resource.NewSchemaless(attribute.String("A", "a")) 28 | 29 | c := &config{} 30 | WithResource(r).apply(c) 31 | assert.Equal(t, r.Equivalent(), c.Resource.Equivalent()) 32 | 33 | // Ensure overwriting works. 34 | c = &config{Resource: &resource.Resource{}} 35 | WithResource(r).apply(c) 36 | assert.Equal(t, r.Equivalent(), c.Resource.Equivalent()) 37 | } 38 | -------------------------------------------------------------------------------- /sdk/trace/event.go: -------------------------------------------------------------------------------- 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 trace // import "go.opentelemetry.io/otel/sdk/trace" 16 | 17 | import ( 18 | "time" 19 | 20 | "go.opentelemetry.io/otel/attribute" 21 | ) 22 | 23 | // Event is a thing that happened during a Span's lifetime. 24 | type Event struct { 25 | // Name is the name of this event 26 | Name string 27 | 28 | // Attributes describe the aspects of the event. 29 | Attributes []attribute.KeyValue 30 | 31 | // DroppedAttributeCount is the number of attributes that were not 32 | // recorded due to configured limits being reached. 33 | DroppedAttributeCount int 34 | 35 | // Time at which this event was recorded. 36 | Time time.Time 37 | } 38 | -------------------------------------------------------------------------------- /.github/workflows/changelog.yml: -------------------------------------------------------------------------------- 1 | # This action requires that any PR targeting the main branch should touch at 2 | # least one CHANGELOG file. If a CHANGELOG entry is not required, add the "Skip 3 | # Changelog" label to disable this action. 4 | 5 | name: changelog 6 | 7 | on: 8 | pull_request: 9 | types: [opened, synchronize, reopened, labeled, unlabeled] 10 | branches: 11 | - main 12 | jobs: 13 | changelog: 14 | runs-on: ubuntu-latest 15 | if: "!contains(github.event.pull_request.labels.*.name, 'Skip Changelog')" 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | 20 | - name: Check for CHANGELOG changes 21 | run: | 22 | # Only the latest commit of the feature branch is available 23 | # automatically. To diff with the base branch, we need to 24 | # fetch that too (and we only need its latest commit). 25 | git fetch origin ${{ github.base_ref }} --depth=1 26 | if [[ $(git diff --name-only FETCH_HEAD | grep CHANGELOG) ]] 27 | then 28 | echo "A CHANGELOG was modified. Looks good!" 29 | else 30 | echo "No CHANGELOG was modified." 31 | echo "Please add a CHANGELOG entry, or add the \"Skip Changelog\" label if not required." 32 | false 33 | fi 34 | -------------------------------------------------------------------------------- /metric/sdkapi/descriptor_test.go: -------------------------------------------------------------------------------- 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 sdkapi 16 | 17 | import ( 18 | "testing" 19 | 20 | "github.com/stretchr/testify/require" 21 | 22 | "go.opentelemetry.io/otel/metric/number" 23 | "go.opentelemetry.io/otel/metric/unit" 24 | ) 25 | 26 | func TestDescriptorGetters(t *testing.T) { 27 | d := NewDescriptor("name", HistogramInstrumentKind, number.Int64Kind, "my description", "my unit") 28 | require.Equal(t, "name", d.Name()) 29 | require.Equal(t, HistogramInstrumentKind, d.InstrumentKind()) 30 | require.Equal(t, number.Int64Kind, d.NumberKind()) 31 | require.Equal(t, "my description", d.Description()) 32 | require.Equal(t, unit.Unit("my unit"), d.Unit()) 33 | } 34 | -------------------------------------------------------------------------------- /example/zipkin/docker-compose.yml: -------------------------------------------------------------------------------- 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 | version: "3.7" 15 | services: 16 | zipkin-collector: 17 | image: openzipkin/zipkin-slim:latest 18 | ports: 19 | - "9411:9411" 20 | networks: 21 | - example 22 | zipkin-client: 23 | build: 24 | dockerfile: $PWD/Dockerfile 25 | context: ../.. 26 | command: 27 | - "/bin/sh" 28 | - "-c" 29 | - "while ! nc -w 1 -z zipkin-collector 9411; do echo sleep for 1s waiting for zipkin-collector to become available; sleep 1; done && /go/bin/main -zipkin http://zipkin-collector:9411/api/v2/spans" 30 | networks: 31 | - example 32 | depends_on: 33 | - zipkin-collector 34 | networks: 35 | example: 36 | -------------------------------------------------------------------------------- /metric/metrictest/alignment_test.go: -------------------------------------------------------------------------------- 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 metrictest 16 | 17 | import ( 18 | "os" 19 | "testing" 20 | "unsafe" 21 | 22 | "go.opentelemetry.io/otel/internal/internaltest" 23 | ) 24 | 25 | // TestMain ensures struct alignment prior to running tests. 26 | func TestMain(m *testing.M) { 27 | fields := []internaltest.FieldOffset{ 28 | { 29 | Name: "Batch.Measurments", 30 | Offset: unsafe.Offsetof(Batch{}.Measurements), 31 | }, 32 | { 33 | Name: "Measurement.Number", 34 | Offset: unsafe.Offsetof(Measurement{}.Number), 35 | }, 36 | } 37 | if !internaltest.Aligned8Byte(fields, os.Stderr) { 38 | os.Exit(1) 39 | } 40 | 41 | os.Exit(m.Run()) 42 | } 43 | -------------------------------------------------------------------------------- /sdk/resource/os_unsupported.go: -------------------------------------------------------------------------------- 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 | // +build !aix 16 | // +build !darwin 17 | // +build !dragonfly 18 | // +build !freebsd 19 | // +build !linux 20 | // +build !netbsd 21 | // +build !openbsd 22 | // +build !solaris 23 | // +build !windows 24 | // +build !zos 25 | 26 | package resource // import "go.opentelemetry.io/otel/sdk/resource" 27 | 28 | // platformOSDescription is a placeholder implementation for OSes 29 | // for which this project currently doesn't support os.description 30 | // attribute detection. See build tags declaration early on this file 31 | // for a list of unsupported OSes. 32 | func platformOSDescription() (string, error) { 33 | return "", nil 34 | } 35 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/third_party/thrift/lib/go/thrift/socket_windows_conn.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | /* 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | package thrift 23 | 24 | func (sc *socketConn) read0() error { 25 | // On windows, we fallback to the default behavior of reading 0 bytes. 26 | var p []byte 27 | _, err := sc.Conn.Read(p) 28 | return err 29 | } 30 | 31 | func (sc *socketConn) checkConn() error { 32 | // On windows, we always return nil for this check. 33 | return nil 34 | } 35 | -------------------------------------------------------------------------------- /exporters/jaeger/assertsocketbuffersize_windows_test.go: -------------------------------------------------------------------------------- 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 | // +build windows 16 | 17 | package jaeger 18 | 19 | import ( 20 | "net" 21 | "testing" 22 | ) 23 | 24 | func assertSockBufferSize(t *testing.T, expectedBytes int, conn *net.UDPConn) bool { 25 | // The Windows implementation of the net.UDPConn does not implement the 26 | // functionality to return a file handle, instead a "not supported" error 27 | // is returned: 28 | // 29 | // https://github.com/golang/go/blob/6cc8aa7ece96aca282db19f08aa5c98ed13695d9/src/net/fd_windows.go#L175-L178 30 | // 31 | // This means we are not able to pass the connection to a syscall and 32 | // determine the buffer size. 33 | return true 34 | } 35 | -------------------------------------------------------------------------------- /sdk/trace/link.go: -------------------------------------------------------------------------------- 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 trace // import "go.opentelemetry.io/otel/sdk/trace" 16 | 17 | import ( 18 | "go.opentelemetry.io/otel/attribute" 19 | "go.opentelemetry.io/otel/trace" 20 | ) 21 | 22 | // Link is the relationship between two Spans. The relationship can be within 23 | // the same Trace or across different Traces. 24 | type Link struct { 25 | // SpanContext of the linked Span. 26 | SpanContext trace.SpanContext 27 | 28 | // Attributes describe the aspects of the link. 29 | Attributes []attribute.KeyValue 30 | 31 | // DroppedAttributeCount is the number of attributes that were not 32 | // recorded due to configured limits being reached. 33 | DroppedAttributeCount int 34 | } 35 | -------------------------------------------------------------------------------- /metric/global/metric_test.go: -------------------------------------------------------------------------------- 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 global 16 | 17 | import ( 18 | "testing" 19 | 20 | "go.opentelemetry.io/otel/metric" 21 | ) 22 | 23 | type testMeterProvider struct{} 24 | 25 | var _ metric.MeterProvider = &testMeterProvider{} 26 | 27 | func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter { 28 | return metric.Meter{} 29 | } 30 | 31 | func TestMultipleGlobalMeterProvider(t *testing.T) { 32 | p1 := testMeterProvider{} 33 | p2 := metric.NewNoopMeterProvider() 34 | SetMeterProvider(&p1) 35 | SetMeterProvider(p2) 36 | 37 | got := GetMeterProvider() 38 | want := p2 39 | if got != want { 40 | t.Fatalf("MeterProvider: got %p, want %p\n", got, want) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /internal/metric/global/internal_test.go: -------------------------------------------------------------------------------- 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 global_test 16 | 17 | import ( 18 | "os" 19 | "testing" 20 | 21 | ottest "go.opentelemetry.io/otel/internal/internaltest" 22 | "go.opentelemetry.io/otel/internal/metric/global" 23 | ) 24 | 25 | // Ensure struct alignment prior to running tests. 26 | func TestMain(m *testing.M) { 27 | fieldsMap := global.AtomicFieldOffsets() 28 | fields := make([]ottest.FieldOffset, 0, len(fieldsMap)) 29 | for name, offset := range fieldsMap { 30 | fields = append(fields, ottest.FieldOffset{ 31 | Name: name, 32 | Offset: offset, 33 | }) 34 | } 35 | if !ottest.Aligned8Byte(fields, os.Stderr) { 36 | os.Exit(1) 37 | } 38 | 39 | os.Exit(m.Run()) 40 | } 41 | -------------------------------------------------------------------------------- /trace_test.go: -------------------------------------------------------------------------------- 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 otel 16 | 17 | import ( 18 | "testing" 19 | 20 | "github.com/stretchr/testify/assert" 21 | 22 | "go.opentelemetry.io/otel/internal/trace/noop" 23 | "go.opentelemetry.io/otel/trace" 24 | ) 25 | 26 | type testTracerProvider struct{} 27 | 28 | var _ trace.TracerProvider = &testTracerProvider{} 29 | 30 | func (*testTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer { 31 | return noop.Tracer 32 | } 33 | 34 | func TestMultipleGlobalTracerProvider(t *testing.T) { 35 | p1 := testTracerProvider{} 36 | p2 := trace.NewNoopTracerProvider() 37 | SetTracerProvider(&p1) 38 | SetTracerProvider(p2) 39 | 40 | got := GetTracerProvider() 41 | assert.Equal(t, p2, got) 42 | } 43 | -------------------------------------------------------------------------------- /metric/sdkapi/sdkapi_test.go: -------------------------------------------------------------------------------- 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 sdkapi 16 | 17 | import ( 18 | "testing" 19 | 20 | "github.com/stretchr/testify/require" 21 | 22 | "go.opentelemetry.io/otel/metric/number" 23 | ) 24 | 25 | func TestMeasurementGetters(t *testing.T) { 26 | num := number.NewFloat64Number(1.5) 27 | si := NewNoopSyncInstrument() 28 | meas := NewMeasurement(si, num) 29 | 30 | require.Equal(t, si, meas.SyncImpl()) 31 | require.Equal(t, num, meas.Number()) 32 | } 33 | 34 | func TestObservationGetters(t *testing.T) { 35 | num := number.NewFloat64Number(1.5) 36 | ai := NewNoopAsyncInstrument() 37 | obs := NewObservation(ai, num) 38 | 39 | require.Equal(t, ai, obs.AsyncImpl()) 40 | require.Equal(t, num, obs.Number()) 41 | } 42 | -------------------------------------------------------------------------------- /sdk/metric/alignment_test.go: -------------------------------------------------------------------------------- 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 metric 16 | 17 | import ( 18 | "os" 19 | "testing" 20 | "unsafe" 21 | 22 | ottest "go.opentelemetry.io/otel/internal/internaltest" 23 | ) 24 | 25 | // Ensure struct alignment prior to running tests. 26 | func TestMain(m *testing.M) { 27 | offsets := map[string]uintptr{ 28 | "record.refMapped.value": unsafe.Offsetof(record{}.refMapped.value), 29 | "record.updateCount": unsafe.Offsetof(record{}.updateCount), 30 | } 31 | var r []ottest.FieldOffset 32 | for name, offset := range offsets { 33 | r = append(r, ottest.FieldOffset{ 34 | Name: name, 35 | Offset: offset, 36 | }) 37 | } 38 | if !ottest.Aligned8Byte(r, os.Stderr) { 39 | os.Exit(1) 40 | } 41 | 42 | os.Exit(m.Run()) 43 | } 44 | -------------------------------------------------------------------------------- /schema/go.sum: -------------------------------------------------------------------------------- 1 | github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= 2 | github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= 3 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 4 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 5 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 6 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 7 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 8 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 9 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 10 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 11 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 12 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 13 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 14 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 15 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 16 | -------------------------------------------------------------------------------- /get_main_pkgs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright The OpenTelemetry Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -euo pipefail 18 | 19 | top_dir='.' 20 | if [[ $# -gt 0 ]]; then 21 | top_dir="${1}" 22 | fi 23 | 24 | p=$(pwd) 25 | mod_dirs=() 26 | 27 | # Note `mapfile` does not exist in older bash versions: 28 | # https://stackoverflow.com/questions/41475261/need-alternative-to-readarray-mapfile-for-script-on-older-version-of-bash 29 | 30 | while IFS= read -r line; do 31 | mod_dirs+=("$line") 32 | done < <(find "${top_dir}" -type f -name 'go.mod' -exec dirname {} \; | sort) 33 | 34 | for mod_dir in "${mod_dirs[@]}"; do 35 | cd "${mod_dir}" 36 | 37 | while IFS= read -r line; do 38 | echo ".${line#${p}}" 39 | done < <(go list --find -f '{{.Name}}|{{.Dir}}' ./... | grep '^main|' | cut -f 2- -d '|') 40 | cd "${p}" 41 | done 42 | -------------------------------------------------------------------------------- /sdk/instrumentation/library.go: -------------------------------------------------------------------------------- 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 | /* 16 | Package instrumentation provides an instrumentation library structure to be 17 | passed to both the OpenTelemetry Tracer and Meter components. 18 | 19 | For more information see 20 | [this](https://github.com/open-telemetry/oteps/blob/main/text/0083-component.md). 21 | */ 22 | package instrumentation // import "go.opentelemetry.io/otel/sdk/instrumentation" 23 | 24 | // Library represents the instrumentation library. 25 | type Library struct { 26 | // Name is the name of the instrumentation library. This should be the 27 | // Go package name of that library. 28 | Name string 29 | // Version is the version of the instrumentation library. 30 | Version string 31 | // SchemaURL of the telemetry emitted by the library. 32 | SchemaURL string 33 | } 34 | -------------------------------------------------------------------------------- /sdk/internal/internal.go: -------------------------------------------------------------------------------- 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 internal // import "go.opentelemetry.io/otel/sdk/internal" 16 | 17 | import ( 18 | "fmt" 19 | "time" 20 | 21 | "go.opentelemetry.io/otel" 22 | ) 23 | 24 | // UserAgent is the user agent to be added to the outgoing 25 | // requests from the exporters. 26 | var UserAgent = fmt.Sprintf("opentelemetry-go/%s", otel.Version()) 27 | 28 | // MonotonicEndTime returns the end time at present 29 | // but offset from start, monotonically. 30 | // 31 | // The monotonic clock is used in subtractions hence 32 | // the duration since start added back to start gives 33 | // end as a monotonic time. 34 | // See https://golang.org/pkg/time/#hdr-Monotonic_Clocks 35 | func MonotonicEndTime(start time.Time) time.Time { 36 | return start.Add(time.Since(start)) 37 | } 38 | -------------------------------------------------------------------------------- /example/otel-collector/k8s/prometheus-monitor.yaml: -------------------------------------------------------------------------------- 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 | apiVersion: monitoring.coreos.com/v1 16 | kind: Prometheus 17 | metadata: 18 | labels: 19 | app: prometheus 20 | prometheus: service-prometheus 21 | name: service-prometheus 22 | namespace: monitoring 23 | spec: 24 | alerting: 25 | alertmanagers: 26 | - name: alertmanager-main 27 | namespace: monitoring 28 | port: web 29 | baseImage: quay.io/prometheus/prometheus 30 | logLevel: info 31 | paused: false 32 | replicas: 2 33 | retention: 2d 34 | routePrefix: / 35 | ruleSelector: 36 | matchLabels: 37 | prometheus: service-prometheus 38 | role: alert-rules 39 | serviceAccountName: prometheus-k8s 40 | serviceMonitorSelector: 41 | matchExpressions: 42 | - key: serviceapp 43 | operator: Exists 44 | -------------------------------------------------------------------------------- /internal/metric/global/state_test.go: -------------------------------------------------------------------------------- 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 global_test 16 | 17 | import ( 18 | "testing" 19 | 20 | internalglobal "go.opentelemetry.io/otel/internal/metric/global" 21 | metricglobal "go.opentelemetry.io/otel/metric/global" 22 | ) 23 | 24 | func TestResetsOfGlobalsPanic(t *testing.T) { 25 | internalglobal.ResetForTest() 26 | tests := map[string]func(){ 27 | "SetMeterProvider": func() { 28 | metricglobal.SetMeterProvider(metricglobal.GetMeterProvider()) 29 | }, 30 | } 31 | 32 | for name, test := range tests { 33 | shouldPanic(t, name, test) 34 | } 35 | } 36 | 37 | func shouldPanic(t *testing.T, name string, f func()) { 38 | defer func() { 39 | if r := recover(); r == nil { 40 | t.Errorf("calling %s with default global did not panic", name) 41 | } 42 | }() 43 | 44 | f() 45 | } 46 | -------------------------------------------------------------------------------- /internal/global/state_test.go: -------------------------------------------------------------------------------- 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 global_test 16 | 17 | import ( 18 | "testing" 19 | 20 | "go.opentelemetry.io/otel/internal/global" 21 | ) 22 | 23 | func TestResetsOfGlobalsPanic(t *testing.T) { 24 | global.ResetForTest() 25 | tests := map[string]func(){ 26 | "SetTextMapPropagator": func() { 27 | global.SetTextMapPropagator(global.TextMapPropagator()) 28 | }, 29 | "SetTracerProvider": func() { 30 | global.SetTracerProvider(global.TracerProvider()) 31 | }, 32 | } 33 | 34 | for name, test := range tests { 35 | shouldPanic(t, name, test) 36 | } 37 | } 38 | 39 | func shouldPanic(t *testing.T, name string, f func()) { 40 | defer func() { 41 | if r := recover(); r == nil { 42 | t.Errorf("calling %s with default global did not panic", name) 43 | } 44 | }() 45 | 46 | f() 47 | } 48 | -------------------------------------------------------------------------------- /sdk/resource/doc.go: -------------------------------------------------------------------------------- 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 resource provides detecting and representing resources. 16 | // 17 | // The fundamental struct is a Resource which holds identifying information 18 | // about the entities for which telemetry is exported. 19 | // 20 | // To automatically construct Resources from an environment a Detector 21 | // interface is defined. Implementations of this interface can be passed to 22 | // the Detect function to generate a Resource from the merged information. 23 | // 24 | // To load a user defined Resource from the environment variable 25 | // OTEL_RESOURCE_ATTRIBUTES the FromEnv Detector can be used. It will interpret 26 | // the value as a list of comma delimited key/value pairs 27 | // (e.g. `=,=,...`). 28 | package resource // import "go.opentelemetry.io/otel/sdk/resource" 29 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/third_party/thrift/lib/go/thrift/server.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | type TServer interface { 23 | ProcessorFactory() TProcessorFactory 24 | ServerTransport() TServerTransport 25 | InputTransportFactory() TTransportFactory 26 | OutputTransportFactory() TTransportFactory 27 | InputProtocolFactory() TProtocolFactory 28 | OutputProtocolFactory() TProtocolFactory 29 | 30 | // Starts the server 31 | Serve() error 32 | // Stops the server. This is optional on a per-implementation basis. Not 33 | // all servers are required to be cleanly stoppable. 34 | Stop() error 35 | } 36 | -------------------------------------------------------------------------------- /bridge/opentracing/migration/defer.go: -------------------------------------------------------------------------------- 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 migration // import "go.opentelemetry.io/otel/bridge/opentracing/migration" 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | type doDeferredContextSetupType struct{} 22 | 23 | // WithDeferredSetup returns a context that can tell the OpenTelemetry 24 | // tracer to skip the context setup in the Start() function. 25 | func WithDeferredSetup(ctx context.Context) context.Context { 26 | return context.WithValue(ctx, doDeferredContextSetupType{}, doDeferredContextSetupType{}) 27 | } 28 | 29 | // SkipContextSetup can tell the OpenTelemetry tracer to skip the 30 | // context setup during the span creation in the Start() function. 31 | func SkipContextSetup(ctx context.Context) bool { 32 | _, ok := ctx.Value(doDeferredContextSetupType{}).(doDeferredContextSetupType) 33 | return ok 34 | } 35 | -------------------------------------------------------------------------------- /internal/rawhelpers.go: -------------------------------------------------------------------------------- 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 internal // import "go.opentelemetry.io/otel/internal" 16 | 17 | import ( 18 | "math" 19 | "unsafe" 20 | ) 21 | 22 | func BoolToRaw(b bool) uint64 { 23 | if b { 24 | return 1 25 | } 26 | return 0 27 | } 28 | 29 | func RawToBool(r uint64) bool { 30 | return r != 0 31 | } 32 | 33 | func Int64ToRaw(i int64) uint64 { 34 | return uint64(i) 35 | } 36 | 37 | func RawToInt64(r uint64) int64 { 38 | return int64(r) 39 | } 40 | 41 | func Float64ToRaw(f float64) uint64 { 42 | return math.Float64bits(f) 43 | } 44 | 45 | func RawToFloat64(r uint64) float64 { 46 | return math.Float64frombits(r) 47 | } 48 | 49 | func RawPtrToFloat64Ptr(r *uint64) *float64 { 50 | return (*float64)(unsafe.Pointer(r)) 51 | } 52 | 53 | func RawPtrToInt64Ptr(r *uint64) *int64 { 54 | return (*int64)(unsafe.Pointer(r)) 55 | } 56 | -------------------------------------------------------------------------------- /website_docs/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Go 3 | description: >- 4 | 5 | A language-specific implementation of OpenTelemetry in Go. 6 | aliases: [/golang, /golang/metrics, /golang/tracing] 7 | cascade: 8 | github_repo: &repo https://github.com/open-telemetry/opentelemetry-go 9 | github_subdir: website_docs 10 | path_base_for_github_subdir: content/en/docs/go/ 11 | github_project_repo: *repo 12 | spelling: cSpell:ignore godoc 13 | weight: 16 14 | --- 15 | 16 | This is the OpenTelemetry for Go documentation. OpenTelemetry is an observability framework -- an API, SDK, and tools that are designed to aid in the generation and collection of application telemetry data such as metrics, logs, and traces. This documentation is designed to help you understand how to get started using OpenTelemetry for Go. 17 | 18 | ## Status and Releases 19 | 20 | The current status of the major functional components for OpenTelemetry Go is as follows: 21 | 22 | | Tracing | Metrics | Logging | 23 | | ------- | ------- | ------- | 24 | | Stable | Alpha | Not Yet Implemented | 25 | 26 | {{% latest_release "go" /%}} 27 | 28 | ## Further Reading 29 | 30 | - [godoc](https://pkg.go.dev/go.opentelemetry.io/otel) 31 | - [Examples](https://github.com/open-telemetry/opentelemetry-go/tree/main/example) 32 | - [Contrib Repository](https://github.com/open-telemetry/opentelemetry-go-contrib) 33 | -------------------------------------------------------------------------------- /metric/sdkapi/instrumentkind_test.go: -------------------------------------------------------------------------------- 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 sdkapi_test 16 | 17 | import ( 18 | "testing" 19 | 20 | "github.com/stretchr/testify/require" 21 | 22 | "go.opentelemetry.io/otel/metric/sdkapi" 23 | ) 24 | 25 | func TestInstrumentKinds(t *testing.T) { 26 | require.Equal(t, sdkapi.HistogramInstrumentKind.String(), "HistogramInstrumentKind") 27 | require.Equal(t, sdkapi.GaugeObserverInstrumentKind.String(), "GaugeObserverInstrumentKind") 28 | require.Equal(t, sdkapi.CounterInstrumentKind.String(), "CounterInstrumentKind") 29 | require.Equal(t, sdkapi.UpDownCounterInstrumentKind.String(), "UpDownCounterInstrumentKind") 30 | require.Equal(t, sdkapi.CounterObserverInstrumentKind.String(), "CounterObserverInstrumentKind") 31 | require.Equal(t, sdkapi.UpDownCounterObserverInstrumentKind.String(), "UpDownCounterObserverInstrumentKind") 32 | } 33 | -------------------------------------------------------------------------------- /sdk/resource/export_test.go: -------------------------------------------------------------------------------- 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 resource // import "go.opentelemetry.io/otel/sdk/resource" 16 | 17 | var ( 18 | SetDefaultOSProviders = setDefaultOSProviders 19 | SetOSProviders = setOSProviders 20 | SetDefaultRuntimeProviders = setDefaultRuntimeProviders 21 | SetRuntimeProviders = setRuntimeProviders 22 | SetDefaultUserProviders = setDefaultUserProviders 23 | SetUserProviders = setUserProviders 24 | SetDefaultOSDescriptionProvider = setDefaultOSDescriptionProvider 25 | SetOSDescriptionProvider = setOSDescriptionProvider 26 | ) 27 | 28 | var ( 29 | CommandArgs = commandArgs 30 | RuntimeName = runtimeName 31 | RuntimeOS = runtimeOS 32 | RuntimeArch = runtimeArch 33 | ) 34 | 35 | var ( 36 | MapRuntimeOSToSemconvOSType = mapRuntimeOSToSemconvOSType 37 | ) 38 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/third_party/thrift/lib/go/thrift/server_transport.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // Server transport. Object which provides client transports. 23 | type TServerTransport interface { 24 | Listen() error 25 | Accept() (TTransport, error) 26 | Close() error 27 | 28 | // Optional method implementation. This signals to the server transport 29 | // that it should break out of any accept() or listen() that it is currently 30 | // blocked on. This method, if implemented, MUST be thread safe, as it may 31 | // be called from a different thread context than the other TServerTransport 32 | // methods. 33 | Interrupt() error 34 | } 35 | -------------------------------------------------------------------------------- /internal/metric/global/benchmark_test.go: -------------------------------------------------------------------------------- 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 global_test 16 | 17 | import ( 18 | "context" 19 | "testing" 20 | 21 | "go.opentelemetry.io/otel/attribute" 22 | internalglobal "go.opentelemetry.io/otel/internal/metric/global" 23 | metricglobal "go.opentelemetry.io/otel/metric/global" 24 | ) 25 | 26 | func BenchmarkGlobalInt64CounterAddNoSDK(b *testing.B) { 27 | // Compare with BenchmarkGlobalInt64CounterAddWithSDK() in 28 | // ../../sdk/metric/benchmark_test.go to see the overhead of the 29 | // global no-op system against a registered SDK. 30 | internalglobal.ResetForTest() 31 | ctx := context.Background() 32 | sdk := metricglobal.Meter("test") 33 | labs := []attribute.KeyValue{attribute.String("A", "B")} 34 | cnt := Must(sdk).NewInt64Counter("int64.counter") 35 | 36 | b.ResetTimer() 37 | 38 | for i := 0; i < b.N; i++ { 39 | cnt.Add(ctx, 1, labs...) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /error_handler.go: -------------------------------------------------------------------------------- 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 otel // import "go.opentelemetry.io/otel" 16 | 17 | // ErrorHandler handles irremediable events. 18 | type ErrorHandler interface { 19 | // DO NOT CHANGE: any modification will not be backwards compatible and 20 | // must never be done outside of a new major release. 21 | 22 | // Handle handles any error deemed irremediable by an OpenTelemetry 23 | // component. 24 | Handle(error) 25 | // DO NOT CHANGE: any modification will not be backwards compatible and 26 | // must never be done outside of a new major release. 27 | } 28 | 29 | // ErrorHandlerFunc is a convenience adapter to allow the use of a function 30 | // as an ErrorHandler. 31 | type ErrorHandlerFunc func(error) 32 | 33 | var _ ErrorHandler = ErrorHandlerFunc(nil) 34 | 35 | // Handle handles the irremediable error by calling the ErrorHandlerFunc itself. 36 | func (f ErrorHandlerFunc) Handle(err error) { 37 | f(err) 38 | } 39 | -------------------------------------------------------------------------------- /example/namedtracer/foo/foo.go: -------------------------------------------------------------------------------- 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 foo // import "go.opentelemetry.io/otel/example/namedtracer/foo" 16 | 17 | import ( 18 | "context" 19 | 20 | "go.opentelemetry.io/otel" 21 | "go.opentelemetry.io/otel/attribute" 22 | "go.opentelemetry.io/otel/trace" 23 | ) 24 | 25 | var ( 26 | lemonsKey = attribute.Key("ex.com/lemons") 27 | ) 28 | 29 | // SubOperation is an example to demonstrate the use of named tracer. 30 | // It creates a named tracer with its package path. 31 | func SubOperation(ctx context.Context) error { 32 | // Using global provider. Alternative is to have application provide a getter 33 | // for its component to get the instance of the provider. 34 | tr := otel.Tracer("example/namedtracer/foo") 35 | 36 | var span trace.Span 37 | _, span = tr.Start(ctx, "Sub operation...") 38 | defer span.End() 39 | span.SetAttributes(lemonsKey.String("five")) 40 | span.AddEvent("Sub span event") 41 | 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /.github/workflows/markdown.yml: -------------------------------------------------------------------------------- 1 | name: markdown 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | jobs: 8 | changedfiles: 9 | name: changed files 10 | runs-on: ubuntu-latest 11 | outputs: 12 | md: ${{ steps.changes.outputs.md }} 13 | steps: 14 | - name: Checkout Repo 15 | uses: actions/checkout@v2 16 | with: 17 | fetch-depth: 0 18 | - name: Get changed files 19 | id: changes 20 | run: | 21 | echo "::set-output name=md::$(git diff --name-only --diff-filter=ACMRTUXB origin/${{ github.event.pull_request.base.ref }} ${{ github.event.pull_request.head.sha }} | grep .md$ | xargs)" 22 | 23 | lint: 24 | name: lint markdown files 25 | runs-on: ubuntu-latest 26 | needs: changedfiles 27 | if: ${{needs.changedfiles.outputs.md}} 28 | steps: 29 | - name: Checkout Repo 30 | uses: actions/checkout@v2 31 | - name: Run linter 32 | uses: docker://avtodev/markdown-lint:v1 33 | with: 34 | args: ${{needs.changedfiles.outputs.md}} 35 | 36 | check-links: 37 | runs-on: ubuntu-latest 38 | steps: 39 | - name: Checkout Repo 40 | uses: actions/checkout@v2 41 | with: 42 | fetch-depth: 0 43 | - uses: gaurav-nelson/github-action-markdown-link-check@v1 44 | with: 45 | base-branch: 'main' 46 | use-quiet-mode: 'yes' 47 | use-verbose-mode: 'yes' 48 | config-file: '.markdown-link.json' 49 | check-modified-files-only: 'yes' 50 | folder-path: '' 51 | -------------------------------------------------------------------------------- /schema/v1.0/ast/metrics.go: -------------------------------------------------------------------------------- 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 ast // import "go.opentelemetry.io/otel/schema/v1.0/ast" 16 | 17 | import "go.opentelemetry.io/otel/schema/v1.0/types" 18 | 19 | // Metrics corresponds to a section representing a list of changes that happened 20 | // to metrics schema in a particular version. 21 | type Metrics struct { 22 | Changes []MetricsChange 23 | } 24 | 25 | // MetricsChange corresponds to a section representing metrics change. 26 | type MetricsChange struct { 27 | RenameMetrics map[types.MetricName]types.MetricName `yaml:"rename_metrics"` 28 | RenameAttributes *AttributeMapForMetrics `yaml:"rename_attributes"` 29 | } 30 | 31 | // AttributeMapForMetrics corresponds to a section representing a translation of 32 | // attributes for specific metrics. 33 | type AttributeMapForMetrics struct { 34 | ApplyToMetrics []types.MetricName `yaml:"apply_to_metrics"` 35 | AttributeMap AttributeMap `yaml:"attribute_map"` 36 | } 37 | -------------------------------------------------------------------------------- /sdk/internal/sanitize.go: -------------------------------------------------------------------------------- 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 internal // import "go.opentelemetry.io/otel/sdk/internal" 16 | 17 | import ( 18 | "strings" 19 | "unicode" 20 | ) 21 | 22 | const labelKeySizeLimit = 100 23 | 24 | // Sanitize returns a string that is trunacated to 100 characters if it's too 25 | // long, and replaces non-alphanumeric characters to underscores. 26 | func Sanitize(s string) string { 27 | if len(s) == 0 { 28 | return s 29 | } 30 | if len(s) > labelKeySizeLimit { 31 | s = s[:labelKeySizeLimit] 32 | } 33 | s = strings.Map(sanitizeRune, s) 34 | if unicode.IsDigit(rune(s[0])) { 35 | s = "key_" + s 36 | } 37 | if s[0] == '_' { 38 | s = "key" + s 39 | } 40 | return s 41 | } 42 | 43 | // converts anything that is not a letter or digit to an underscore 44 | func sanitizeRune(r rune) rune { 45 | if unicode.IsLetter(r) || unicode.IsDigit(r) { 46 | return r 47 | } 48 | // Everything else turns into an underscore 49 | return '_' 50 | } 51 | -------------------------------------------------------------------------------- /bridge/opencensus/internal/oc2otel/attributes.go: -------------------------------------------------------------------------------- 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 oc2otel // import "go.opentelemetry.io/otel/bridge/opencensus/internal/oc2otel" 16 | 17 | import ( 18 | octrace "go.opencensus.io/trace" 19 | 20 | "go.opentelemetry.io/otel/attribute" 21 | ) 22 | 23 | func Attributes(attr []octrace.Attribute) []attribute.KeyValue { 24 | otelAttr := make([]attribute.KeyValue, len(attr)) 25 | for i, a := range attr { 26 | otelAttr[i] = attribute.KeyValue{ 27 | Key: attribute.Key(a.Key()), 28 | Value: AttributeValue(a.Value()), 29 | } 30 | } 31 | return otelAttr 32 | } 33 | 34 | func AttributeValue(ocval interface{}) attribute.Value { 35 | switch v := ocval.(type) { 36 | case bool: 37 | return attribute.BoolValue(v) 38 | case int64: 39 | return attribute.Int64Value(v) 40 | case float64: 41 | return attribute.Float64Value(v) 42 | case string: 43 | return attribute.StringValue(v) 44 | default: 45 | return attribute.StringValue("unknown") 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /baggage/context.go: -------------------------------------------------------------------------------- 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 baggage // import "go.opentelemetry.io/otel/baggage" 16 | 17 | import ( 18 | "context" 19 | 20 | "go.opentelemetry.io/otel/internal/baggage" 21 | ) 22 | 23 | // ContextWithBaggage returns a copy of parent with baggage. 24 | func ContextWithBaggage(parent context.Context, b Baggage) context.Context { 25 | // Delegate so any hooks for the OpenTracing bridge are handled. 26 | return baggage.ContextWithList(parent, b.list) 27 | } 28 | 29 | // ContextWithoutBaggage returns a copy of parent with no baggage. 30 | func ContextWithoutBaggage(parent context.Context) context.Context { 31 | // Delegate so any hooks for the OpenTracing bridge are handled. 32 | return baggage.ContextWithList(parent, nil) 33 | } 34 | 35 | // FromContext returns the baggage contained in ctx. 36 | func FromContext(ctx context.Context) Baggage { 37 | // Delegate so any hooks for the OpenTracing bridge are handled. 38 | return Baggage{list: baggage.ListFromContext(ctx)} 39 | } 40 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 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 | /* 16 | Package otel provides global access to the OpenTelemetry API. The subpackages of 17 | the otel package provide an implementation of the OpenTelemetry API. 18 | 19 | The provided API is used to instrument code and measure data about that code's 20 | performance and operation. The measured data, by default, is not processed or 21 | transmitted anywhere. An implementation of the OpenTelemetry SDK, like the 22 | default SDK implementation (go.opentelemetry.io/otel/sdk), and associated 23 | exporters are used to process and transport this data. 24 | 25 | To read the getting started guide, see https://opentelemetry.io/docs/go/getting-started/. 26 | 27 | To read more about tracing, see go.opentelemetry.io/otel/trace. 28 | 29 | To read more about metrics, see go.opentelemetry.io/otel/metric. 30 | 31 | To read more about propagation, see go.opentelemetry.io/otel/propagation and 32 | go.opentelemetry.io/otel/baggage. 33 | */ 34 | package otel // import "go.opentelemetry.io/otel" 35 | -------------------------------------------------------------------------------- /trace/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 4 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 5 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 6 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 7 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 8 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 9 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 10 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 11 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 12 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 13 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 14 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 15 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 16 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 17 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 18 | -------------------------------------------------------------------------------- /exporters/otlp/otlpmetric/internal/metrictransform/resource_test.go: -------------------------------------------------------------------------------- 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 metrictransform 16 | 17 | import ( 18 | "testing" 19 | 20 | "github.com/stretchr/testify/assert" 21 | 22 | "go.opentelemetry.io/otel/attribute" 23 | "go.opentelemetry.io/otel/sdk/resource" 24 | ) 25 | 26 | func TestNilResource(t *testing.T) { 27 | assert.Empty(t, Resource(nil)) 28 | } 29 | 30 | func TestEmptyResource(t *testing.T) { 31 | assert.Empty(t, Resource(&resource.Resource{})) 32 | } 33 | 34 | /* 35 | * This does not include any testing on the ordering of Resource Attributes. 36 | * They are stored as a map internally to the Resource and their order is not 37 | * guaranteed. 38 | */ 39 | 40 | func TestResourceAttributes(t *testing.T) { 41 | attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)} 42 | 43 | got := Resource(resource.NewSchemaless(attrs...)).GetAttributes() 44 | if !assert.Len(t, attrs, 2) { 45 | return 46 | } 47 | assert.ElementsMatch(t, KeyValues(attrs), got) 48 | } 49 | -------------------------------------------------------------------------------- /exporters/otlp/otlptrace/internal/tracetransform/resource_test.go: -------------------------------------------------------------------------------- 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 tracetransform 16 | 17 | import ( 18 | "testing" 19 | 20 | "github.com/stretchr/testify/assert" 21 | 22 | "go.opentelemetry.io/otel/attribute" 23 | "go.opentelemetry.io/otel/sdk/resource" 24 | ) 25 | 26 | func TestNilResource(t *testing.T) { 27 | assert.Empty(t, Resource(nil)) 28 | } 29 | 30 | func TestEmptyResource(t *testing.T) { 31 | assert.Empty(t, Resource(&resource.Resource{})) 32 | } 33 | 34 | /* 35 | * This does not include any testing on the ordering of Resource Attributes. 36 | * They are stored as a map internally to the Resource and their order is not 37 | * guaranteed. 38 | */ 39 | 40 | func TestResourceAttributes(t *testing.T) { 41 | attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)} 42 | 43 | got := Resource(resource.NewSchemaless(attrs...)).GetAttributes() 44 | if !assert.Len(t, attrs, 2) { 45 | return 46 | } 47 | assert.ElementsMatch(t, KeyValues(attrs), got) 48 | } 49 | -------------------------------------------------------------------------------- /sdk/metric/controller/time/time.go: -------------------------------------------------------------------------------- 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 time // import "go.opentelemetry.io/otel/sdk/metric/controller/time" 16 | 17 | import ( 18 | "time" 19 | lib "time" 20 | ) 21 | 22 | // Several types below are created to match "github.com/benbjohnson/clock" 23 | // so that it remains a test-only dependency. 24 | 25 | type Clock interface { 26 | Now() lib.Time 27 | Ticker(duration lib.Duration) Ticker 28 | } 29 | 30 | type Ticker interface { 31 | Stop() 32 | C() <-chan lib.Time 33 | } 34 | 35 | type RealClock struct { 36 | } 37 | 38 | type RealTicker struct { 39 | ticker *lib.Ticker 40 | } 41 | 42 | var _ Clock = RealClock{} 43 | var _ Ticker = RealTicker{} 44 | 45 | func (RealClock) Now() time.Time { 46 | return time.Now() 47 | } 48 | 49 | func (RealClock) Ticker(period time.Duration) Ticker { 50 | return RealTicker{time.NewTicker(period)} 51 | } 52 | 53 | func (t RealTicker) Stop() { 54 | t.ticker.Stop() 55 | } 56 | 57 | func (t RealTicker) C() <-chan time.Time { 58 | return t.ticker.C 59 | } 60 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/third_party/thrift/lib/go/thrift/transport_factory.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // Factory class used to create wrapped instance of Transports. 23 | // This is used primarily in servers, which get Transports from 24 | // a ServerTransport and then may want to mutate them (i.e. create 25 | // a BufferedTransport from the underlying base transport) 26 | type TTransportFactory interface { 27 | GetTransport(trans TTransport) (TTransport, error) 28 | } 29 | 30 | type tTransportFactory struct{} 31 | 32 | // Return a wrapped instance of the base Transport. 33 | func (p *tTransportFactory) GetTransport(trans TTransport) (TTransport, error) { 34 | return trans, nil 35 | } 36 | 37 | func NewTTransportFactory() TTransportFactory { 38 | return &tTransportFactory{} 39 | } 40 | -------------------------------------------------------------------------------- /sdk/metric/processor/basic/config.go: -------------------------------------------------------------------------------- 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 basic // import "go.opentelemetry.io/otel/sdk/metric/processor/basic" 16 | 17 | // config contains the options for configuring a basic metric processor. 18 | type config struct { 19 | // Memory controls whether the processor remembers metric 20 | // instruments and label sets that were previously reported. 21 | // When Memory is true, Reader.ForEach() will visit 22 | // metrics that were not updated in the most recent interval. 23 | Memory bool 24 | } 25 | 26 | type Option interface { 27 | applyProcessor(*config) 28 | } 29 | 30 | // WithMemory sets the memory behavior of a Processor. If this is 31 | // true, the processor will report metric instruments and label sets 32 | // that were previously reported but not updated in the most recent 33 | // interval. 34 | func WithMemory(memory bool) Option { 35 | return memoryOption(memory) 36 | } 37 | 38 | type memoryOption bool 39 | 40 | func (m memoryOption) applyProcessor(cfg *config) { 41 | cfg.Memory = bool(m) 42 | } 43 | -------------------------------------------------------------------------------- /exporters/jaeger/assertsocketbuffersize_test.go: -------------------------------------------------------------------------------- 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 | //go:build !windows 16 | // +build !windows 17 | 18 | package jaeger 19 | 20 | import ( 21 | "net" 22 | "runtime" 23 | "syscall" 24 | "testing" 25 | 26 | "github.com/stretchr/testify/assert" 27 | ) 28 | 29 | func assertSockBufferSize(t *testing.T, expectedBytes int, conn *net.UDPConn) bool { 30 | fd, err := conn.File() 31 | if !assert.NoError(t, err) { 32 | return false 33 | } 34 | 35 | bufferBytes, err := syscall.GetsockoptInt(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_SNDBUF) 36 | if !assert.NoError(t, err) { 37 | return false 38 | } 39 | 40 | // The linux kernel doubles SO_SNDBUF value (to allow space for 41 | // bookkeeping overhead) when it is set using setsockopt(2), and this 42 | // doubled value is returned by getsockopt(2) 43 | // https://linux.die.net/man/7/socket 44 | if runtime.GOOS == "linux" { 45 | return assert.GreaterOrEqual(t, expectedBytes*2, bufferBytes) 46 | } 47 | 48 | return assert.Equal(t, expectedBytes, bufferBytes) 49 | } 50 | -------------------------------------------------------------------------------- /exporters/otlp/otlpmetric/internal/otlpconfig/tls.go: -------------------------------------------------------------------------------- 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 otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal/otlpconfig" 16 | 17 | import ( 18 | "crypto/tls" 19 | "crypto/x509" 20 | "errors" 21 | "io/ioutil" 22 | ) 23 | 24 | // ReadTLSConfigFromFile reads a PEM certificate file and creates 25 | // a tls.Config that will use this certifate to verify a server certificate. 26 | func ReadTLSConfigFromFile(path string) (*tls.Config, error) { 27 | b, err := ioutil.ReadFile(path) 28 | if err != nil { 29 | return nil, err 30 | } 31 | 32 | return CreateTLSConfig(b) 33 | } 34 | 35 | // CreateTLSConfig creates a tls.Config from a raw certificate bytes 36 | // to verify a server certificate. 37 | func CreateTLSConfig(certBytes []byte) (*tls.Config, error) { 38 | cp := x509.NewCertPool() 39 | if ok := cp.AppendCertsFromPEM(certBytes); !ok { 40 | return nil, errors.New("failed to append certificate to the cert pool") 41 | } 42 | 43 | return &tls.Config{ 44 | RootCAs: cp, 45 | }, nil 46 | } 47 | -------------------------------------------------------------------------------- /exporters/otlp/otlpmetric/options.go: -------------------------------------------------------------------------------- 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 otlpmetric // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric" 16 | 17 | import "go.opentelemetry.io/otel/sdk/metric/export/aggregation" 18 | 19 | // Option are setting options passed to an Exporter on creation. 20 | type Option interface { 21 | apply(*config) 22 | } 23 | 24 | type exporterOptionFunc func(*config) 25 | 26 | func (fn exporterOptionFunc) apply(cfg *config) { 27 | fn(cfg) 28 | } 29 | 30 | type config struct { 31 | temporalitySelector aggregation.TemporalitySelector 32 | } 33 | 34 | // WithMetricAggregationTemporalitySelector defines the aggregation.TemporalitySelector used 35 | // for selecting aggregation.Temporality (i.e., Cumulative vs. Delta 36 | // aggregation). If not specified otherwise, exporter will use a 37 | // cumulative temporality selector. 38 | func WithMetricAggregationTemporalitySelector(selector aggregation.TemporalitySelector) Option { 39 | return exporterOptionFunc(func(cfg *config) { 40 | cfg.temporalitySelector = selector 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /bridge/opencensus/internal/oc2otel/tracer_start_options.go: -------------------------------------------------------------------------------- 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 oc2otel // import "go.opentelemetry.io/otel/bridge/opencensus/internal/oc2otel" 16 | 17 | import ( 18 | "fmt" 19 | 20 | octrace "go.opencensus.io/trace" 21 | 22 | "go.opentelemetry.io/otel/trace" 23 | ) 24 | 25 | func StartOptions(optFuncs []octrace.StartOption) ([]trace.SpanStartOption, error) { 26 | var ocOpts octrace.StartOptions 27 | for _, fn := range optFuncs { 28 | fn(&ocOpts) 29 | } 30 | 31 | var otelOpts []trace.SpanStartOption 32 | switch ocOpts.SpanKind { 33 | case octrace.SpanKindClient: 34 | otelOpts = append(otelOpts, trace.WithSpanKind(trace.SpanKindClient)) 35 | case octrace.SpanKindServer: 36 | otelOpts = append(otelOpts, trace.WithSpanKind(trace.SpanKindServer)) 37 | case octrace.SpanKindUnspecified: 38 | otelOpts = append(otelOpts, trace.WithSpanKind(trace.SpanKindUnspecified)) 39 | } 40 | 41 | var err error 42 | if ocOpts.Sampler != nil { 43 | err = fmt.Errorf("unsupported sampler: %v", ocOpts.Sampler) 44 | } 45 | return otelOpts, err 46 | } 47 | -------------------------------------------------------------------------------- /internal/metric/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= 4 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 5 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 6 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 7 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 8 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 9 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 12 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 13 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 14 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 15 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 16 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 17 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 18 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 19 | -------------------------------------------------------------------------------- /example/passthrough/README.md: -------------------------------------------------------------------------------- 1 | # "Passthrough" setup for OpenTelemetry 2 | 3 | Some Go programs may wish to propagate context without recording spans. To do this in OpenTelemetry, simply install `TextMapPropagators`, but do not install a TracerProvider using the SDK. This works because the default TracerProvider implementation returns a "Non-Recording" span that keeps the context of the caller but does not record spans. 4 | 5 | For example, when you initialize your global settings, the following will propagate context without recording spans: 6 | 7 | ```golang 8 | // Setup Propagators only 9 | otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) 10 | ``` 11 | 12 | But the following will propagate context _and_ create new, potentially recorded spans: 13 | 14 | ```golang 15 | // Setup SDK 16 | exp, _ := stdout.New(stdout.WithPrettyPrint()) 17 | tp = sdktrace.NewTracerProvider( 18 | sdktrace.WithBatcher(exp), 19 | ) 20 | otel.SetTracerProvider(tp) 21 | // Setup Propagators 22 | otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) 23 | ``` 24 | 25 | ## The Demo 26 | 27 | The demo has the following call structure: 28 | 29 | `Outer -> Passthrough -> Inner` 30 | 31 | If all components had both an SDK and propagators registered, we would expect the trace to look like: 32 | 33 | ``` 34 | |-------outer---------| 35 | |-Passthrough recv-| 36 | |Passthrough send| 37 | |---inner---| 38 | ``` 39 | 40 | However, in this demo, only the outer and inner have TracerProvider backed by the SDK. All components have Propagators set. In this case, we expect to see: 41 | 42 | ``` 43 | |-------outer---------| 44 | |---inner---| 45 | ``` 46 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= 4 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 5 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 6 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 7 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 8 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 9 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 12 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 13 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 14 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 15 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 16 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 17 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 18 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 19 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 20 | -------------------------------------------------------------------------------- /metric/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= 4 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 5 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 6 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 7 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 8 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 9 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 12 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 13 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 14 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 15 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 16 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 17 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 18 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 19 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 20 | -------------------------------------------------------------------------------- /trace.go: -------------------------------------------------------------------------------- 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 otel // import "go.opentelemetry.io/otel" 16 | 17 | import ( 18 | "go.opentelemetry.io/otel/internal/global" 19 | "go.opentelemetry.io/otel/trace" 20 | ) 21 | 22 | // Tracer creates a named tracer that implements Tracer interface. 23 | // If the name is an empty string then provider uses default name. 24 | // 25 | // This is short for GetTracerProvider().Tracer(name, opts...) 26 | func Tracer(name string, opts ...trace.TracerOption) trace.Tracer { 27 | return GetTracerProvider().Tracer(name, opts...) 28 | } 29 | 30 | // GetTracerProvider returns the registered global trace provider. 31 | // If none is registered then an instance of NoopTracerProvider is returned. 32 | // 33 | // Use the trace provider to create a named tracer. E.g. 34 | // tracer := otel.GetTracerProvider().Tracer("example.com/foo") 35 | // or 36 | // tracer := otel.Tracer("example.com/foo") 37 | func GetTracerProvider() trace.TracerProvider { 38 | return global.TracerProvider() 39 | } 40 | 41 | // SetTracerProvider registers `tp` as the global trace provider. 42 | func SetTracerProvider(tp trace.TracerProvider) { 43 | global.SetTracerProvider(tp) 44 | } 45 | -------------------------------------------------------------------------------- /example/fib/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= 4 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 5 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 6 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 7 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 8 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 9 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 12 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 13 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 14 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 h1:iGu644GcxtEcrInvDsQRCwJjtCIOlT2V7IRt6ah2Whw= 15 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 16 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 17 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 18 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 19 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 20 | -------------------------------------------------------------------------------- /example/namedtracer/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= 4 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 5 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 6 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 7 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 8 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 9 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 12 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 13 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 14 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 h1:iGu644GcxtEcrInvDsQRCwJjtCIOlT2V7IRt6ah2Whw= 15 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 16 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 17 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 18 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 19 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 20 | -------------------------------------------------------------------------------- /example/passthrough/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= 4 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 5 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 6 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 7 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 8 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 9 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 12 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 13 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 14 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 h1:iGu644GcxtEcrInvDsQRCwJjtCIOlT2V7IRt6ah2Whw= 15 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 16 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 17 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 18 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 19 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 20 | -------------------------------------------------------------------------------- /exporters/jaeger/env.go: -------------------------------------------------------------------------------- 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 jaeger // import "go.opentelemetry.io/otel/exporters/jaeger" 16 | 17 | import ( 18 | "os" 19 | ) 20 | 21 | // Environment variable names 22 | const ( 23 | // Hostname for the Jaeger agent, part of address where exporter sends spans 24 | // i.e. "localhost" 25 | envAgentHost = "OTEL_EXPORTER_JAEGER_AGENT_HOST" 26 | // Port for the Jaeger agent, part of address where exporter sends spans 27 | // i.e. 6831 28 | envAgentPort = "OTEL_EXPORTER_JAEGER_AGENT_PORT" 29 | // The HTTP endpoint for sending spans directly to a collector, 30 | // i.e. http://jaeger-collector:14268/api/traces. 31 | envEndpoint = "OTEL_EXPORTER_JAEGER_ENDPOINT" 32 | // Username to send as part of "Basic" authentication to the collector endpoint. 33 | envUser = "OTEL_EXPORTER_JAEGER_USER" 34 | // Password to send as part of "Basic" authentication to the collector endpoint. 35 | envPassword = "OTEL_EXPORTER_JAEGER_PASSWORD" 36 | ) 37 | 38 | // envOr returns an env variable's value if it is exists or the default if not 39 | func envOr(key, defaultValue string) string { 40 | if v, ok := os.LookupEnv(key); ok && v != "" { 41 | return v 42 | } 43 | return defaultValue 44 | } 45 | -------------------------------------------------------------------------------- /exporters/prometheus/sanitize.go: -------------------------------------------------------------------------------- 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 prometheus // import "go.opentelemetry.io/otel/exporters/prometheus" 16 | 17 | import ( 18 | "strings" 19 | "unicode" 20 | ) 21 | 22 | // TODO(paivagustavo): we should provide a more uniform and controlled way of sanitizing. 23 | // Letting users define wether we should try or not to sanitize metric names. 24 | // This is a copy of sdk/internal/sanitize.go 25 | 26 | // sanitize returns a string that is truncated to 100 characters if it's too 27 | // long, and replaces non-alphanumeric characters to underscores. 28 | func sanitize(s string) string { 29 | if len(s) == 0 { 30 | return s 31 | } 32 | // TODO(paivagustavo): change this to use a bytes buffer to avoid a large number of string allocations. 33 | s = strings.Map(sanitizeRune, s) 34 | if unicode.IsDigit(rune(s[0])) { 35 | s = "key_" + s 36 | } 37 | if s[0] == '_' { 38 | s = "key" + s 39 | } 40 | return s 41 | } 42 | 43 | // converts anything that is not a letter or digit to an underscore 44 | func sanitizeRune(r rune) rune { 45 | if unicode.IsLetter(r) || unicode.IsDigit(r) { 46 | return r 47 | } 48 | // Everything else turns into an underscore 49 | return '_' 50 | } 51 | -------------------------------------------------------------------------------- /exporters/prometheus/sanitize_test.go: -------------------------------------------------------------------------------- 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 prometheus 16 | 17 | import ( 18 | "testing" 19 | ) 20 | 21 | func TestSanitize(t *testing.T) { 22 | tests := []struct { 23 | name string 24 | input string 25 | want string 26 | }{ 27 | { 28 | name: "replace character", 29 | input: "test/key-1", 30 | want: "test_key_1", 31 | }, 32 | { 33 | name: "add prefix if starting with digit", 34 | input: "0123456789", 35 | want: "key_0123456789", 36 | }, 37 | { 38 | name: "add prefix if starting with _", 39 | input: "_0123456789", 40 | want: "key_0123456789", 41 | }, 42 | { 43 | name: "starts with _ after sanitization", 44 | input: "/0123456789", 45 | want: "key_0123456789", 46 | }, 47 | { 48 | name: "valid input", 49 | input: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789", 50 | want: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789", 51 | }, 52 | } 53 | 54 | for _, tt := range tests { 55 | t.Run(tt.name, func(t *testing.T) { 56 | if got, want := sanitize(tt.input), tt.want; got != want { 57 | t.Errorf("sanitize() = %q; want %q", got, want) 58 | } 59 | }) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /bridge/opencensus/internal/oc2otel/attributes_test.go: -------------------------------------------------------------------------------- 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 oc2otel 16 | 17 | import ( 18 | "testing" 19 | 20 | octrace "go.opencensus.io/trace" 21 | 22 | "go.opentelemetry.io/otel/attribute" 23 | ) 24 | 25 | func TestAttributes(t *testing.T) { 26 | in := []octrace.Attribute{ 27 | octrace.BoolAttribute("bool", true), 28 | octrace.Int64Attribute("int64", 49), 29 | octrace.Float64Attribute("float64", 1.618), 30 | octrace.StringAttribute("key", "val"), 31 | } 32 | 33 | want := []attribute.KeyValue{ 34 | attribute.Bool("bool", true), 35 | attribute.Int64("int64", 49), 36 | attribute.Float64("float64", 1.618), 37 | attribute.String("key", "val"), 38 | } 39 | got := Attributes(in) 40 | 41 | if len(got) != len(want) { 42 | t.Errorf("Attributes conversion failed: want %#v, got %#v", want, got) 43 | } 44 | for i := range got { 45 | if g, w := got[i], want[i]; g != w { 46 | t.Errorf("Attributes conversion: want %#v, got %#v", w, g) 47 | } 48 | } 49 | } 50 | 51 | func TestAttributeValueUnknown(t *testing.T) { 52 | got := AttributeValue([]byte{}) 53 | if got != attribute.StringValue("unknown") { 54 | t.Errorf("AttributeValue of unknown wrong: %#v", got) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /bridge/opencensus/internal/oc2otel/tracer_start_options_test.go: -------------------------------------------------------------------------------- 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 oc2otel 16 | 17 | import ( 18 | "testing" 19 | 20 | octrace "go.opencensus.io/trace" 21 | 22 | "go.opentelemetry.io/otel/trace" 23 | ) 24 | 25 | func TestStartOptionsSpanKind(t *testing.T) { 26 | conv := map[int]trace.SpanKind{ 27 | octrace.SpanKindClient: trace.SpanKindClient, 28 | octrace.SpanKindServer: trace.SpanKindServer, 29 | octrace.SpanKindUnspecified: trace.SpanKindUnspecified, 30 | } 31 | 32 | for oc, otel := range conv { 33 | ocOpts := []octrace.StartOption{octrace.WithSpanKind(oc)} 34 | otelOpts, err := StartOptions(ocOpts) 35 | if err != nil { 36 | t.Errorf("StartOptions errored: %v", err) 37 | continue 38 | } 39 | c := trace.NewSpanStartConfig(otelOpts...) 40 | if c.SpanKind() != otel { 41 | t.Errorf("conversion of SpanKind start option: got %v, want %v", c.SpanKind(), otel) 42 | } 43 | } 44 | } 45 | 46 | func TestStartOptionsSamplerErrors(t *testing.T) { 47 | ocOpts := []octrace.StartOption{octrace.WithSampler(octrace.AlwaysSample())} 48 | _, err := StartOptions(ocOpts) 49 | if err == nil { 50 | t.Error("StartOptions should error Sampler option") 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /internal/baggage/baggage.go: -------------------------------------------------------------------------------- 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 | /* 16 | Package baggage provides base types and functionality to store and retrieve 17 | baggage in Go context. This package exists because the OpenTracing bridge to 18 | OpenTelemetry needs to synchronize state whenever baggage for a context is 19 | modified and that context contains an OpenTracing span. If it were not for 20 | this need this package would not need to exist and the 21 | `go.opentelemetry.io/otel/baggage` package would be the singular place where 22 | W3C baggage is handled. 23 | */ 24 | package baggage // import "go.opentelemetry.io/otel/internal/baggage" 25 | 26 | // List is the collection of baggage members. The W3C allows for duplicates, 27 | // but OpenTelemetry does not, therefore, this is represented as a map. 28 | type List map[string]Item 29 | 30 | // Item is the value and metadata properties part of a list-member. 31 | type Item struct { 32 | Value string 33 | Properties []Property 34 | } 35 | 36 | // Property is a metadata entry for a list-member. 37 | type Property struct { 38 | Key, Value string 39 | 40 | // HasValue indicates if a zero-value value means the property does not 41 | // have a value or if it was the zero-value. 42 | HasValue bool 43 | } 44 | -------------------------------------------------------------------------------- /bridge/opentracing/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= 4 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 5 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 6 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 7 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 8 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 9 | github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= 10 | github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= 11 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 12 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 13 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 14 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 15 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 16 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 17 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 18 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 19 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 20 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 21 | -------------------------------------------------------------------------------- /example/jaeger/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= 4 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 5 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 6 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 7 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 8 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 9 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 10 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 11 | github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= 12 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 13 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 14 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 15 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 h1:iGu644GcxtEcrInvDsQRCwJjtCIOlT2V7IRt6ah2Whw= 16 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 17 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 18 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 19 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 20 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 21 | -------------------------------------------------------------------------------- /exporters/otlp/otlptrace/internal/otlpconfig/optiontypes.go: -------------------------------------------------------------------------------- 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 otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/otlpconfig" 16 | 17 | const ( 18 | // DefaultCollectorPort is the port the Exporter will attempt connect to 19 | // if no collector port is provided. 20 | DefaultCollectorPort uint16 = 4317 21 | // DefaultCollectorHost is the host address the Exporter will attempt 22 | // connect to if no collector address is provided. 23 | DefaultCollectorHost string = "localhost" 24 | ) 25 | 26 | // Compression describes the compression used for payloads sent to the 27 | // collector. 28 | type Compression int 29 | 30 | const ( 31 | // NoCompression tells the driver to send payloads without 32 | // compression. 33 | NoCompression Compression = iota 34 | // GzipCompression tells the driver to send payloads after 35 | // compressing them with gzip. 36 | GzipCompression 37 | ) 38 | 39 | // Marshaler describes the kind of message format sent to the collector 40 | type Marshaler int 41 | 42 | const ( 43 | // MarshalProto tells the driver to send using the protobuf binary format. 44 | MarshalProto Marshaler = iota 45 | // MarshalJSON tells the driver to send using json format. 46 | MarshalJSON 47 | ) 48 | -------------------------------------------------------------------------------- /exporters/jaeger/internal/third_party/thrift/lib/go/thrift/type.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package thrift 21 | 22 | // Type constants in the Thrift protocol 23 | type TType byte 24 | 25 | const ( 26 | STOP = 0 27 | VOID = 1 28 | BOOL = 2 29 | BYTE = 3 30 | I08 = 3 31 | DOUBLE = 4 32 | I16 = 6 33 | I32 = 8 34 | I64 = 10 35 | STRING = 11 36 | UTF7 = 11 37 | STRUCT = 12 38 | MAP = 13 39 | SET = 14 40 | LIST = 15 41 | UTF8 = 16 42 | UTF16 = 17 43 | //BINARY = 18 wrong and unusued 44 | ) 45 | 46 | var typeNames = map[int]string{ 47 | STOP: "STOP", 48 | VOID: "VOID", 49 | BOOL: "BOOL", 50 | BYTE: "BYTE", 51 | DOUBLE: "DOUBLE", 52 | I16: "I16", 53 | I32: "I32", 54 | I64: "I64", 55 | STRING: "STRING", 56 | STRUCT: "STRUCT", 57 | MAP: "MAP", 58 | SET: "SET", 59 | LIST: "LIST", 60 | UTF8: "UTF8", 61 | UTF16: "UTF16", 62 | } 63 | 64 | func (p TType) String() string { 65 | if s, ok := typeNames[int(p)]; ok { 66 | return s 67 | } 68 | return "Unknown" 69 | } 70 | -------------------------------------------------------------------------------- /sdk/export/metric/go.sum: -------------------------------------------------------------------------------- 1 | github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= 2 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 3 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= 5 | github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 6 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 7 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 8 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 9 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 10 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 11 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 12 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 13 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 14 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 15 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7 h1:iGu644GcxtEcrInvDsQRCwJjtCIOlT2V7IRt6ah2Whw= 16 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 17 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 18 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 19 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 20 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 21 | -------------------------------------------------------------------------------- /bridge/opencensus/doc.go: -------------------------------------------------------------------------------- 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 opencensus provides a migration bridge from OpenCensus to 16 | // OpenTelemetry. The NewTracer function should be used to create an 17 | // OpenCensus Tracer from an OpenTelemetry Tracer. This Tracer can be use in 18 | // place of any existing OpenCensus Tracer and will generate OpenTelemetry 19 | // spans for traces. These spans will be exported by the OpenTelemetry 20 | // TracerProvider the original OpenTelemetry Tracer came from. 21 | // 22 | // There are known limitations to this bridge: 23 | // 24 | // - The AddLink method for OpenCensus Spans is not compatible with the 25 | // OpenTelemetry Span. No link can be added to an OpenTelemetry Span once it 26 | // is started. Any calls to this method for the OpenCensus Span will result 27 | // in an error being sent to the OpenTelemetry default ErrorHandler. 28 | // 29 | // - The NewContext method of the OpenCensus Tracer cannot embed an OpenCensus 30 | // Span in a context unless that Span was created by that Tracer. 31 | // 32 | // - Conversion of custom OpenCensus Samplers to OpenTelemetry is not 33 | // implemented. An error will be sent to the OpenTelemetry default 34 | // ErrorHandler if this is attempted. 35 | package opencensus // import "go.opentelemetry.io/otel/bridge/opencensus" 36 | -------------------------------------------------------------------------------- /bridge/opentracing/util.go: -------------------------------------------------------------------------------- 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 opentracing // import "go.opentelemetry.io/otel/bridge/opentracing" 16 | 17 | import ( 18 | "context" 19 | 20 | "go.opentelemetry.io/otel/trace" 21 | ) 22 | 23 | // NewTracerPair is a utility function that creates a BridgeTracer and a 24 | // WrapperTracerProvider. WrapperTracerProvider creates a single instance of 25 | // WrapperTracer. The BridgeTracer forwards the calls to the WrapperTracer 26 | // that wraps the passed tracer. BridgeTracer and WrapperTracerProvider are 27 | // returned to the caller and the caller is expected to register BridgeTracer 28 | // with opentracing and WrapperTracerProvider with opentelemetry. 29 | func NewTracerPair(tracer trace.Tracer) (*BridgeTracer, *WrapperTracerProvider) { 30 | bridgeTracer := NewBridgeTracer() 31 | wrapperProvider := NewWrappedTracerProvider(bridgeTracer, tracer) 32 | bridgeTracer.SetOpenTelemetryTracer(wrapperProvider.Tracer("")) 33 | return bridgeTracer, wrapperProvider 34 | } 35 | 36 | func NewTracerPairWithContext(ctx context.Context, tracer trace.Tracer) (context.Context, *BridgeTracer, *WrapperTracerProvider) { 37 | bridgeTracer, wrapperProvider := NewTracerPair(tracer) 38 | ctx = bridgeTracer.NewHookedContext(ctx) 39 | return ctx, bridgeTracer, wrapperProvider 40 | } 41 | --------------------------------------------------------------------------------