mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: update kubernetes and libraries to v1.22.0 version
Kubernetes v1.22 version has been released and this update ceph csi dependencies to use the same version. Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
committed by
mergify[bot]
parent
e077c1fdf5
commit
aa698bc3e1
13
vendor/go.opentelemetry.io/contrib/.gitignore
generated
vendored
Normal file
13
vendor/go.opentelemetry.io/contrib/.gitignore
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
.tools/
|
||||
.idea/
|
||||
.vscode/
|
||||
*.iml
|
||||
*.so
|
||||
coverage.*
|
||||
example
|
||||
|
||||
instrumentation/google.golang.org/grpc/otelgrpc/example/server/server
|
||||
instrumentation/google.golang.org/grpc/otelgrpc/example/client/client
|
32
vendor/go.opentelemetry.io/contrib/.golangci.yml
generated
vendored
Normal file
32
vendor/go.opentelemetry.io/contrib/.golangci.yml
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
# See https://github.com/golangci/golangci-lint#config-file
|
||||
run:
|
||||
issues-exit-code: 1 #Default
|
||||
tests: true #Default
|
||||
|
||||
linters:
|
||||
enable:
|
||||
- misspell
|
||||
- goimports
|
||||
- golint
|
||||
- gofmt
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
# helpers in tests often (rightfully) pass a *testing.T as their first argument
|
||||
- path: _test\.go
|
||||
text: "context.Context should be the first parameter of a function"
|
||||
linters:
|
||||
- golint
|
||||
# Yes, they are, but it's okay in a test
|
||||
- path: _test\.go
|
||||
text: "exported func.*returns unexported type.*which can be annoying to use"
|
||||
linters:
|
||||
- golint
|
||||
|
||||
linters-settings:
|
||||
misspell:
|
||||
locale: US
|
||||
#ignore-words:
|
||||
# - someword
|
||||
goimports:
|
||||
local-prefixes: go.opentelemetry.io
|
319
vendor/go.opentelemetry.io/contrib/CHANGELOG.md
generated
vendored
Normal file
319
vendor/go.opentelemetry.io/contrib/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,319 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.20.0] - 2021-04-23
|
||||
|
||||
### Changed
|
||||
|
||||
- The `go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo` instrumentation now accepts a `WithCommandAttributeDisabled`,
|
||||
so the caller can specify whether to opt-out of tracing the mongo command. (#712)
|
||||
- Upgrade to v0.20.0 of `go.opentelemetry.io/otel`. (#758)
|
||||
- The B3 and Jaeger propagators now store their debug or deferred state in the context.Context instead of the SpanContext. (#758)
|
||||
|
||||
## [0.19.0] - 2021-03-19
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgrade to v0.19.0 of `go.opentelemetry.io/otel`.
|
||||
|
||||
## [0.18.0] - 2021-03-04
|
||||
|
||||
### Fixed
|
||||
|
||||
- `otelmemcache` no longer sets span status to OK instead of leaving it unset. (#477)
|
||||
- Fix goroutine leak in gRPC `StreamClientInterceptor`. (#581)
|
||||
|
||||
### Removed
|
||||
|
||||
- Remove service name from `otelmemcache` configuration and span attributes. (#477)
|
||||
|
||||
## [0.17.0] - 2021-02-15
|
||||
|
||||
### Added
|
||||
|
||||
- Add `ot-tracer` propagator (#562)
|
||||
|
||||
### Changed
|
||||
|
||||
- Rename project default branch from `master` to `main`.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Added failure message for AWS ECS resource detector for better debugging (#568)
|
||||
- Goroutine leak in gRPC StreamClientInterceptor while streamer returns an error. (#581)
|
||||
|
||||
## [0.16.0] - 2021-01-13
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix module path for AWS ECS resource detector (#517)
|
||||
|
||||
## [0.15.1] - 2020-12-14
|
||||
|
||||
### Added
|
||||
|
||||
- Add registry link check to `Makefile` and pre-release script. (#446)
|
||||
- A new AWS X-Ray ID Generator (#459)
|
||||
- Migrate CircleCI jobs to GitHub Actions (#476)
|
||||
- Add CodeQL GitHub Action (#506)
|
||||
- Add gosec workflow to GitHub Actions (#507)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixes the body replacement in otelhttp to not to mutate a nil body. (#484)
|
||||
|
||||
## [0.15.0] - 2020-12-11
|
||||
|
||||
### Added
|
||||
|
||||
- A new Amazon EKS resource detector. (#465)
|
||||
- A new `gcp.CloudRun` detector for detecting resource from a Cloud Run instance. (#455)
|
||||
|
||||
## [0.14.0] - 2020-11-20
|
||||
|
||||
### Added
|
||||
|
||||
- `otelhttp.{Get,Head,Post,PostForm}` convenience wrappers for their `http` counterparts. (#390)
|
||||
- The AWS detector now adds the cloud zone, host image ID, host type, and host name to the returned `Resource`. (#410)
|
||||
- Add Amazon ECS Resource Detector for AWS X-Ray. (#466)
|
||||
- Add propagator for AWS X-Ray (#462)
|
||||
|
||||
### Changed
|
||||
|
||||
- Add semantic version to `Tracer` / `Meter` created by instrumentation packages `otelsaram`, `otelrestful`, `otelmongo`, `otelhttp` and `otelhttptrace`. (#412)
|
||||
- Update instrumentation guidelines about tracer / meter semantic version. (#412)
|
||||
- Replace internal tracer and meter helpers by helpers from `go.opentelemetry.io/otel`. (#414)
|
||||
- gRPC instrumentation sets span attribute `rpc.grpc.status_code`. (#453)
|
||||
|
||||
## Fixed
|
||||
|
||||
- `/detectors/aws` no longer fails if instance metadata is not available (e.g. not running in AWS) (#401)
|
||||
- The AWS detector now returns a partial resource and an appropriate error if it encounters an error part way through determining a `Resource` identity. (#410)
|
||||
- The `host` instrumentation unit test has been updated to not depend on the system it runs on. (#426)
|
||||
|
||||
## [0.13.0] - 2020-10-09
|
||||
|
||||
## Added
|
||||
|
||||
- A Jaeger propagator. (#375)
|
||||
|
||||
## Changed
|
||||
|
||||
- The `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` package instrumentation no longer accepts a `Tracer` as an argument to the interceptor function.
|
||||
Instead, a new `WithTracerProvider` option is added to configure the `TracerProvider` used when creating the `Tracer` for the instrumentation. (#373)
|
||||
- The `go.opentelemetry.io/contrib/instrumentation/gopkg.in/macaron.v1/otelmacaron` instrumentation now accepts a `TracerProvider` rather than a `Tracer`. (#374)
|
||||
- Remove `go.opentelemetry.io/otel/sdk` dependency from instrumentation. (#381)
|
||||
- Use `httpsnoop` in `go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux` to ensure `http.ResponseWriter` additional interfaces are preserved. (#388)
|
||||
|
||||
### Fixed
|
||||
|
||||
- The `go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho.Middleware` no longer sends duplicate errors to the global `ErrorHandler`. (#377, #364)
|
||||
- The import comment in `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` is now correctly quoted. (#379)
|
||||
- The B3 propagator sets the sample bitmask when the sampling decision is `debug`. (#369)
|
||||
|
||||
## [0.12.0] - 2020-09-25
|
||||
|
||||
### Changed
|
||||
|
||||
- Replace `WithTracer` with `WithTracerProvider` in the `go.opentelemetry.io/contrib/instrumentation/gopkg.in/macaron.v1/otelmacaron` instrumentation. (#374)
|
||||
|
||||
### Added
|
||||
|
||||
- Benchmark tests for the gRPC instrumentation. (#296)
|
||||
- Integration testing for the gRPC instrumentation. (#297)
|
||||
- Allow custom labels to be added to net/http metrics. (#306)
|
||||
- Added B3 propagator, moving it out of open.telemetry.io/otel repo. (#344)
|
||||
|
||||
### Changed
|
||||
|
||||
- Unify instrumentation about provider options for `go.mongodb.org/mongo-driver`, `gin-gonic/gin`, `gorilla/mux`,
|
||||
`labstack/echo`, `emicklei/go-restful`, `bradfitz/gomemcache`, `Shopify/sarama`, `net/http` and `beego`. (#303)
|
||||
- Update instrumentation guidelines about uniform provider options. Also, update style guide. (#303)
|
||||
- Make config struct of instrumentation unexported. (#303)
|
||||
- Instrumentations have been updated to adhere to the [configuration style guide's](https://github.com/open-telemetry/opentelemetry-go/blob/master/CONTRIBUTING.md#config)
|
||||
updated recommendation to use `newConfig()` instead of `configure()`. (#336)
|
||||
- A new instrumentation naming scheme is implemented to avoid package name conflicts for instrumented packages while still remaining discoverable. (#359)
|
||||
- `google.golang.org/grpc` -> `google.golang.org/grpc/otelgrpc`
|
||||
- `go.mongodb.org/mongo-driver` -> `go.mongodb.org/mongo-driver/mongo/otelmongo`
|
||||
- `net/http` -> `net/http/otelhttp`
|
||||
- `net/http/httptrace` -> `net/http/httptrace/otelhttptrace`
|
||||
- `github.com/labstack/echo` -> `github.com/labstack/echo/otelecho`
|
||||
- `github.com/bradfitz/gomemcache` -> `github.com/bradfitz/gomemcache/memcache/otelmemcache`
|
||||
- `github.com/gin-gonic/gin` -> `github.com/gin-gonic/gin/otelgin`
|
||||
- `github.com/gocql/gocql` -> `github.com/gocql/gocql/otelgocql`
|
||||
- `github.com/emicklei/go-restful` -> `github.com/emicklei/go-restful/otelrestful`
|
||||
- `github.com/Shopify/sarama` -> `github.com/Shopify/sarama/otelsarama`
|
||||
- `github.com/gorilla/mux` -> `github.com/gorilla/mux/otelmux`
|
||||
- `github.com/astaxie/beego` -> `github.com/astaxie/beego/otelbeego`
|
||||
- `gopkg.in/macaron.v1` -> `gopkg.in/macaron.v1/otelmacaron`
|
||||
- Rename `OTelBeegoHandler` to `Handler` in the `go.opentelemetry.io/contrib/instrumentation/github.com/astaxie/beego/otelbeego` package. (#359)
|
||||
|
||||
## [0.11.0] - 2020-08-25
|
||||
|
||||
### Added
|
||||
|
||||
- Top-level `Version()` and `SemVersion()` functions defining the current version of the contrib package. (#225)
|
||||
- Instrumentation for the `github.com/astaxie/beego` package. (#200)
|
||||
- Instrumentation for the `github.com/bradfitz/gomemcache` package. (#204)
|
||||
- Host metrics instrumentation. (#231)
|
||||
- Cortex histogram and distribution support. (#237)
|
||||
- Cortex example project. (#238)
|
||||
- Cortex HTTP authentication. (#246)
|
||||
|
||||
### Changed
|
||||
|
||||
- Remove service name as a parameter of Sarama instrumentation. (#221)
|
||||
- Replace `WithTracer` with `WithTracerProvider` in Sarama instrumentation. (#221)
|
||||
- Switch to use common top-level module `SemVersion()` when creating versioned tracer in `bradfitz/gomemcache`. (#226)
|
||||
- Use `IntegrationShouldRun` in `gomemcache_test`. (#254)
|
||||
- Use Go 1.15 for CI builds. (#236)
|
||||
- Improved configuration for `runtime` instrumentation. (#224)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Update dependabot configuration to include newly added `bradfitz/gomemcache` package. (#226)
|
||||
- Correct `runtime` instrumentation name. (#241)
|
||||
|
||||
## [0.10.1] - 2020-08-13
|
||||
|
||||
### Added
|
||||
|
||||
- The `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc` module has been added to replace the instrumentation that had previoiusly existed in the `go.opentelemetry.io/otel/instrumentation/grpctrace` package. (#189)
|
||||
- Instrumentation for the stdlib `net/http` and `net/http/httptrace` packages. (#190)
|
||||
- Initial Cortex exporter. (#202, #205, #210, #211, #215)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Bump google.golang.org/grpc from 1.30.0 to 1.31.0. (#166)
|
||||
- Bump go.mongodb.org/mongo-driver from 1.3.5 to 1.4.0 in /instrumentation/go.mongodb.org/mongo-driver. (#170)
|
||||
- Bump google.golang.org/grpc in /instrumentation/github.com/gin-gonic/gin. (#173)
|
||||
- Bump google.golang.org/grpc in /instrumentation/github.com/labstack/echo. (#176)
|
||||
- Bump google.golang.org/grpc from 1.30.0 to 1.31.0 in /instrumentation/github.com/Shopify/sarama. (#179)
|
||||
- Bump cloud.google.com/go from 0.61.0 to 0.63.0 in /detectors/gcp. (#181, #199)
|
||||
- Bump github.com/aws/aws-sdk-go from 1.33.15 to 1.34.1 in /detectors/aws. (#184, #192, #193, #198, #201, #203)
|
||||
- Bump github.com/golangci/golangci-lint from 1.29.0 to 1.30.0 in /tools. (#186)
|
||||
- Setup CI to run tests that require external resources (Cassandra and MongoDB). (#191)
|
||||
- Bump github.com/Shopify/sarama from 1.26.4 to 1.27.0 in /instrumentation/github.com/Shopify/sarama. (#206)
|
||||
|
||||
## [0.10.0] - 2020-07-31
|
||||
|
||||
This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.10.0) dependency to v0.10.0 and includes new instrumentation for popular Kafka and Cassandra clients.
|
||||
|
||||
### Added
|
||||
|
||||
- A detector that generate resources from GCE instance. (#132)
|
||||
- A detector that generate resources from AWS instances. (#139)
|
||||
- Instrumentation for the Kafka client github.com/Shopify/sarama. (#134, #153)
|
||||
- Links and status message for mock span in the internal testing library. (#134)
|
||||
- Instrumentation for the Cassandra client github.com/gocql/gocql. (#137)
|
||||
- A detector that generate resources from GKE clusters. (#154)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Bump github.com/aws/aws-sdk-go from 1.33.8 to 1.33.15 in /detectors/aws. (#155, #157, #159, #162)
|
||||
- Bump github.com/golangci/golangci-lint from 1.28.3 to 1.29.0 in /tools. (#146)
|
||||
|
||||
## [0.9.0] - 2020-07-20
|
||||
|
||||
This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.9.0) dependency to v0.9.0.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Bump github.com/emicklei/go-restful/v3 from 3.0.0 to 3.2.0 in /instrumentation/github.com/emicklei/go-restful. (#133)
|
||||
- Update dependabot configuration to correctly check all included packages. (#131)
|
||||
- Update `RELEASING.md` with correct `tag.sh` command. (#130)
|
||||
|
||||
## [0.8.0] - 2020-07-10
|
||||
|
||||
This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.8.0) dependency to v0.8.0, includes minor fixes, and new instrumentation.
|
||||
|
||||
### Added
|
||||
|
||||
- Create this `CHANGELOG.md`. (#114)
|
||||
- Add `emicklei/go-restful/v3` trace instrumentation. (#115)
|
||||
|
||||
### Changed
|
||||
|
||||
- Update `CONTRIBUTING.md` to ask for updates to `CHANGELOG.md` with each pull request. (#114)
|
||||
- Move all `github.com` package instrumentation under a `github.com` directory. (#118)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Update README to include information about external instrumentation.
|
||||
To start, this includes native instrumentation found in the `go-redis/redis` package. (#117)
|
||||
- Bump github.com/golangci/golangci-lint from 1.27.0 to 1.28.2 in /tools. (#122, #123, #125)
|
||||
- Bump go.mongodb.org/mongo-driver from 1.3.4 to 1.3.5 in /instrumentation/go.mongodb.org/mongo-driver. (#124)
|
||||
|
||||
## [0.7.0] - 2020-06-29
|
||||
|
||||
This release upgrades its [go.opentelemetry.io/otel](https://github.com/open-telemetry/opentelemetry-go/releases/tag/v0.7.0) dependency to v0.7.0.
|
||||
|
||||
### Added
|
||||
|
||||
- Create `RELEASING.md` instructions. (#101)
|
||||
- Apply transitive dependabot go.mod updates as part of a new automatic Github workflow. (#94)
|
||||
- New dependabot integration to automate package upgrades. (#61)
|
||||
- Add automatic tag generation script for release. (#60)
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgrade Datadog metrics exporter to include Resource tags. (#46)
|
||||
- Added output validation to Datadog example. (#96)
|
||||
- Move Macaron package to match layout guidelines. (#92)
|
||||
- Update top-level README and instrumentation README. (#92)
|
||||
- Bump google.golang.org/grpc from 1.29.1 to 1.30.0. (#99)
|
||||
- Bump github.com/golangci/golangci-lint from 1.21.0 to 1.27.0 in /tools. (#77)
|
||||
- Bump go.mongodb.org/mongo-driver from 1.3.2 to 1.3.4 in /instrumentation/go.mongodb.org/mongo-driver. (#76)
|
||||
- Bump github.com/stretchr/testify from 1.5.1 to 1.6.1. (#74)
|
||||
- Bump gopkg.in/macaron.v1 from 1.3.5 to 1.3.9 in /instrumentation/macaron. (#68)
|
||||
- Bump github.com/gin-gonic/gin from 1.6.2 to 1.6.3 in /instrumentation/gin-gonic/gin. (#73)
|
||||
- Bump github.com/DataDog/datadog-go from 3.5.0+incompatible to 3.7.2+incompatible in /exporters/metric/datadog. (#78)
|
||||
- Replaced `internal/trace/http.go` helpers with `api/standard` helpers from otel-go repo. (#112)
|
||||
|
||||
## [0.6.1] - 2020-06-08
|
||||
|
||||
First official tagged release of `contrib` repository.
|
||||
|
||||
### Added
|
||||
|
||||
- `labstack/echo` trace instrumentation (#42)
|
||||
- `mongodb` trace instrumentation (#26)
|
||||
- Go Runtime metrics (#9)
|
||||
- `gorilla/mux` trace instrumentation (#19)
|
||||
- `gin-gonic` trace instrumentation (#15)
|
||||
- `macaron` trace instrumentation (#20)
|
||||
- `dogstatsd` metrics exporter (#10)
|
||||
- `datadog` metrics exporter (#22)
|
||||
- Tags to all modules in repository
|
||||
- Repository folder structure and automated build (#3)
|
||||
|
||||
### Changes
|
||||
|
||||
- Prefix support for dogstatsd (#34)
|
||||
- Update Go Runtime package to use batch observer (#44)
|
||||
|
||||
[Unreleased]: https://github.com/open-telemetry/opentelemetry-go-contrib/compare/v0.20.0...HEAD
|
||||
[0.20.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.20.0
|
||||
[0.19.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.19.0
|
||||
[0.18.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.18.0
|
||||
[0.17.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.17.0
|
||||
[0.16.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.16.0
|
||||
[0.15.1]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.15.1
|
||||
[0.15.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.15.0
|
||||
[0.14.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.14.0
|
||||
[0.13.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.13.0
|
||||
[0.12.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.12.0
|
||||
[0.11.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.11.0
|
||||
[0.10.1]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.10.1
|
||||
[0.10.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.10.0
|
||||
[0.9.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.9.0
|
||||
[0.8.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.8.0
|
||||
[0.7.0]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.7.0
|
||||
[0.6.1]: https://github.com/open-telemetry/opentelemetry-go-contrib/releases/tag/v0.6.1
|
17
vendor/go.opentelemetry.io/contrib/CODEOWNERS
generated
vendored
Normal file
17
vendor/go.opentelemetry.io/contrib/CODEOWNERS
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
#####################################################
|
||||
#
|
||||
# List of approvers for this repository
|
||||
#
|
||||
#####################################################
|
||||
#
|
||||
# Learn about membership in OpenTelemetry community:
|
||||
# https://github.com/open-telemetry/community/blob/main/community-membership.md
|
||||
#
|
||||
#
|
||||
# Learn about CODEOWNERS file format:
|
||||
# https://help.github.com/en/articles/about-code-owners
|
||||
#
|
||||
|
||||
* @jmacd @MrAlias @Aneurysm9 @evantorrie @XSAM @dashpole @paivagustavo
|
||||
|
||||
CODEOWNERS @MrAlias @Aneurysm9
|
135
vendor/go.opentelemetry.io/contrib/CONTRIBUTING.md
generated
vendored
Normal file
135
vendor/go.opentelemetry.io/contrib/CONTRIBUTING.md
generated
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
# Contributing to opentelemetry-go-contrib
|
||||
|
||||
The Go special interest group (SIG) meets regularly. See the
|
||||
OpenTelemetry
|
||||
[community](https://github.com/open-telemetry/community#golang-sdk)
|
||||
repo for information on this and other language SIGs.
|
||||
|
||||
See the [public meeting
|
||||
notes](https://docs.google.com/document/d/1A63zSWX0x2CyCK_LoNhmQC4rqhLpYXJzXbEPDUQ2n6w/edit#heading=h.9tngw7jdwd6b)
|
||||
for a summary description of past meetings. To request edit access,
|
||||
join the meeting or get in touch on
|
||||
[Slack](https://cloud-native.slack.com/archives/C01NPAXACKT).
|
||||
|
||||
## Development
|
||||
|
||||
There are some generated files checked into the repo. To make sure
|
||||
that the generated files are up-to-date, run `make` (or `make
|
||||
precommit` - the `precommit` target is the default).
|
||||
|
||||
The `precommit` target also fixes the formatting of the code and
|
||||
checks the status of the go module files.
|
||||
|
||||
If after running `make precommit` the output of `git status` contains
|
||||
`nothing to commit, working tree clean` then it means that everything
|
||||
is up-to-date and properly formatted.
|
||||
|
||||
## Pull Requests
|
||||
|
||||
### How to Send Pull Requests
|
||||
|
||||
Everyone is welcome to contribute code to `opentelemetry-go-contrib` via
|
||||
GitHub pull requests (PRs).
|
||||
|
||||
To create a new PR, fork the project in GitHub and clone the upstream
|
||||
repo:
|
||||
|
||||
```sh
|
||||
$ git clone https://github.com/open-telemetry/opentelemetry-go-contrib
|
||||
```
|
||||
This would put the project in the `opentelemetry-go-contrib` directory in
|
||||
current working directory.
|
||||
|
||||
Enter the newly created directory and add your fork as a new remote:
|
||||
|
||||
```sh
|
||||
$ git remote add <YOUR_FORK> git@github.com:<YOUR_GITHUB_USERNAME>/opentelemetry-go
|
||||
```
|
||||
|
||||
Check out a new branch, make modifications, run linters and tests, update
|
||||
`CHANGELOG.md` and push the branch to your fork:
|
||||
|
||||
```sh
|
||||
$ git checkout -b <YOUR_BRANCH_NAME>
|
||||
# edit files
|
||||
# update changelog
|
||||
$ make precommit
|
||||
$ git add -p
|
||||
$ git commit
|
||||
$ git push <YOUR_FORK> <YOUR_BRANCH_NAME>
|
||||
```
|
||||
|
||||
Open a pull request against the main `opentelemetry-go-contrib` repo. Be sure to add the pull
|
||||
request ID to the entry you added to `CHANGELOG.md`.
|
||||
|
||||
### How to Receive Comments
|
||||
|
||||
* If the PR is not ready for review, please put `[WIP]` in the title,
|
||||
tag it as `work-in-progress`, or mark it as
|
||||
[`draft`](https://github.blog/2019-02-14-introducing-draft-pull-requests/).
|
||||
* Make sure CLA is signed and CI is clear.
|
||||
|
||||
### How to Get PRs Merged
|
||||
|
||||
A PR is considered to be **ready to merge** when:
|
||||
|
||||
* It has received two approvals from Approvers/Maintainers (at
|
||||
different companies).
|
||||
* Feedback has been addressed.
|
||||
* Any substantive changes to your PR will require that you clear any prior
|
||||
Approval reviews, this includes changes resulting from other feedback. Unless
|
||||
the approver explicitly stated that their approval will persist across
|
||||
changes it should be assumed that the PR needs their review again. Other
|
||||
project members (e.g. approvers, maintainers) can help with this if there are
|
||||
any questions or if you forget to clear reviews.
|
||||
* It has been open for review for at least one working day. This gives
|
||||
people reasonable time to review.
|
||||
* Trivial change (typo, cosmetic, doc, etc.) doesn't have to wait for
|
||||
one day.
|
||||
* `CHANGELOG.md` has been updated to reflect what has been
|
||||
added, changed, removed, or fixed.
|
||||
* Urgent fix can take exception as long as it has been actively
|
||||
communicated.
|
||||
|
||||
Any Maintainer can merge the PR once it is **ready to merge**.
|
||||
|
||||
## Style Guide
|
||||
|
||||
* Make sure to run `make precommit` - this will find and fix the code
|
||||
formatting.
|
||||
* Check [opentelemetry-go Style Guide](https://github.com/open-telemetry/opentelemetry-go/blob/main/CONTRIBUTING.md#style-guide)
|
||||
|
||||
## Adding a new Contrib package
|
||||
|
||||
To add a new contrib package follow an existing one. An empty Sample instrumentation
|
||||
provides base structure with an example and a test. Each contrib package
|
||||
should be its own module. A contrib package may contain more than one go package.
|
||||
|
||||
### Folder Structure
|
||||
- instrumentation/\<instrumentation-package> (**Common**)
|
||||
- instrumentation/\<instrumentation-package>/trace (**specific to trace**)
|
||||
- instrumentation/\<instrumentation-package>/metrics (**specific to metrics**)
|
||||
|
||||
#### Example
|
||||
- instrumentation/gorm/trace
|
||||
- instrumentation/kafka/metrics
|
||||
|
||||
## Approvers and Maintainers
|
||||
|
||||
Approvers:
|
||||
|
||||
- [Evan Torrie](https://github.com/evantorrie), Verizon Media
|
||||
- [Josh MacDonald](https://github.com/jmacd), LightStep
|
||||
- [Sam Xie](https://github.com/XSAM)
|
||||
- [David Ashpole](https://github.com/dashpole), Google
|
||||
- [Gustavo Silva Paiva](https://github.com/paivagustavo), LightStep
|
||||
|
||||
Maintainers:
|
||||
|
||||
- [Anthony Mirabella](https://github.com/Aneurysm9), Centene
|
||||
- [Tyler Yahn](https://github.com/MrAlias), New Relic
|
||||
|
||||
### Become an Approver or a Maintainer
|
||||
|
||||
See the [community membership document in OpenTelemetry community
|
||||
repo](https://github.com/open-telemetry/community/blob/main/community-membership.md).
|
201
vendor/go.opentelemetry.io/contrib/LICENSE
generated
vendored
Normal file
201
vendor/go.opentelemetry.io/contrib/LICENSE
generated
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
203
vendor/go.opentelemetry.io/contrib/Makefile
generated
vendored
Normal file
203
vendor/go.opentelemetry.io/contrib/Makefile
generated
vendored
Normal file
@ -0,0 +1,203 @@
|
||||
TOOLS_MOD_DIR := ./tools
|
||||
|
||||
# All source code and documents. Used in spell check.
|
||||
ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
|
||||
# All directories with go.mod files related to opentelemetry library. Used for building, testing and linting.
|
||||
ALL_GO_MOD_DIRS := $(filter-out $(TOOLS_MOD_DIR), $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort))
|
||||
ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./example|^$(TOOLS_MOD_DIR)' | sort)
|
||||
|
||||
# URLs to check if all contrib entries exist in the registry.
|
||||
REGISTRY_BASE_URL = https://raw.githubusercontent.com/open-telemetry/opentelemetry.io/main/content/en/registry
|
||||
CONTRIB_REPO_URL = https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main
|
||||
|
||||
# Mac OS Catalina 10.5.x doesn't support 386. Hence skip 386 test
|
||||
SKIP_386_TEST = false
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
SW_VERS := $(shell sw_vers -productVersion)
|
||||
ifeq ($(shell echo $(SW_VERS) | egrep '^(10.1[5-9]|1[1-9]|[2-9])'), $(SW_VERS))
|
||||
SKIP_386_TEST = true
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
GOTEST_MIN = go test -v -timeout 30s
|
||||
GOTEST = $(GOTEST_MIN) -race
|
||||
GOTEST_WITH_COVERAGE = $(GOTEST) -coverprofile=coverage.out -covermode=atomic -coverpkg=./...
|
||||
|
||||
.DEFAULT_GOAL := precommit
|
||||
|
||||
.PHONY: precommit
|
||||
|
||||
TOOLS_DIR := $(abspath ./.tools)
|
||||
|
||||
$(TOOLS_DIR)/golangci-lint: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go
|
||||
cd $(TOOLS_MOD_DIR) && \
|
||||
go build -o $(TOOLS_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
|
||||
|
||||
$(TOOLS_DIR)/misspell: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go
|
||||
cd $(TOOLS_MOD_DIR) && \
|
||||
go build -o $(TOOLS_DIR)/misspell github.com/client9/misspell/cmd/misspell
|
||||
|
||||
$(TOOLS_DIR)/stringer: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go
|
||||
cd $(TOOLS_MOD_DIR) && \
|
||||
go build -o $(TOOLS_DIR)/stringer golang.org/x/tools/cmd/stringer
|
||||
|
||||
precommit: dependabot-check license-check generate build lint test
|
||||
|
||||
.PHONY: test-with-coverage
|
||||
test-with-coverage:
|
||||
set -e; \
|
||||
printf "" > coverage.txt; \
|
||||
for dir in $(ALL_COVERAGE_MOD_DIRS); do \
|
||||
echo "go test ./... + coverage in $${dir}"; \
|
||||
(cd "$${dir}" && \
|
||||
$(GOTEST_WITH_COVERAGE) ./... && \
|
||||
go tool cover -html=coverage.out -o coverage.html); \
|
||||
[ -f "$${dir}/coverage.out" ] && cat "$${dir}/coverage.out" >> coverage.txt; \
|
||||
done; \
|
||||
sed -i.bak -e '2,$$ { /^mode: /d; }' coverage.txt && rm coverage.txt.bak
|
||||
|
||||
.PHONY: ci
|
||||
ci: precommit check-clean-work-tree test-with-coverage test-386
|
||||
|
||||
.PHONY: test-gocql
|
||||
test-gocql:
|
||||
@if ./tools/should_build.sh gocql; then \
|
||||
set -e; \
|
||||
docker run --name cass-integ --rm -p 9042:9042 -d cassandra:3; \
|
||||
CMD=cassandra IMG_NAME=cass-integ ./tools/wait.sh; \
|
||||
(cd instrumentation/github.com/gocql/gocql/otelgocql && \
|
||||
$(GOTEST_WITH_COVERAGE) . && \
|
||||
go tool cover -html=coverage.out -o coverage.html); \
|
||||
docker stop cass-integ; \
|
||||
fi
|
||||
|
||||
.PHONY: test-mongo-driver
|
||||
test-mongo-driver:
|
||||
@if ./tools/should_build.sh mongo-driver; then \
|
||||
set -e; \
|
||||
docker run --name mongo-integ --rm -p 27017:27017 -d mongo; \
|
||||
CMD=mongo IMG_NAME=mongo-integ ./tools/wait.sh; \
|
||||
(cd instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo && \
|
||||
$(GOTEST_WITH_COVERAGE) . && \
|
||||
go tool cover -html=coverage.out -o coverage.html); \
|
||||
docker stop mongo-integ; \
|
||||
fi
|
||||
|
||||
.PHONY: test-gomemcache
|
||||
test-gomemcache:
|
||||
@if ./tools/should_build.sh gomemcache; then \
|
||||
set -e; \
|
||||
docker run --name gomemcache-integ --rm -p 11211:11211 -d memcached; \
|
||||
CMD=gomemcache IMG_NAME=gomemcache-integ ./tools/wait.sh; \
|
||||
(cd instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache && \
|
||||
$(GOTEST_WITH_COVERAGE) . && \
|
||||
go tool cover -html=coverage.out -o coverage.html); \
|
||||
docker stop gomemcache-integ ; \
|
||||
fi
|
||||
|
||||
.PHONY: check-clean-work-tree
|
||||
check-clean-work-tree:
|
||||
@if ! git diff --quiet; then \
|
||||
echo; \
|
||||
echo 'Working tree is not clean, did you forget to run "make precommit"?'; \
|
||||
echo; \
|
||||
git status; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
# TODO: Fix this on windows.
|
||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||
echo "compiling all packages in $${dir}"; \
|
||||
(cd "$${dir}" && \
|
||||
go build ./... && \
|
||||
go test -run xxxxxMatchNothingxxxxx ./... >/dev/null); \
|
||||
done
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||
echo "go test ./... + race in $${dir}"; \
|
||||
(cd "$${dir}" && \
|
||||
$(GOTEST) ./...); \
|
||||
done
|
||||
|
||||
.PHONY: test-386
|
||||
test-386:
|
||||
if [ $(SKIP_386_TEST) = true ] ; then \
|
||||
echo "skipping the test for GOARCH 386 as it is not supported on the current OS"; \
|
||||
else \
|
||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||
echo "go test ./... GOARCH 386 in $${dir}"; \
|
||||
(cd "$${dir}" && \
|
||||
GOARCH=386 $(GOTEST_MIN) ./...); \
|
||||
done; \
|
||||
fi
|
||||
|
||||
.PHONY: lint
|
||||
lint: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell
|
||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||
echo "golangci-lint in $${dir}"; \
|
||||
(cd "$${dir}" && \
|
||||
$(TOOLS_DIR)/golangci-lint run --fix && \
|
||||
$(TOOLS_DIR)/golangci-lint run); \
|
||||
done
|
||||
$(TOOLS_DIR)/misspell -w $(ALL_DOCS)
|
||||
set -e; for dir in $(ALL_GO_MOD_DIRS) $(TOOLS_MOD_DIR); do \
|
||||
echo "go mod tidy in $${dir}"; \
|
||||
(cd "$${dir}" && \
|
||||
go mod tidy); \
|
||||
done
|
||||
|
||||
.PHONY: generate
|
||||
generate: $(TOOLS_DIR)/stringer
|
||||
PATH="$(TOOLS_DIR):$${PATH}" go generate ./...
|
||||
|
||||
.PHONY: license-check
|
||||
license-check:
|
||||
@licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path './vendor/*' ! -path './exporters/otlp/internal/opentelemetry-proto/*') ; do \
|
||||
awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=3 { found=1; next } END { if (!found) print FILENAME }' $$f; \
|
||||
done); \
|
||||
if [ -n "$${licRes}" ]; then \
|
||||
echo "license header checking failed:"; echo "$${licRes}"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
.PHONY: registry-links-check
|
||||
registry-links-check:
|
||||
@checkRes=$$( \
|
||||
for f in $$( find ./instrumentation ./exporters ./detectors ! -path './instrumentation/net/*' -type f -name 'go.mod' -exec dirname {} \; | egrep -v '/example|/utils' | sort ) \
|
||||
./instrumentation/net/http; do \
|
||||
TYPE="instrumentation"; \
|
||||
if $$(echo "$$f" | grep -q "exporters"); then \
|
||||
TYPE="exporter"; \
|
||||
fi; \
|
||||
if $$(echo "$$f" | grep -q "detectors"); then \
|
||||
TYPE="detector"; \
|
||||
fi; \
|
||||
NAME=$$(echo "$$f" | sed -e 's/.*\///' -e 's/.*otel//'); \
|
||||
LINK=$(CONTRIB_REPO_URL)/$$(echo "$$f" | sed -e 's/..//' -e 's/\/otel.*$$//'); \
|
||||
if ! $$(curl -s $(REGISTRY_BASE_URL)/$${TYPE}-go-$${NAME}.md | grep -q "$${LINK}"); then \
|
||||
echo "$$f"; \
|
||||
fi \
|
||||
done; \
|
||||
); \
|
||||
if [ -n "$$checkRes" ]; then \
|
||||
echo "WARNING: registry link check failed for the following packages:"; echo "$${checkRes}"; \
|
||||
fi
|
||||
|
||||
.PHONY: dependabot-check
|
||||
dependabot-check:
|
||||
@result=$$( \
|
||||
for f in $$( find . -type f -name go.mod -exec dirname {} \; | sed 's/^.\/\?/\//' ); \
|
||||
do grep -q "$$f" .github/dependabot.yml \
|
||||
|| echo "$$f"; \
|
||||
done; \
|
||||
); \
|
||||
if [ -n "$$result" ]; then \
|
||||
echo "missing go.mod dependabot check:"; echo "$$result"; \
|
||||
exit 1; \
|
||||
fi
|
25
vendor/go.opentelemetry.io/contrib/README.md
generated
vendored
Normal file
25
vendor/go.opentelemetry.io/contrib/README.md
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
# OpenTelemetry-Go Contrib
|
||||
|
||||
[](https://github.com/open-telemetry/opentelemetry-go-contrib/actions?query=workflow%3Abuild_and_test+branch%3Amain)
|
||||
[](https://pkg.go.dev/go.opentelemetry.io/contrib)
|
||||
[](https://goreportcard.com/report/go.opentelemetry.io/contrib)
|
||||
[](https://cloud-native.slack.com/archives/C01NPAXACKT)
|
||||
|
||||
Collection of 3rd-party instrumentation and exporters for [OpenTelemetry-Go](https://github.com/open-telemetry/opentelemetry-go).
|
||||
|
||||
## Contents
|
||||
|
||||
- [Instrumentation](./instrumentation/): Packages providing OpenTelemetry instrumentation for 3rd-party libraries.
|
||||
- [Exporters](./exporters/): Packages providing OpenTelemetry exporters for 3rd-party telemetry systems.
|
||||
- [Propagators](./propagators/): Packages providing OpenTelemetry context propagators for 3rd-party propagation formats.
|
||||
- [Detectors](./detectors/): Packages providing OpenTelemetry resource detectors for 3rd-party cloud computing environments.
|
||||
|
||||
## Project Status
|
||||
|
||||
This project is currently in a pre-GA phase. Our progress towards a GA release
|
||||
candidate is tracked in [this project
|
||||
board](https://github.com/orgs/open-telemetry/projects/5).
|
||||
|
||||
## Contributing
|
||||
|
||||
For information on how to contribute, consult [the contributing guidelines](./CONTRIBUTING.md)
|
96
vendor/go.opentelemetry.io/contrib/RELEASING.md
generated
vendored
Normal file
96
vendor/go.opentelemetry.io/contrib/RELEASING.md
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
# Release Process
|
||||
|
||||
There are two types of release for the `go.opentelemetry.io/contrib` repo
|
||||
and submodules.
|
||||
|
||||
1. **Case 1** A release due to changes independent of the
|
||||
`go.opentelemetry.io/otel` module, e.g. perhaps a critical bug fix in
|
||||
one of the contrib modules.
|
||||
|
||||
2. **Case 2** A release due to a breaking API change in
|
||||
`go.opentelemetry.io/otel` which all modules in this repo
|
||||
depend on.
|
||||
|
||||
## Pre-Release
|
||||
|
||||
Update go.mod for submodules to depend on the upcoming new release of
|
||||
the module in this repo, `go.opentelemetry.io/contrib`. Decide on the
|
||||
next version of the semantic tag to apply to the contrib
|
||||
module based on whether you fall into Case 1 or Case 2.
|
||||
|
||||
### Case 1
|
||||
|
||||
If the changes are all internal to this repo, then the new tag will
|
||||
most often be a patch or minor version upgrade to the existing tag on
|
||||
this module. Let's call this `<new_contrib_tag>`.
|
||||
|
||||
### Case 2
|
||||
|
||||
If a new release is required due to breaking changes in
|
||||
`go.opentelemetry.io/otel`, then the new semantic tag for this repo
|
||||
should be bumped to match the `go.opentelemetry.io/otel` new tag.
|
||||
Let's call this `<new_otel_tag>`. The script checks that
|
||||
`go.opentelemetry.io/otel@v<new_otel_tag>` is a valid tag, so you need
|
||||
to wait until that tag has been pushed in the main repo.
|
||||
|
||||
In nearly all cases, `<new_contrib_tag>` should be the same as
|
||||
`<new_otel_tag>`.
|
||||
|
||||
1. Run `pre_release.sh` script to create a branch `pre_release_<new_contrib_tag>`.
|
||||
The script will also run `go mod tidy` and `make ci`.
|
||||
|
||||
* **Case 1** `./pre_release.sh -t <new_contrib_tag>`
|
||||
* **Case 2** `./pre_release.sh -o <new_otel_tag> [-t <new_contrib_tag>]`
|
||||
|
||||
2. If you used `-o <new_otel_tag>` to rewrite the modules to depend on
|
||||
a new version of `go.opentelemetry.io/otel`, there will likely be
|
||||
breaking changes that require fixes to the files in this
|
||||
`contrib` repo. Make the appropriate fixes to address any API
|
||||
breaks and run through the
|
||||
|
||||
```
|
||||
git commit -m "fixes due to API changes"
|
||||
make precommit
|
||||
```
|
||||
|
||||
cycle until everything passes
|
||||
|
||||
4. Push the changes to upstream.
|
||||
|
||||
```
|
||||
git diff main
|
||||
git push
|
||||
```
|
||||
|
||||
5. Create a PR on github and merge the PR once approved.
|
||||
|
||||
|
||||
### Tag
|
||||
Now create a `<new_contrib_tag>` on the commit hash of the changes made in pre-release step,
|
||||
|
||||
1. Run the tag.sh script.
|
||||
|
||||
```
|
||||
./tag.sh <new_contrib_tag> <commit-hash>
|
||||
```
|
||||
2. Push tags upstream. Make sure you push upstream for all the sub-module tags as well.
|
||||
|
||||
```
|
||||
git push upstream <new_contrib_tag>
|
||||
git push upstream <submodules-path/new_contrib_tag>
|
||||
...
|
||||
```
|
||||
|
||||
## Release
|
||||
Now create a release for the new `<new_contrib_tag>` on github.
|
||||
The release body should include all the release notes in the Changelog for this release.
|
||||
Additionally, the `tag.sh` script generates commit logs since last release which can be used to suppliment the release notes.
|
||||
|
||||
<!-- ## Verify Examples -->
|
||||
<!-- After releasing run following script to verify that examples build outside of the otel repo. -->
|
||||
<!-- The script copies examples into a different directory and builds them. -->
|
||||
|
||||
<!-- ``` -->
|
||||
<!-- ./verify_examples.sh -->
|
||||
<!-- ``` -->
|
||||
|
28
vendor/go.opentelemetry.io/contrib/contrib.go
generated
vendored
Normal file
28
vendor/go.opentelemetry.io/contrib/contrib.go
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package contrib contains common values used across all
|
||||
// instrumentation, exporter, and detector contributions.
|
||||
package contrib // import "go.opentelemetry.io/contrib"
|
||||
|
||||
// Version is the current release version of OpenTelemetry Contrib in use.
|
||||
func Version() string {
|
||||
return "0.20.0"
|
||||
// This string is updated by the pre_release.sh script during release
|
||||
}
|
||||
|
||||
// SemVersion is the semantic version to be supplied to tracer/meter creation.
|
||||
func SemVersion() string {
|
||||
return "semver:" + Version()
|
||||
}
|
20
vendor/go.opentelemetry.io/contrib/doc.go
generated
vendored
Normal file
20
vendor/go.opentelemetry.io/contrib/doc.go
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// This package provides all of its functionality through its
|
||||
// submodules. The submodules in the exporters directory provide
|
||||
// implementations for trace and metric exporters for third-party
|
||||
// collectors, and submodules in the instrumentation directory provide the
|
||||
// instrumentation for the popular go libraries.
|
||||
package contrib
|
3
vendor/go.opentelemetry.io/contrib/go.mod
generated
vendored
Normal file
3
vendor/go.opentelemetry.io/contrib/go.mod
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
module go.opentelemetry.io/contrib
|
||||
|
||||
go 1.14
|
0
vendor/go.opentelemetry.io/contrib/go.sum
generated
vendored
Normal file
0
vendor/go.opentelemetry.io/contrib/go.sum
generated
vendored
Normal file
201
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/LICENSE
generated
vendored
Normal file
201
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/LICENSE
generated
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
61
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/client.go
generated
vendored
Normal file
61
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/client.go
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otelhttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DefaultClient is the default Client and is used by Get, Head, Post and PostForm.
|
||||
// Please be careful of intitialization order - for example, if you change
|
||||
// the global propagator, the DefaultClient might still be using the old one
|
||||
var DefaultClient = &http.Client{Transport: NewTransport(http.DefaultTransport)}
|
||||
|
||||
// Get is a convenient replacement for http.Get that adds a span around the request.
|
||||
func Get(ctx context.Context, url string) (resp *http.Response, err error) {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return DefaultClient.Do(req)
|
||||
}
|
||||
|
||||
// Head is a convenient replacement for http.Head that adds a span around the request.
|
||||
func Head(ctx context.Context, url string) (resp *http.Response, err error) {
|
||||
req, err := http.NewRequestWithContext(ctx, "HEAD", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return DefaultClient.Do(req)
|
||||
}
|
||||
|
||||
// Post is a convenient replacement for http.Post that adds a span around the request.
|
||||
func Post(ctx context.Context, url, contentType string, body io.Reader) (resp *http.Response, err error) {
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", contentType)
|
||||
return DefaultClient.Do(req)
|
||||
}
|
||||
|
||||
// PostForm is a convenient replacement for http.PostForm that adds a span around the request.
|
||||
func PostForm(ctx context.Context, url string, data url.Values) (resp *http.Response, err error) {
|
||||
return Post(ctx, url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
|
||||
}
|
41
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/common.go
generated
vendored
Normal file
41
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/common.go
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otelhttp
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
)
|
||||
|
||||
// Attribute keys that can be added to a span.
|
||||
const (
|
||||
ReadBytesKey = attribute.Key("http.read_bytes") // if anything was read from the request body, the total number of bytes read
|
||||
ReadErrorKey = attribute.Key("http.read_error") // If an error occurred while reading a request, the string of the error (io.EOF is not recorded)
|
||||
WroteBytesKey = attribute.Key("http.wrote_bytes") // if anything was written to the response writer, the total number of bytes written
|
||||
WriteErrorKey = attribute.Key("http.write_error") // if an error occurred while writing a reply, the string of the error (io.EOF is not recorded)
|
||||
)
|
||||
|
||||
// Server HTTP metrics
|
||||
const (
|
||||
RequestCount = "http.server.request_count" // Incoming request count total
|
||||
RequestContentLength = "http.server.request_content_length" // Incoming request bytes total
|
||||
ResponseContentLength = "http.server.response_content_length" // Incoming response bytes total
|
||||
ServerLatency = "http.server.duration" // Incoming end to end duration, microseconds
|
||||
)
|
||||
|
||||
// Filter is a predicate used to determine whether a given http.request should
|
||||
// be traced. A Filter must return true if the request should be traced.
|
||||
type Filter func(*http.Request) bool
|
173
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/config.go
generated
vendored
Normal file
173
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/config.go
generated
vendored
Normal file
@ -0,0 +1,173 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otelhttp
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"go.opentelemetry.io/contrib"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/global"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
const (
|
||||
instrumentationName = "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
)
|
||||
|
||||
// config represents the configuration options available for the http.Handler
|
||||
// and http.Transport types.
|
||||
type config struct {
|
||||
Tracer trace.Tracer
|
||||
Meter metric.Meter
|
||||
Propagators propagation.TextMapPropagator
|
||||
SpanStartOptions []trace.SpanOption
|
||||
ReadEvent bool
|
||||
WriteEvent bool
|
||||
Filters []Filter
|
||||
SpanNameFormatter func(string, *http.Request) string
|
||||
|
||||
TracerProvider trace.TracerProvider
|
||||
MeterProvider metric.MeterProvider
|
||||
}
|
||||
|
||||
// Option Interface used for setting *optional* config properties
|
||||
type Option interface {
|
||||
Apply(*config)
|
||||
}
|
||||
|
||||
// OptionFunc provides a convenience wrapper for simple Options
|
||||
// that can be represented as functions.
|
||||
type OptionFunc func(*config)
|
||||
|
||||
func (o OptionFunc) Apply(c *config) {
|
||||
o(c)
|
||||
}
|
||||
|
||||
// newConfig creates a new config struct and applies opts to it.
|
||||
func newConfig(opts ...Option) *config {
|
||||
c := &config{
|
||||
Propagators: otel.GetTextMapPropagator(),
|
||||
TracerProvider: otel.GetTracerProvider(),
|
||||
MeterProvider: global.GetMeterProvider(),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt.Apply(c)
|
||||
}
|
||||
|
||||
c.Tracer = c.TracerProvider.Tracer(
|
||||
instrumentationName,
|
||||
trace.WithInstrumentationVersion(contrib.SemVersion()),
|
||||
)
|
||||
c.Meter = c.MeterProvider.Meter(
|
||||
instrumentationName,
|
||||
metric.WithInstrumentationVersion(contrib.SemVersion()),
|
||||
)
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
// WithTracerProvider specifies a tracer provider to use for creating a tracer.
|
||||
// If none is specified, the global provider is used.
|
||||
func WithTracerProvider(provider trace.TracerProvider) Option {
|
||||
return OptionFunc(func(cfg *config) {
|
||||
cfg.TracerProvider = provider
|
||||
})
|
||||
}
|
||||
|
||||
// WithMeterProvider specifies a meter provider to use for creating a meter.
|
||||
// If none is specified, the global provider is used.
|
||||
func WithMeterProvider(provider metric.MeterProvider) Option {
|
||||
return OptionFunc(func(cfg *config) {
|
||||
cfg.MeterProvider = provider
|
||||
})
|
||||
}
|
||||
|
||||
// WithPublicEndpoint configures the Handler to link the span with an incoming
|
||||
// span context. If this option is not provided, then the association is a child
|
||||
// association instead of a link.
|
||||
func WithPublicEndpoint() Option {
|
||||
return OptionFunc(func(c *config) {
|
||||
c.SpanStartOptions = append(c.SpanStartOptions, trace.WithNewRoot())
|
||||
})
|
||||
}
|
||||
|
||||
// WithPropagators configures specific propagators. If this
|
||||
// option isn't specified then
|
||||
func WithPropagators(ps propagation.TextMapPropagator) Option {
|
||||
return OptionFunc(func(c *config) {
|
||||
c.Propagators = ps
|
||||
})
|
||||
}
|
||||
|
||||
// WithSpanOptions configures an additional set of
|
||||
// trace.SpanOptions, which are applied to each new span.
|
||||
func WithSpanOptions(opts ...trace.SpanOption) Option {
|
||||
return OptionFunc(func(c *config) {
|
||||
c.SpanStartOptions = append(c.SpanStartOptions, opts...)
|
||||
})
|
||||
}
|
||||
|
||||
// WithFilter adds a filter to the list of filters used by the handler.
|
||||
// If any filter indicates to exclude a request then the request will not be
|
||||
// traced. All filters must allow a request to be traced for a Span to be created.
|
||||
// If no filters are provided then all requests are traced.
|
||||
// Filters will be invoked for each processed request, it is advised to make them
|
||||
// simple and fast.
|
||||
func WithFilter(f Filter) Option {
|
||||
return OptionFunc(func(c *config) {
|
||||
c.Filters = append(c.Filters, f)
|
||||
})
|
||||
}
|
||||
|
||||
type event int
|
||||
|
||||
// Different types of events that can be recorded, see WithMessageEvents
|
||||
const (
|
||||
ReadEvents event = iota
|
||||
WriteEvents
|
||||
)
|
||||
|
||||
// WithMessageEvents configures the Handler to record the specified events
|
||||
// (span.AddEvent) on spans. By default only summary attributes are added at the
|
||||
// end of the request.
|
||||
//
|
||||
// Valid events are:
|
||||
// * ReadEvents: Record the number of bytes read after every http.Request.Body.Read
|
||||
// using the ReadBytesKey
|
||||
// * WriteEvents: Record the number of bytes written after every http.ResponeWriter.Write
|
||||
// using the WriteBytesKey
|
||||
func WithMessageEvents(events ...event) Option {
|
||||
return OptionFunc(func(c *config) {
|
||||
for _, e := range events {
|
||||
switch e {
|
||||
case ReadEvents:
|
||||
c.ReadEvent = true
|
||||
case WriteEvents:
|
||||
c.WriteEvent = true
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// WithSpanNameFormatter takes a function that will be called on every
|
||||
// request and the returned string will become the Span Name
|
||||
func WithSpanNameFormatter(f func(operation string, r *http.Request) string) Option {
|
||||
return OptionFunc(func(c *config) {
|
||||
c.SpanNameFormatter = f
|
||||
})
|
||||
}
|
18
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/doc.go
generated
vendored
Normal file
18
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/doc.go
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package otelhttp provides an http.Handler and functions that are intended
|
||||
// to be used to add tracing by wrapping existing handlers (with Handler) and
|
||||
// routes WithRouteTag.
|
||||
package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
15
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/go.mod
generated
vendored
Normal file
15
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/go.mod
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
module go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp
|
||||
|
||||
go 1.14
|
||||
|
||||
replace go.opentelemetry.io/contrib => ../../../..
|
||||
|
||||
require (
|
||||
github.com/felixge/httpsnoop v1.0.1
|
||||
github.com/stretchr/testify v1.7.0
|
||||
go.opentelemetry.io/contrib v0.20.0
|
||||
go.opentelemetry.io/otel v0.20.0
|
||||
go.opentelemetry.io/otel/metric v0.20.0
|
||||
go.opentelemetry.io/otel/oteltest v0.20.0
|
||||
go.opentelemetry.io/otel/trace v0.20.0
|
||||
)
|
25
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/go.sum
generated
vendored
Normal file
25
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/go.sum
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
|
||||
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
go.opentelemetry.io/otel v0.20.0 h1:eaP0Fqu7SXHwvjiqDq83zImeehOHX8doTvU9AwXON8g=
|
||||
go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo=
|
||||
go.opentelemetry.io/otel/metric v0.20.0 h1:4kzhXFP+btKm4jwxpjIqjs41A7MakRFUS86bqLHTIw8=
|
||||
go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU=
|
||||
go.opentelemetry.io/otel/oteltest v0.20.0 h1:HiITxCawalo5vQzdHfKeZurV8x7ljcqAgiWzF6Vaeaw=
|
||||
go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw=
|
||||
go.opentelemetry.io/otel/trace v0.20.0 h1:1DL6EXUdcg95gukhuRRvLDO/4X5THh/5dIV52lqtnbw=
|
||||
go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
225
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/handler.go
generated
vendored
Normal file
225
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/handler.go
generated
vendored
Normal file
@ -0,0 +1,225 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otelhttp
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/felixge/httpsnoop"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/semconv"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var _ http.Handler = &Handler{}
|
||||
|
||||
// Handler is http middleware that corresponds to the http.Handler interface and
|
||||
// is designed to wrap a http.Mux (or equivalent), while individual routes on
|
||||
// the mux are wrapped with WithRouteTag. A Handler will add various attributes
|
||||
// to the span using the attribute.Keys defined in this package.
|
||||
type Handler struct {
|
||||
operation string
|
||||
handler http.Handler
|
||||
|
||||
tracer trace.Tracer
|
||||
meter metric.Meter
|
||||
propagators propagation.TextMapPropagator
|
||||
spanStartOptions []trace.SpanOption
|
||||
readEvent bool
|
||||
writeEvent bool
|
||||
filters []Filter
|
||||
spanNameFormatter func(string, *http.Request) string
|
||||
counters map[string]metric.Int64Counter
|
||||
valueRecorders map[string]metric.Int64ValueRecorder
|
||||
}
|
||||
|
||||
func defaultHandlerFormatter(operation string, _ *http.Request) string {
|
||||
return operation
|
||||
}
|
||||
|
||||
// NewHandler wraps the passed handler, functioning like middleware, in a span
|
||||
// named after the operation and with any provided Options.
|
||||
func NewHandler(handler http.Handler, operation string, opts ...Option) http.Handler {
|
||||
h := Handler{
|
||||
handler: handler,
|
||||
operation: operation,
|
||||
}
|
||||
|
||||
defaultOpts := []Option{
|
||||
WithSpanOptions(trace.WithSpanKind(trace.SpanKindServer)),
|
||||
WithSpanNameFormatter(defaultHandlerFormatter),
|
||||
}
|
||||
|
||||
c := newConfig(append(defaultOpts, opts...)...)
|
||||
h.configure(c)
|
||||
h.createMeasures()
|
||||
|
||||
return &h
|
||||
}
|
||||
|
||||
func (h *Handler) configure(c *config) {
|
||||
h.tracer = c.Tracer
|
||||
h.meter = c.Meter
|
||||
h.propagators = c.Propagators
|
||||
h.spanStartOptions = c.SpanStartOptions
|
||||
h.readEvent = c.ReadEvent
|
||||
h.writeEvent = c.WriteEvent
|
||||
h.filters = c.Filters
|
||||
h.spanNameFormatter = c.SpanNameFormatter
|
||||
}
|
||||
|
||||
func handleErr(err error) {
|
||||
if err != nil {
|
||||
otel.Handle(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) createMeasures() {
|
||||
h.counters = make(map[string]metric.Int64Counter)
|
||||
h.valueRecorders = make(map[string]metric.Int64ValueRecorder)
|
||||
|
||||
requestBytesCounter, err := h.meter.NewInt64Counter(RequestContentLength)
|
||||
handleErr(err)
|
||||
|
||||
responseBytesCounter, err := h.meter.NewInt64Counter(ResponseContentLength)
|
||||
handleErr(err)
|
||||
|
||||
serverLatencyMeasure, err := h.meter.NewInt64ValueRecorder(ServerLatency)
|
||||
handleErr(err)
|
||||
|
||||
h.counters[RequestContentLength] = requestBytesCounter
|
||||
h.counters[ResponseContentLength] = responseBytesCounter
|
||||
h.valueRecorders[ServerLatency] = serverLatencyMeasure
|
||||
}
|
||||
|
||||
// ServeHTTP serves HTTP requests (http.Handler)
|
||||
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
requestStartTime := time.Now()
|
||||
for _, f := range h.filters {
|
||||
if !f(r) {
|
||||
// Simply pass through to the handler if a filter rejects the request
|
||||
h.handler.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
opts := append([]trace.SpanOption{
|
||||
trace.WithAttributes(semconv.NetAttributesFromHTTPRequest("tcp", r)...),
|
||||
trace.WithAttributes(semconv.EndUserAttributesFromHTTPRequest(r)...),
|
||||
trace.WithAttributes(semconv.HTTPServerAttributesFromHTTPRequest(h.operation, "", r)...),
|
||||
}, h.spanStartOptions...) // start with the configured options
|
||||
|
||||
ctx := h.propagators.Extract(r.Context(), propagation.HeaderCarrier(r.Header))
|
||||
ctx, span := h.tracer.Start(ctx, h.spanNameFormatter(h.operation, r), opts...)
|
||||
defer span.End()
|
||||
|
||||
readRecordFunc := func(int64) {}
|
||||
if h.readEvent {
|
||||
readRecordFunc = func(n int64) {
|
||||
span.AddEvent("read", trace.WithAttributes(ReadBytesKey.Int64(n)))
|
||||
}
|
||||
}
|
||||
|
||||
var bw bodyWrapper
|
||||
// if request body is nil we don't want to mutate the body as it will affect
|
||||
// the identity of it in a unforeseeable way because we assert ReadCloser
|
||||
// fullfills a certain interface and it is indeed nil.
|
||||
if r.Body != nil {
|
||||
bw.ReadCloser = r.Body
|
||||
bw.record = readRecordFunc
|
||||
r.Body = &bw
|
||||
}
|
||||
|
||||
writeRecordFunc := func(int64) {}
|
||||
if h.writeEvent {
|
||||
writeRecordFunc = func(n int64) {
|
||||
span.AddEvent("write", trace.WithAttributes(WroteBytesKey.Int64(n)))
|
||||
}
|
||||
}
|
||||
|
||||
rww := &respWriterWrapper{ResponseWriter: w, record: writeRecordFunc, ctx: ctx, props: h.propagators}
|
||||
|
||||
// Wrap w to use our ResponseWriter methods while also exposing
|
||||
// other interfaces that w may implement (http.CloseNotifier,
|
||||
// http.Flusher, http.Hijacker, http.Pusher, io.ReaderFrom).
|
||||
|
||||
w = httpsnoop.Wrap(w, httpsnoop.Hooks{
|
||||
Header: func(httpsnoop.HeaderFunc) httpsnoop.HeaderFunc {
|
||||
return rww.Header
|
||||
},
|
||||
Write: func(httpsnoop.WriteFunc) httpsnoop.WriteFunc {
|
||||
return rww.Write
|
||||
},
|
||||
WriteHeader: func(httpsnoop.WriteHeaderFunc) httpsnoop.WriteHeaderFunc {
|
||||
return rww.WriteHeader
|
||||
},
|
||||
})
|
||||
|
||||
labeler := &Labeler{}
|
||||
ctx = injectLabeler(ctx, labeler)
|
||||
|
||||
h.handler.ServeHTTP(w, r.WithContext(ctx))
|
||||
|
||||
setAfterServeAttributes(span, bw.read, rww.written, rww.statusCode, bw.err, rww.err)
|
||||
|
||||
// Add metrics
|
||||
attributes := append(labeler.Get(), semconv.HTTPServerMetricAttributesFromHTTPRequest(h.operation, r)...)
|
||||
h.counters[RequestContentLength].Add(ctx, bw.read, attributes...)
|
||||
h.counters[ResponseContentLength].Add(ctx, rww.written, attributes...)
|
||||
|
||||
elapsedTime := time.Since(requestStartTime).Microseconds()
|
||||
|
||||
h.valueRecorders[ServerLatency].Record(ctx, elapsedTime, attributes...)
|
||||
}
|
||||
|
||||
func setAfterServeAttributes(span trace.Span, read, wrote int64, statusCode int, rerr, werr error) {
|
||||
attributes := []attribute.KeyValue{}
|
||||
|
||||
// TODO: Consider adding an event after each read and write, possibly as an
|
||||
// option (defaulting to off), so as to not create needlessly verbose spans.
|
||||
if read > 0 {
|
||||
attributes = append(attributes, ReadBytesKey.Int64(read))
|
||||
}
|
||||
if rerr != nil && rerr != io.EOF {
|
||||
attributes = append(attributes, ReadErrorKey.String(rerr.Error()))
|
||||
}
|
||||
if wrote > 0 {
|
||||
attributes = append(attributes, WroteBytesKey.Int64(wrote))
|
||||
}
|
||||
if statusCode > 0 {
|
||||
attributes = append(attributes, semconv.HTTPAttributesFromHTTPStatusCode(statusCode)...)
|
||||
span.SetStatus(semconv.SpanStatusFromHTTPStatusCode(statusCode))
|
||||
}
|
||||
if werr != nil && werr != io.EOF {
|
||||
attributes = append(attributes, WriteErrorKey.String(werr.Error()))
|
||||
}
|
||||
span.SetAttributes(attributes...)
|
||||
}
|
||||
|
||||
// WithRouteTag annotates a span with the provided route name using the
|
||||
// RouteKey Tag.
|
||||
func WithRouteTag(route string, h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
span := trace.SpanFromContext(r.Context())
|
||||
span.SetAttributes(semconv.HTTPRouteKey.String(route))
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
65
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/labeler.go
generated
vendored
Normal file
65
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/labeler.go
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otelhttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
)
|
||||
|
||||
// Labeler is used to allow instrumented HTTP handlers to add custom attributes to
|
||||
// the metrics recorded by the net/http instrumentation.
|
||||
type Labeler struct {
|
||||
mu sync.Mutex
|
||||
attributes []attribute.KeyValue
|
||||
}
|
||||
|
||||
// Add attributes to a Labeler.
|
||||
func (l *Labeler) Add(ls ...attribute.KeyValue) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
l.attributes = append(l.attributes, ls...)
|
||||
}
|
||||
|
||||
// Labels returns a copy of the attributes added to the Labeler.
|
||||
func (l *Labeler) Get() []attribute.KeyValue {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
ret := make([]attribute.KeyValue, len(l.attributes))
|
||||
copy(ret, l.attributes)
|
||||
return ret
|
||||
}
|
||||
|
||||
type labelerContextKeyType int
|
||||
|
||||
const lablelerContextKey labelerContextKeyType = 0
|
||||
|
||||
func injectLabeler(ctx context.Context, l *Labeler) context.Context {
|
||||
return context.WithValue(ctx, lablelerContextKey, l)
|
||||
}
|
||||
|
||||
// LabelerFromContext retrieves a Labeler instance from the provided context if
|
||||
// one is available. If no Labeler was found in the provided context a new, empty
|
||||
// Labeler is returned and the second return value is false. In this case it is
|
||||
// safe to use the Labeler but any attributes added to it will not be used.
|
||||
func LabelerFromContext(ctx context.Context) (*Labeler, bool) {
|
||||
l, ok := ctx.Value(lablelerContextKey).(*Labeler)
|
||||
if !ok {
|
||||
l = &Labeler{}
|
||||
}
|
||||
return l, ok
|
||||
}
|
136
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/transport.go
generated
vendored
Normal file
136
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/transport.go
generated
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otelhttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/semconv"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// Transport implements the http.RoundTripper interface and wraps
|
||||
// outbound HTTP(S) requests with a span.
|
||||
type Transport struct {
|
||||
rt http.RoundTripper
|
||||
|
||||
tracer trace.Tracer
|
||||
propagators propagation.TextMapPropagator
|
||||
spanStartOptions []trace.SpanOption
|
||||
filters []Filter
|
||||
spanNameFormatter func(string, *http.Request) string
|
||||
}
|
||||
|
||||
var _ http.RoundTripper = &Transport{}
|
||||
|
||||
// NewTransport wraps the provided http.RoundTripper with one that
|
||||
// starts a span and injects the span context into the outbound request headers.
|
||||
//
|
||||
// If the provided http.RoundTripper is nil, http.DefaultTransport will be used
|
||||
// as the base http.RoundTripper
|
||||
func NewTransport(base http.RoundTripper, opts ...Option) *Transport {
|
||||
if base == nil {
|
||||
base = http.DefaultTransport
|
||||
}
|
||||
|
||||
t := Transport{
|
||||
rt: base,
|
||||
}
|
||||
|
||||
defaultOpts := []Option{
|
||||
WithSpanOptions(trace.WithSpanKind(trace.SpanKindClient)),
|
||||
WithSpanNameFormatter(defaultTransportFormatter),
|
||||
}
|
||||
|
||||
c := newConfig(append(defaultOpts, opts...)...)
|
||||
t.applyConfig(c)
|
||||
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t *Transport) applyConfig(c *config) {
|
||||
t.tracer = c.Tracer
|
||||
t.propagators = c.Propagators
|
||||
t.spanStartOptions = c.SpanStartOptions
|
||||
t.filters = c.Filters
|
||||
t.spanNameFormatter = c.SpanNameFormatter
|
||||
}
|
||||
|
||||
func defaultTransportFormatter(_ string, r *http.Request) string {
|
||||
return r.Method
|
||||
}
|
||||
|
||||
// RoundTrip creates a Span and propagates its context via the provided request's headers
|
||||
// before handing the request to the configured base RoundTripper. The created span will
|
||||
// end when the response body is closed or when a read from the body returns io.EOF.
|
||||
func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
for _, f := range t.filters {
|
||||
if !f(r) {
|
||||
// Simply pass through to the base RoundTripper if a filter rejects the request
|
||||
return t.rt.RoundTrip(r)
|
||||
}
|
||||
}
|
||||
|
||||
opts := append([]trace.SpanOption{}, t.spanStartOptions...) // start with the configured options
|
||||
|
||||
ctx, span := t.tracer.Start(r.Context(), t.spanNameFormatter("", r), opts...)
|
||||
|
||||
r = r.WithContext(ctx)
|
||||
span.SetAttributes(semconv.HTTPClientAttributesFromHTTPRequest(r)...)
|
||||
t.propagators.Inject(ctx, propagation.HeaderCarrier(r.Header))
|
||||
|
||||
res, err := t.rt.RoundTrip(r)
|
||||
if err != nil {
|
||||
span.RecordError(err)
|
||||
span.End()
|
||||
return res, err
|
||||
}
|
||||
|
||||
span.SetAttributes(semconv.HTTPAttributesFromHTTPStatusCode(res.StatusCode)...)
|
||||
span.SetStatus(semconv.SpanStatusFromHTTPStatusCode(res.StatusCode))
|
||||
res.Body = &wrappedBody{ctx: ctx, span: span, body: res.Body}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
type wrappedBody struct {
|
||||
ctx context.Context
|
||||
span trace.Span
|
||||
body io.ReadCloser
|
||||
}
|
||||
|
||||
var _ io.ReadCloser = &wrappedBody{}
|
||||
|
||||
func (wb *wrappedBody) Read(b []byte) (int, error) {
|
||||
n, err := wb.body.Read(b)
|
||||
|
||||
switch err {
|
||||
case nil:
|
||||
// nothing to do here but fall through to the return
|
||||
case io.EOF:
|
||||
wb.span.End()
|
||||
default:
|
||||
wb.span.RecordError(err)
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (wb *wrappedBody) Close() error {
|
||||
wb.span.End()
|
||||
return wb.body.Close()
|
||||
}
|
96
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/wrap.go
generated
vendored
Normal file
96
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/wrap.go
generated
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otelhttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
)
|
||||
|
||||
var _ io.ReadCloser = &bodyWrapper{}
|
||||
|
||||
// bodyWrapper wraps a http.Request.Body (an io.ReadCloser) to track the number
|
||||
// of bytes read and the last error
|
||||
type bodyWrapper struct {
|
||||
io.ReadCloser
|
||||
record func(n int64) // must not be nil
|
||||
|
||||
read int64
|
||||
err error
|
||||
}
|
||||
|
||||
func (w *bodyWrapper) Read(b []byte) (int, error) {
|
||||
n, err := w.ReadCloser.Read(b)
|
||||
n1 := int64(n)
|
||||
w.read += n1
|
||||
w.err = err
|
||||
w.record(n1)
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (w *bodyWrapper) Close() error {
|
||||
return w.ReadCloser.Close()
|
||||
}
|
||||
|
||||
var _ http.ResponseWriter = &respWriterWrapper{}
|
||||
|
||||
// respWriterWrapper wraps a http.ResponseWriter in order to track the number of
|
||||
// bytes written, the last error, and to catch the returned statusCode
|
||||
// TODO: The wrapped http.ResponseWriter doesn't implement any of the optional
|
||||
// types (http.Hijacker, http.Pusher, http.CloseNotifier, http.Flusher, etc)
|
||||
// that may be useful when using it in real life situations.
|
||||
type respWriterWrapper struct {
|
||||
http.ResponseWriter
|
||||
record func(n int64) // must not be nil
|
||||
|
||||
// used to inject the header
|
||||
ctx context.Context
|
||||
|
||||
props propagation.TextMapPropagator
|
||||
|
||||
written int64
|
||||
statusCode int
|
||||
err error
|
||||
wroteHeader bool
|
||||
}
|
||||
|
||||
func (w *respWriterWrapper) Header() http.Header {
|
||||
return w.ResponseWriter.Header()
|
||||
}
|
||||
|
||||
func (w *respWriterWrapper) Write(p []byte) (int, error) {
|
||||
if !w.wroteHeader {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
n, err := w.ResponseWriter.Write(p)
|
||||
n1 := int64(n)
|
||||
w.record(n1)
|
||||
w.written += n1
|
||||
w.err = err
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (w *respWriterWrapper) WriteHeader(statusCode int) {
|
||||
if w.wroteHeader {
|
||||
return
|
||||
}
|
||||
w.wroteHeader = true
|
||||
w.statusCode = statusCode
|
||||
w.props.Inject(w.ctx, propagation.HeaderCarrier(w.Header()))
|
||||
w.ResponseWriter.WriteHeader(statusCode)
|
||||
}
|
158
vendor/go.opentelemetry.io/contrib/pre_release.sh
generated
vendored
Normal file
158
vendor/go.opentelemetry.io/contrib/pre_release.sh
generated
vendored
Normal file
@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright The OpenTelemetry Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#
|
||||
# This script is used for
|
||||
# a) creating a new tagged release of go.opentelemetry.io/contrib
|
||||
# b) bumping the referenced version of go.opentelemetry.io/otel
|
||||
#
|
||||
# The options can be used together or individually.
|
||||
#
|
||||
set -e
|
||||
|
||||
declare CONTRIB_TAG
|
||||
declare OTEL_TAG
|
||||
|
||||
help() {
|
||||
printf "\n"
|
||||
printf "Usage: %s [-o otel_tag] [-t tag]\n" "$0"
|
||||
printf "\t-o Otel release tag. Update all go.mod to reference go.opentelemetry.io/otel <otel_tag>.\n"
|
||||
printf "\t-t New Contrib unreleased tag. Update all go.mod files with this tag.\n"
|
||||
exit 1 # Exit script after printing help
|
||||
}
|
||||
|
||||
while getopts "t:o:" opt
|
||||
do
|
||||
case "$opt" in
|
||||
t ) CONTRIB_TAG="$OPTARG" ;;
|
||||
o ) OTEL_TAG="$OPTARG" ;;
|
||||
? ) help ;; # Print help
|
||||
esac
|
||||
done
|
||||
|
||||
declare -r SEMVER_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
|
||||
|
||||
validate_tag() {
|
||||
local tag_=$1
|
||||
if [[ "${tag_}" =~ ${SEMVER_REGEX} ]]; then
|
||||
printf "%s is valid semver tag.\n" "${tag_}"
|
||||
else
|
||||
printf "%s is not a valid semver tag.\n" "${tag_}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Print help in case parameters are empty
|
||||
if [[ -z "$CONTRIB_TAG" && -z "$OTEL_TAG" ]]
|
||||
then
|
||||
printf "At least one of '-o' or '-t' must be specified.\n"
|
||||
help
|
||||
fi
|
||||
|
||||
|
||||
## Validate tags first
|
||||
if [ -n "${OTEL_TAG}" ]; then
|
||||
validate_tag "${OTEL_TAG}" || exit $?
|
||||
|
||||
# check that OTEL_TAG is a currently released tag for go.opentelemetry.io/otel
|
||||
TMPDIR=$(mktemp -d "/tmp/otel-contrib.XXXXXX") || exit 1
|
||||
trap "rm -fr ${TMPDIR}" EXIT
|
||||
(cd "${TMPDIR}" && go mod init tagtest)
|
||||
# requires go 1.14 for support of '-modfile'
|
||||
if ! go get -modfile="${TMPDIR}/go.mod" -d -v "go.opentelemetry.io/otel@${OTEL_TAG}"; then
|
||||
printf "go.opentelemetry.io/otel %s does not exist. Please supply a valid tag\n" "${OTEL_TAG}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
if [ -n "${CONTRIB_TAG}" ]; then
|
||||
validate_tag "${CONTRIB_TAG}" || exit $?
|
||||
TAG_FOUND=$(git tag --list "${CONTRIB_TAG}")
|
||||
if [[ ${TAG_FOUND} = "${CONTRIB_TAG}" ]] ; then
|
||||
printf "Tag %s already exists in this repo\n" "${CONTRIB_TAG}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
CONTRIB_TAG=${OTEL_TAG} # if contrib_tag not specified, but OTEL_TAG is, then set it to OTEL_TAG
|
||||
fi
|
||||
|
||||
# Get version for contrib.go
|
||||
OTEL_CONTRIB_VERSION=$(echo "${CONTRIB_TAG}" | egrep -o "${SEMVER_REGEX}")
|
||||
# Strip leading v
|
||||
OTEL_CONTRIB_VERSION="${OTEL_CONTRIB_VERSION#v}"
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
if ! git diff --quiet; then \
|
||||
printf "Working tree is not clean, can't proceed\n"
|
||||
git status
|
||||
git diff
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Update contrib.go version definition
|
||||
cp contrib.go contrib.go.bak
|
||||
sed "s/\(return \"\)[0-9]*\.[0-9]*\.[0-9]*\"/\1${OTEL_CONTRIB_VERSION}\"/" ./contrib.go.bak > ./contrib.go
|
||||
rm -f ./contrib.go.bak
|
||||
|
||||
declare -r BRANCH_NAME=pre_release_${CONTRIB_TAG}
|
||||
|
||||
patch_gomods() {
|
||||
local pkg_=$1
|
||||
local tag_=$2
|
||||
# now do the same for all the directories underneath
|
||||
PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep -v 'tools' | sed 's|^\.\/||' | sort)
|
||||
# quote any '.' characters in the pkg name
|
||||
local quoted_pkg_=${pkg_//./\\.}
|
||||
for dir in $PACKAGE_DIRS; do
|
||||
cp "${dir}/go.mod" "${dir}/go.mod.bak"
|
||||
sed "s|${quoted_pkg_}\([^ ]*\) v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*[^0-9]*.*$|${pkg_}\1 ${tag_}|" "${dir}/go.mod.bak" >"${dir}/go.mod"
|
||||
rm -f "${dir}/go.mod.bak"
|
||||
done
|
||||
}
|
||||
|
||||
# branch off from existing main
|
||||
git checkout -b "${BRANCH_NAME}" main
|
||||
|
||||
# Update go.mods
|
||||
if [ -n "${OTEL_TAG}" ]; then
|
||||
# first update the top most module
|
||||
go get "go.opentelemetry.io/otel@${OTEL_TAG}"
|
||||
patch_gomods go.opentelemetry.io/otel "${OTEL_TAG}"
|
||||
fi
|
||||
|
||||
if [ -n "${CONTRIB_TAG}" ]; then
|
||||
patch_gomods go.opentelemetry.io/contrib "${CONTRIB_TAG}"
|
||||
fi
|
||||
|
||||
git diff
|
||||
# Run lint to update go.sum
|
||||
make lint
|
||||
|
||||
# Add changes and commit.
|
||||
git add .
|
||||
make ci
|
||||
# Check whether registry links are up to date
|
||||
make registry-links-check
|
||||
|
||||
declare COMMIT_MSG=""
|
||||
if [ -n "${OTEL_TAG}" ]; then
|
||||
COMMIT_MSG+="Bumping otel version to ${OTEL_TAG}"
|
||||
fi
|
||||
COMMIT_MSG+=". Prepare for releasing ${CONTRIB_TAG}"
|
||||
git commit -m "${COMMIT_MSG}"
|
||||
|
||||
printf "Now run following to verify the changes.\ngit diff main\n"
|
||||
printf "\nThen push the changes to upstream\n"
|
178
vendor/go.opentelemetry.io/contrib/tag.sh
generated
vendored
Normal file
178
vendor/go.opentelemetry.io/contrib/tag.sh
generated
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright The OpenTelemetry Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
readonly PROGNAME=$(basename "$0")
|
||||
readonly PROGDIR=$(readlink -m "$(dirname "$0")")
|
||||
|
||||
readonly EXCLUDE_PACKAGES="tools"
|
||||
readonly SEMVER_REGEX="v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?"
|
||||
|
||||
usage() {
|
||||
cat <<- EOF
|
||||
Usage: $PROGNAME [OPTIONS] SEMVER_TAG COMMIT_HASH
|
||||
|
||||
Creates git tag for all Go packages in project.
|
||||
|
||||
OPTIONS:
|
||||
-h --help Show this help.
|
||||
|
||||
ARGUMENTS:
|
||||
SEMVER_TAG Semantic version to tag with.
|
||||
COMMIT_HASH Git commit hash to tag.
|
||||
EOF
|
||||
}
|
||||
|
||||
cmdline() {
|
||||
local arg commit
|
||||
|
||||
for arg
|
||||
do
|
||||
local delim=""
|
||||
case "$arg" in
|
||||
# Translate long form options to short form.
|
||||
--help) args="${args}-h ";;
|
||||
# Pass through for everything else.
|
||||
*) [[ "${arg:0:1}" == "-" ]] || delim="\""
|
||||
args="${args}${delim}${arg}${delim} ";;
|
||||
esac
|
||||
done
|
||||
|
||||
# Reset and process short form options.
|
||||
eval set -- "$args"
|
||||
|
||||
while getopts "h" OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "unknown option: $OPTION"
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Positional arguments.
|
||||
shift $((OPTIND-1))
|
||||
readonly TAG="$1"
|
||||
if [ -z "$TAG" ]
|
||||
then
|
||||
echo "missing SEMVER_TAG"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! "$TAG" =~ $SEMVER_REGEX ]]
|
||||
then
|
||||
printf "invalid semantic version: %s\n" "$TAG"
|
||||
exit 2
|
||||
fi
|
||||
if [[ "$( git tag --list "$TAG" )" ]]
|
||||
then
|
||||
printf "tag already exists: %s\n" "$TAG"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
shift
|
||||
commit="$1"
|
||||
if [ -z "$commit" ]
|
||||
then
|
||||
echo "missing COMMIT_HASH"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
# Verify rev is for a commit and unify hashes into a complete SHA1.
|
||||
readonly SHA="$( git rev-parse --quiet --verify "${commit}^{commit}" )"
|
||||
if [ -z "$SHA" ]
|
||||
then
|
||||
printf "invalid commit hash: %s\n" "$commit"
|
||||
exit 2
|
||||
fi
|
||||
if [ "$( git merge-base "$SHA" HEAD )" != "$SHA" ]
|
||||
then
|
||||
printf "commit '%s' not found on this branch\n" "$commit"
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
package_dirs() {
|
||||
# Return a list of package directories in the form:
|
||||
#
|
||||
# package/directory/a
|
||||
# package/directory/b
|
||||
# deeper/package/directory/a
|
||||
# ...
|
||||
#
|
||||
# Making sure to exclude any packages in the EXCLUDE_PACKAGES regexp.
|
||||
find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; \
|
||||
| grep -E -v "$EXCLUDE_PACKAGES" \
|
||||
| sed 's/^\.\///' \
|
||||
| sort
|
||||
}
|
||||
|
||||
git_tag() {
|
||||
local tag="$1"
|
||||
local commit="$2"
|
||||
|
||||
git tag -a "$tag" -s -m "Version $tag" "$commit"
|
||||
}
|
||||
|
||||
previous_version() {
|
||||
local current="$1"
|
||||
|
||||
# Requires git > 2.0
|
||||
git tag -l --sort=v:refname \
|
||||
| grep -E "^${SEMVER_REGEX}$" \
|
||||
| grep -v "$current" \
|
||||
| tail -1
|
||||
}
|
||||
|
||||
print_changes() {
|
||||
local tag="$1"
|
||||
local previous
|
||||
|
||||
previous="$( previous_version "$tag" )"
|
||||
if [ -n "$previous" ]
|
||||
then
|
||||
printf "\nRaw changes made between %s and %s\n" "$previous" "$tag"
|
||||
printf "======================================\n"
|
||||
git --no-pager log --pretty=oneline "${previous}..$tag"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local dir
|
||||
|
||||
cmdline "$@"
|
||||
|
||||
cd "$PROGDIR" || exit 3
|
||||
|
||||
# Create tag for root package.
|
||||
git_tag "$TAG" "$SHA"
|
||||
printf "created tag: %s\n" "$TAG"
|
||||
|
||||
# Create tag for all sub-packages.
|
||||
for dir in $( package_dirs )
|
||||
do
|
||||
git_tag "${dir}/$TAG" "$SHA"
|
||||
printf "created tag: %s\n" "${dir}/$TAG"
|
||||
done
|
||||
|
||||
print_changes "$TAG"
|
||||
}
|
||||
main "$@"
|
19
vendor/go.opentelemetry.io/otel/.gitignore
generated
vendored
Normal file
19
vendor/go.opentelemetry.io/otel/.gitignore
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
.tools/
|
||||
.idea/
|
||||
.vscode/
|
||||
*.iml
|
||||
*.so
|
||||
coverage.*
|
||||
|
||||
gen/
|
||||
|
||||
/example/jaeger/jaeger
|
||||
/example/namedtracer/namedtracer
|
||||
/example/opencensus/opencensus
|
||||
/example/prometheus/prometheus
|
||||
/example/prom-collector/prom-collector
|
||||
/example/zipkin/zipkin
|
||||
/example/otel-collector/otel-collector
|
3
vendor/go.opentelemetry.io/otel/.gitmodules
generated
vendored
Normal file
3
vendor/go.opentelemetry.io/otel/.gitmodules
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "opentelemetry-proto"]
|
||||
path = exporters/otlp/internal/opentelemetry-proto
|
||||
url = https://github.com/open-telemetry/opentelemetry-proto
|
32
vendor/go.opentelemetry.io/otel/.golangci.yml
generated
vendored
Normal file
32
vendor/go.opentelemetry.io/otel/.golangci.yml
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
# See https://github.com/golangci/golangci-lint#config-file
|
||||
run:
|
||||
issues-exit-code: 1 #Default
|
||||
tests: true #Default
|
||||
|
||||
linters:
|
||||
enable:
|
||||
- misspell
|
||||
- goimports
|
||||
- golint
|
||||
- gofmt
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
# helpers in tests often (rightfully) pass a *testing.T as their first argument
|
||||
- path: _test\.go
|
||||
text: "context.Context should be the first parameter of a function"
|
||||
linters:
|
||||
- golint
|
||||
# Yes, they are, but it's okay in a test
|
||||
- path: _test\.go
|
||||
text: "exported func.*returns unexported type.*which can be annoying to use"
|
||||
linters:
|
||||
- golint
|
||||
|
||||
linters-settings:
|
||||
misspell:
|
||||
locale: US
|
||||
ignore-words:
|
||||
- cancelled
|
||||
goimports:
|
||||
local-prefixes: go.opentelemetry.io
|
1319
vendor/go.opentelemetry.io/otel/CHANGELOG.md
generated
vendored
Normal file
1319
vendor/go.opentelemetry.io/otel/CHANGELOG.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
17
vendor/go.opentelemetry.io/otel/CODEOWNERS
generated
vendored
Normal file
17
vendor/go.opentelemetry.io/otel/CODEOWNERS
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
#####################################################
|
||||
#
|
||||
# List of approvers for this repository
|
||||
#
|
||||
#####################################################
|
||||
#
|
||||
# Learn about membership in OpenTelemetry community:
|
||||
# https://github.com/open-telemetry/community/blob/main/community-membership.md
|
||||
#
|
||||
#
|
||||
# Learn about CODEOWNERS file format:
|
||||
# https://help.github.com/en/articles/about-code-owners
|
||||
#
|
||||
|
||||
* @jmacd @MrAlias @Aneurysm9 @evantorrie @XSAM @dashpole @paivagustavo
|
||||
|
||||
CODEOWNERS @MrAlias @Aneurysm9
|
380
vendor/go.opentelemetry.io/otel/CONTRIBUTING.md
generated
vendored
Normal file
380
vendor/go.opentelemetry.io/otel/CONTRIBUTING.md
generated
vendored
Normal file
@ -0,0 +1,380 @@
|
||||
# Contributing to opentelemetry-go
|
||||
|
||||
The Go special interest group (SIG) meets regularly. See the
|
||||
OpenTelemetry
|
||||
[community](https://github.com/open-telemetry/community#golang-sdk)
|
||||
repo for information on this and other language SIGs.
|
||||
|
||||
See the [public meeting
|
||||
notes](https://docs.google.com/document/d/1A63zSWX0x2CyCK_LoNhmQC4rqhLpYXJzXbEPDUQ2n6w/edit#heading=h.9tngw7jdwd6b)
|
||||
for a summary description of past meetings. To request edit access,
|
||||
join the meeting or get in touch on
|
||||
[Slack](https://cloud-native.slack.com/archives/C01NPAXACKT).
|
||||
|
||||
## Development
|
||||
|
||||
You can view and edit the source code by cloning this repository:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/open-telemetry/opentelemetry-go.git
|
||||
```
|
||||
|
||||
Run `make test` to run the tests instead of `go test`.
|
||||
|
||||
There are some generated files checked into the repo. To make sure
|
||||
that the generated files are up-to-date, run `make` (or `make
|
||||
precommit` - the `precommit` target is the default).
|
||||
|
||||
The `precommit` target also fixes the formatting of the code and
|
||||
checks the status of the go module files.
|
||||
|
||||
If after running `make precommit` the output of `git status` contains
|
||||
`nothing to commit, working tree clean` then it means that everything
|
||||
is up-to-date and properly formatted.
|
||||
|
||||
## Pull Requests
|
||||
|
||||
### How to Send Pull Requests
|
||||
|
||||
Everyone is welcome to contribute code to `opentelemetry-go` via
|
||||
GitHub pull requests (PRs).
|
||||
|
||||
To create a new PR, fork the project in GitHub and clone the upstream
|
||||
repo:
|
||||
|
||||
```sh
|
||||
$ go get -d go.opentelemetry.io/otel
|
||||
```
|
||||
|
||||
(This may print some warning about "build constraints exclude all Go
|
||||
files", just ignore it.)
|
||||
|
||||
This will put the project in `${GOPATH}/src/go.opentelemetry.io/otel`. You
|
||||
can alternatively use `git` directly with:
|
||||
|
||||
```sh
|
||||
$ git clone https://github.com/open-telemetry/opentelemetry-go
|
||||
```
|
||||
|
||||
(Note that `git clone` is *not* using the `go.opentelemetry.io/otel` name -
|
||||
that name is a kind of a redirector to GitHub that `go get` can
|
||||
understand, but `git` does not.)
|
||||
|
||||
This would put the project in the `opentelemetry-go` directory in
|
||||
current working directory.
|
||||
|
||||
Enter the newly created directory and add your fork as a new remote:
|
||||
|
||||
```sh
|
||||
$ git remote add <YOUR_FORK> git@github.com:<YOUR_GITHUB_USERNAME>/opentelemetry-go
|
||||
```
|
||||
|
||||
Check out a new branch, make modifications, run linters and tests, update
|
||||
`CHANGELOG.md`, and push the branch to your fork:
|
||||
|
||||
```sh
|
||||
$ git checkout -b <YOUR_BRANCH_NAME>
|
||||
# edit files
|
||||
# update changelog
|
||||
$ make precommit
|
||||
$ git add -p
|
||||
$ git commit
|
||||
$ git push <YOUR_FORK> <YOUR_BRANCH_NAME>
|
||||
```
|
||||
|
||||
Open a pull request against the main `opentelemetry-go` repo. Be sure to add the pull
|
||||
request ID to the entry you added to `CHANGELOG.md`.
|
||||
|
||||
### How to Receive Comments
|
||||
|
||||
* If the PR is not ready for review, please put `[WIP]` in the title,
|
||||
tag it as `work-in-progress`, or mark it as
|
||||
[`draft`](https://github.blog/2019-02-14-introducing-draft-pull-requests/).
|
||||
* Make sure CLA is signed and CI is clear.
|
||||
|
||||
### How to Get PRs Merged
|
||||
|
||||
A PR is considered to be **ready to merge** when:
|
||||
|
||||
* It has received two approvals from Collaborators/Maintainers (at
|
||||
different companies). This is not enforced through technical means
|
||||
and a PR may be **ready to merge** with a single approval if the change
|
||||
and its approach have been discussed and consensus reached.
|
||||
* Feedback has been addressed.
|
||||
* Any substantive changes to your PR will require that you clear any prior
|
||||
Approval reviews, this includes changes resulting from other feedback. Unless
|
||||
the approver explicitly stated that their approval will persist across
|
||||
changes it should be assumed that the PR needs their review again. Other
|
||||
project members (e.g. approvers, maintainers) can help with this if there are
|
||||
any questions or if you forget to clear reviews.
|
||||
* It has been open for review for at least one working day. This gives
|
||||
people reasonable time to review.
|
||||
* Trivial changes (typo, cosmetic, doc, etc.) do not have to wait for
|
||||
one day and may be merged with a single Maintainer's approval.
|
||||
* `CHANGELOG.md` has been updated to reflect what has been
|
||||
added, changed, removed, or fixed.
|
||||
* Urgent fix can take exception as long as it has been actively
|
||||
communicated.
|
||||
|
||||
Any Maintainer can merge the PR once it is **ready to merge**.
|
||||
|
||||
## Design Choices
|
||||
|
||||
As with other OpenTelemetry clients, opentelemetry-go follows the
|
||||
[opentelemetry-specification](https://github.com/open-telemetry/opentelemetry-specification).
|
||||
|
||||
It's especially valuable to read through the [library
|
||||
guidelines](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/library-guidelines.md).
|
||||
|
||||
### Focus on Capabilities, Not Structure Compliance
|
||||
|
||||
OpenTelemetry is an evolving specification, one where the desires and
|
||||
use cases are clear, but the method to satisfy those uses cases are
|
||||
not.
|
||||
|
||||
As such, Contributions should provide functionality and behavior that
|
||||
conforms to the specification, but the interface and structure is
|
||||
flexible.
|
||||
|
||||
It is preferable to have contributions follow the idioms of the
|
||||
language rather than conform to specific API names or argument
|
||||
patterns in the spec.
|
||||
|
||||
For a deeper discussion, see:
|
||||
https://github.com/open-telemetry/opentelemetry-specification/issues/165
|
||||
|
||||
## Style Guide
|
||||
|
||||
One of the primary goals of this project is that it is actually used by
|
||||
developers. With this goal in mind the project strives to build
|
||||
user-friendly and idiomatic Go code adhering to the Go community's best
|
||||
practices.
|
||||
|
||||
For a non-comprehensive but foundational overview of these best practices
|
||||
the [Effective Go](https://golang.org/doc/effective_go.html) documentation
|
||||
is an excellent starting place.
|
||||
|
||||
As a convenience for developers building this project the `make precommit`
|
||||
will format, lint, validate, and in some cases fix the changes you plan to
|
||||
submit. This check will need to pass for your changes to be able to be
|
||||
merged.
|
||||
|
||||
In addition to idiomatic Go, the project has adopted certain standards for
|
||||
implementations of common patterns. These standards should be followed as a
|
||||
default, and if they are not followed documentation needs to be included as
|
||||
to the reasons why.
|
||||
|
||||
### Configuration
|
||||
|
||||
When creating an instantiation function for a complex `struct` it is useful
|
||||
to allow variable number of options to be applied. However, the strong type
|
||||
system of Go restricts the function design options. There are a few ways to
|
||||
solve this problem, but we have landed on the following design.
|
||||
|
||||
#### `config`
|
||||
|
||||
Configuration should be held in a `struct` named `config`, or prefixed with
|
||||
specific type name this Configuration applies to if there are multiple
|
||||
`config` in the package. This `struct` must contain configuration options.
|
||||
|
||||
```go
|
||||
// config contains configuration options for a thing.
|
||||
type config struct {
|
||||
// options ...
|
||||
}
|
||||
```
|
||||
|
||||
In general the `config` `struct` will not need to be used externally to the
|
||||
package and should be unexported. If, however, it is expected that the user
|
||||
will likely want to build custom options for the configuration, the `config`
|
||||
should be exported. Please, include in the documentation for the `config`
|
||||
how the user can extend the configuration.
|
||||
|
||||
It is important that `config` are not shared across package boundaries.
|
||||
Meaning a `config` from one package should not be directly used by another.
|
||||
|
||||
Optionally, it is common to include a `newConfig` function (with the same
|
||||
naming scheme). This function wraps any defaults setting and looping over
|
||||
all options to create a configured `config`.
|
||||
|
||||
```go
|
||||
// newConfig returns an appropriately configured config.
|
||||
func newConfig([]Option) config {
|
||||
// Set default values for config.
|
||||
config := config{/* […] */}
|
||||
for _, option := range options {
|
||||
option.Apply(&config)
|
||||
}
|
||||
// Preform any validation here.
|
||||
return config
|
||||
}
|
||||
```
|
||||
|
||||
If validation of the `config` options is also preformed this can return an
|
||||
error as well that is expected to be handled by the instantiation function
|
||||
or propagated to the user.
|
||||
|
||||
Given the design goal of not having the user need to work with the `config`,
|
||||
the `newConfig` function should also be unexported.
|
||||
|
||||
#### `Option`
|
||||
|
||||
To set the value of the options a `config` contains, a corresponding
|
||||
`Option` interface type should be used.
|
||||
|
||||
```go
|
||||
type Option interface {
|
||||
Apply(*config)
|
||||
}
|
||||
```
|
||||
|
||||
The name of the interface should be prefixed in the same way the
|
||||
corresponding `config` is (if at all).
|
||||
|
||||
#### Options
|
||||
|
||||
All user configurable options for a `config` must have a related unexported
|
||||
implementation of the `Option` interface and an exported configuration
|
||||
function that wraps this implementation.
|
||||
|
||||
The wrapping function name should be prefixed with `With*` (or in the
|
||||
special case of a boolean options `Without*`) and should have the following
|
||||
function signature.
|
||||
|
||||
```go
|
||||
func With*(…) Option { … }
|
||||
```
|
||||
|
||||
##### `bool` Options
|
||||
|
||||
```go
|
||||
type defaultFalseOption bool
|
||||
|
||||
func (o defaultFalseOption) Apply(c *config) {
|
||||
c.Bool = bool(o)
|
||||
}
|
||||
|
||||
// WithOption sets a T* to have an option included.
|
||||
func WithOption() Option {
|
||||
return defaultFalseOption(true)
|
||||
}
|
||||
```
|
||||
|
||||
```go
|
||||
type defaultTrueOption bool
|
||||
|
||||
func (o defaultTrueOption) Apply(c *config) {
|
||||
c.Bool = bool(o)
|
||||
}
|
||||
|
||||
// WithoutOption sets a T* to have Bool option excluded.
|
||||
func WithoutOption() Option {
|
||||
return defaultTrueOption(false)
|
||||
}
|
||||
````
|
||||
|
||||
##### Declared Type Options
|
||||
|
||||
```go
|
||||
type myTypeOption struct {
|
||||
MyType MyType
|
||||
}
|
||||
|
||||
func (o myTypeOption) Apply(c *config) {
|
||||
c.MyType = o.MyType
|
||||
}
|
||||
|
||||
// WithMyType sets T* to have include MyType.
|
||||
func WithMyType(t MyType) Option {
|
||||
return myTypeOption{t}
|
||||
}
|
||||
```
|
||||
|
||||
#### Instantiation
|
||||
|
||||
Using this configuration pattern to configure instantiation with a `New*`
|
||||
function.
|
||||
|
||||
```go
|
||||
func NewT*(options ...Option) T* {…}
|
||||
```
|
||||
|
||||
Any required parameters can be declared before the variadic `options`.
|
||||
|
||||
#### Dealing with Overlap
|
||||
|
||||
Sometimes there are multiple complex `struct` that share common
|
||||
configuration and also have distinct configuration. To avoid repeated
|
||||
portions of `config`s, a common `config` can be used with the union of
|
||||
options being handled with the `Option` interface.
|
||||
|
||||
For example.
|
||||
|
||||
```go
|
||||
// config holds options for all animals.
|
||||
type config struct {
|
||||
Weight float64
|
||||
Color string
|
||||
MaxAltitude float64
|
||||
}
|
||||
|
||||
// DogOption apply Dog specific options.
|
||||
type DogOption interface {
|
||||
ApplyDog(*config)
|
||||
}
|
||||
|
||||
// BirdOption apply Bird specific options.
|
||||
type BirdOption interface {
|
||||
ApplyBird(*config)
|
||||
}
|
||||
|
||||
// Option apply options for all animals.
|
||||
type Option interface {
|
||||
BirdOption
|
||||
DogOption
|
||||
}
|
||||
|
||||
type weightOption float64
|
||||
func (o weightOption) ApplyDog(c *config) { c.Weight = float64(o) }
|
||||
func (o weightOption) ApplyBird(c *config) { c.Weight = float64(o) }
|
||||
func WithWeight(w float64) Option { return weightOption(w) }
|
||||
|
||||
type furColorOption string
|
||||
func (o furColorOption) ApplyDog(c *config) { c.Color = string(o) }
|
||||
func WithFurColor(c string) DogOption { return furColorOption(c) }
|
||||
|
||||
type maxAltitudeOption float64
|
||||
func (o maxAltitudeOption) ApplyBird(c *config) { c.MaxAltitude = float64(o) }
|
||||
func WithMaxAltitude(a float64) BirdOption { return maxAltitudeOption(a) }
|
||||
|
||||
func NewDog(name string, o ...DogOption) Dog {…}
|
||||
func NewBird(name string, o ...BirdOption) Bird {…}
|
||||
```
|
||||
|
||||
### Interface Type
|
||||
|
||||
To allow other developers to better comprehend the code, it is important
|
||||
to ensure it is sufficiently documented. One simple measure that contributes
|
||||
to this aim is self-documenting by naming method parameters. Therefore,
|
||||
where appropriate, methods of every exported interface type should have
|
||||
their parameters appropriately named.
|
||||
|
||||
## Approvers and Maintainers
|
||||
|
||||
Approvers:
|
||||
|
||||
- [Evan Torrie](https://github.com/evantorrie), Verizon Media
|
||||
- [Josh MacDonald](https://github.com/jmacd), LightStep
|
||||
- [Sam Xie](https://github.com/XSAM)
|
||||
- [David Ashpole](https://github.com/dashpole), Google
|
||||
- [Gustavo Silva Paiva](https://github.com/paivagustavo), LightStep
|
||||
|
||||
Maintainers:
|
||||
|
||||
- [Anthony Mirabella](https://github.com/Aneurysm9), AWS
|
||||
- [Tyler Yahn](https://github.com/MrAlias), Splunk
|
||||
|
||||
### Become an Approver or a Maintainer
|
||||
|
||||
See the [community membership document in OpenTelemetry community
|
||||
repo](https://github.com/open-telemetry/community/blob/main/community-membership.md).
|
201
vendor/go.opentelemetry.io/otel/LICENSE
generated
vendored
Normal file
201
vendor/go.opentelemetry.io/otel/LICENSE
generated
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
179
vendor/go.opentelemetry.io/otel/Makefile
generated
vendored
Normal file
179
vendor/go.opentelemetry.io/otel/Makefile
generated
vendored
Normal file
@ -0,0 +1,179 @@
|
||||
# Copyright The OpenTelemetry Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
EXAMPLES := $(shell ./get_main_pkgs.sh ./example)
|
||||
TOOLS_MOD_DIR := ./internal/tools
|
||||
|
||||
# All source code and documents. Used in spell check.
|
||||
ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
|
||||
# All directories with go.mod files related to opentelemetry library. Used for building, testing and linting.
|
||||
ALL_GO_MOD_DIRS := $(filter-out $(TOOLS_MOD_DIR), $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./example' | sort)) $(shell find ./example -type f -name 'go.mod' -exec dirname {} \; | sort)
|
||||
ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./example|^$(TOOLS_MOD_DIR)' | sort)
|
||||
|
||||
GO = go
|
||||
TIMEOUT = 60
|
||||
|
||||
.DEFAULT_GOAL := precommit
|
||||
|
||||
.PHONY: precommit ci
|
||||
precommit: dependabot-check license-check lint build examples test-default
|
||||
ci: precommit check-clean-work-tree test-coverage
|
||||
|
||||
# Tools
|
||||
|
||||
TOOLS = $(CURDIR)/.tools
|
||||
|
||||
$(TOOLS):
|
||||
@mkdir -p $@
|
||||
$(TOOLS)/%: | $(TOOLS)
|
||||
cd $(TOOLS_MOD_DIR) && \
|
||||
$(GO) build -o $@ $(PACKAGE)
|
||||
|
||||
CROSSLINK = $(TOOLS)/crosslink
|
||||
$(TOOLS)/crosslink: PACKAGE=go.opentelemetry.io/otel/$(TOOLS_MOD_DIR)/crosslink
|
||||
|
||||
GOLANGCI_LINT = $(TOOLS)/golangci-lint
|
||||
$(TOOLS)/golangci-lint: PACKAGE=github.com/golangci/golangci-lint/cmd/golangci-lint
|
||||
|
||||
MISSPELL = $(TOOLS)/misspell
|
||||
$(TOOLS)/misspell: PACKAGE= github.com/client9/misspell/cmd/misspell
|
||||
|
||||
STRINGER = $(TOOLS)/stringer
|
||||
$(TOOLS)/stringer: PACKAGE=golang.org/x/tools/cmd/stringer
|
||||
|
||||
$(TOOLS)/gojq: PACKAGE=github.com/itchyny/gojq/cmd/gojq
|
||||
|
||||
.PHONY: tools
|
||||
tools: $(CROSSLINK) $(GOLANGCI_LINT) $(MISSPELL) $(STRINGER) $(TOOLS)/gojq
|
||||
|
||||
|
||||
# Build
|
||||
|
||||
.PHONY: examples generate build
|
||||
examples:
|
||||
@set -e; for dir in $(EXAMPLES); do \
|
||||
echo "$(GO) build $${dir}/..."; \
|
||||
(cd "$${dir}" && \
|
||||
$(GO) build .); \
|
||||
done
|
||||
|
||||
generate: $(STRINGER)
|
||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||
echo "$(GO) generate $${dir}/..."; \
|
||||
(cd "$${dir}" && \
|
||||
PATH="$(TOOLS):$${PATH}" $(GO) generate ./...); \
|
||||
done
|
||||
|
||||
build: generate
|
||||
# Build all package code including testing code.
|
||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||
echo "$(GO) build $${dir}/..."; \
|
||||
(cd "$${dir}" && \
|
||||
$(GO) build ./... && \
|
||||
$(GO) list ./... \
|
||||
| grep -v third_party \
|
||||
| xargs $(GO) test -vet=off -run xxxxxMatchNothingxxxxx >/dev/null); \
|
||||
done
|
||||
|
||||
# Tests
|
||||
|
||||
TEST_TARGETS := test-default test-bench test-short test-verbose test-race
|
||||
.PHONY: $(TEST_TARGETS) test
|
||||
test-default: ARGS=-v -race
|
||||
test-bench: ARGS=-run=xxxxxMatchNothingxxxxx -test.benchtime=1ms -bench=.
|
||||
test-short: ARGS=-short
|
||||
test-verbose: ARGS=-v
|
||||
test-race: ARGS=-race
|
||||
$(TEST_TARGETS): test
|
||||
test:
|
||||
@set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||
echo "$(GO) test -timeout $(TIMEOUT)s $(ARGS) $${dir}/..."; \
|
||||
(cd "$${dir}" && \
|
||||
$(GO) list ./... \
|
||||
| grep -v third_party \
|
||||
| xargs $(GO) test -timeout $(TIMEOUT)s $(ARGS)); \
|
||||
done
|
||||
|
||||
COVERAGE_MODE = atomic
|
||||
COVERAGE_PROFILE = coverage.out
|
||||
.PHONY: test-coverage
|
||||
test-coverage:
|
||||
@set -e; \
|
||||
printf "" > coverage.txt; \
|
||||
for dir in $(ALL_COVERAGE_MOD_DIRS); do \
|
||||
echo "$(GO) test -coverpkg=./... -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_PROFILE)" $${dir}/..."; \
|
||||
(cd "$${dir}" && \
|
||||
$(GO) list ./... \
|
||||
| grep -v third_party \
|
||||
| xargs $(GO) test -coverpkg=./... -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_PROFILE)" && \
|
||||
$(GO) tool cover -html=coverage.out -o coverage.html); \
|
||||
[ -f "$${dir}/coverage.out" ] && cat "$${dir}/coverage.out" >> coverage.txt; \
|
||||
done; \
|
||||
sed -i.bak -e '2,$$ { /^mode: /d; }' coverage.txt
|
||||
|
||||
.PHONY: lint
|
||||
lint: misspell lint-modules | $(GOLANGCI_LINT)
|
||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||
echo "golangci-lint in $${dir}"; \
|
||||
(cd "$${dir}" && \
|
||||
$(GOLANGCI_LINT) run --fix && \
|
||||
$(GOLANGCI_LINT) run); \
|
||||
done
|
||||
|
||||
.PHONY: misspell
|
||||
misspell: | $(MISSPELL)
|
||||
$(MISSPELL) -w $(ALL_DOCS)
|
||||
|
||||
.PHONY: lint-modules
|
||||
lint-modules: | $(CROSSLINK)
|
||||
set -e; for dir in $(ALL_GO_MOD_DIRS) $(TOOLS_MOD_DIR); do \
|
||||
echo "$(GO) mod tidy in $${dir}"; \
|
||||
(cd "$${dir}" && \
|
||||
$(GO) mod tidy); \
|
||||
done
|
||||
echo "cross-linking all go modules"
|
||||
$(CROSSLINK)
|
||||
|
||||
.PHONY: license-check
|
||||
license-check:
|
||||
@licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path '**/third_party/*' ! -path './exporters/otlp/internal/opentelemetry-proto/*') ; do \
|
||||
awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=3 { found=1; next } END { if (!found) print FILENAME }' $$f; \
|
||||
done); \
|
||||
if [ -n "$${licRes}" ]; then \
|
||||
echo "license header checking failed:"; echo "$${licRes}"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
.PHONY: dependabot-check
|
||||
dependabot-check:
|
||||
@result=$$( \
|
||||
for f in $$( find . -type f -name go.mod -exec dirname {} \; | sed 's/^.\/\?/\//' ); \
|
||||
do grep -q "$$f" .github/dependabot.yml \
|
||||
|| echo "$$f"; \
|
||||
done; \
|
||||
); \
|
||||
if [ -n "$$result" ]; then \
|
||||
echo "missing go.mod dependabot check:"; echo "$$result"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
.PHONY: check-clean-work-tree
|
||||
check-clean-work-tree:
|
||||
@if ! git diff --quiet; then \
|
||||
echo; \
|
||||
echo 'Working tree is not clean, did you forget to run "make precommit"?'; \
|
||||
echo; \
|
||||
git status; \
|
||||
exit 1; \
|
||||
fi
|
92
vendor/go.opentelemetry.io/otel/README.md
generated
vendored
Normal file
92
vendor/go.opentelemetry.io/otel/README.md
generated
vendored
Normal file
@ -0,0 +1,92 @@
|
||||
# OpenTelemetry-Go
|
||||
|
||||
[](https://github.com/open-telemetry/opentelemetry-go/actions?query=workflow%3Aci+branch%3Amain)
|
||||
[](https://pkg.go.dev/go.opentelemetry.io/otel)
|
||||
[](https://goreportcard.com/report/go.opentelemetry.io/otel)
|
||||
[](https://cloud-native.slack.com/archives/C01NPAXACKT)
|
||||
|
||||
|
||||
The Go [OpenTelemetry](https://opentelemetry.io/) implementation.
|
||||
|
||||
## Project Status
|
||||
|
||||
**Warning**: this project is currently in a pre-GA phase. Backwards
|
||||
incompatible changes may be introduced in subsequent minor version releases as
|
||||
we work to track the evolving OpenTelemetry specification and user feedback.
|
||||
|
||||
Our progress towards a GA release candidate is tracked in [this project
|
||||
board](https://github.com/orgs/open-telemetry/projects/5). This release
|
||||
candidate will follow semantic versioning and will be released with a major
|
||||
version greater than zero.
|
||||
|
||||
Progress and status specific to this repository is tracked in our local
|
||||
[project boards](https://github.com/open-telemetry/opentelemetry-go/projects)
|
||||
and
|
||||
[milestones](https://github.com/open-telemetry/opentelemetry-go/milestones).
|
||||
|
||||
Project versioning information and stability guarantees can be found in the
|
||||
[versioning documentation](./VERSIONING.md).
|
||||
|
||||
### Compatibility
|
||||
|
||||
This project is tested on the following systems.
|
||||
|
||||
| OS | Go Version | Architecture |
|
||||
| ------- | ---------- | ------------ |
|
||||
| Ubuntu | 1.15 | amd64 |
|
||||
| Ubuntu | 1.14 | amd64 |
|
||||
| Ubuntu | 1.15 | 386 |
|
||||
| Ubuntu | 1.14 | 386 |
|
||||
| MacOS | 1.15 | amd64 |
|
||||
| MacOS | 1.14 | amd64 |
|
||||
| Windows | 1.15 | amd64 |
|
||||
| Windows | 1.14 | amd64 |
|
||||
| Windows | 1.15 | 386 |
|
||||
| Windows | 1.14 | 386 |
|
||||
|
||||
While this project should work for other systems, no compatibility guarantees
|
||||
are made for those systems currently.
|
||||
|
||||
## Getting Started
|
||||
|
||||
You can find a getting started guide on [opentelemetry.io](https://opentelemetry.io/docs/go/getting-started/).
|
||||
|
||||
OpenTelemetry's goal is to provide a single set of APIs to capture distributed
|
||||
traces and metrics from your application and send them to an observability
|
||||
platform. This project allows you to do just that for applications written in
|
||||
Go. There are two steps to this process: instrument your application, and
|
||||
configure an exporter.
|
||||
|
||||
### Instrumentation
|
||||
|
||||
To start capturing distributed traces and metric events from your application
|
||||
it first needs to be instrumented. The easiest way to do this is by using an
|
||||
instrumentation library for your code. Be sure to check out [the officially
|
||||
supported instrumentation
|
||||
libraries](https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/instrumentation).
|
||||
|
||||
If you need to extend the telemetry an instrumentation library provides or want
|
||||
to build your own instrumentation for your application directly you will need
|
||||
to use the
|
||||
[go.opentelemetry.io/otel/api](https://pkg.go.dev/go.opentelemetry.io/otel/api)
|
||||
package. The included [examples](./example/) are a good way to see some
|
||||
practical uses of this process.
|
||||
|
||||
### Export
|
||||
|
||||
Now that your application is instrumented to collect telemetry, it needs an
|
||||
export pipeline to send that telemetry to an observability platform.
|
||||
|
||||
You can find officially supported exporters [here](./exporters/) and in the
|
||||
companion [contrib
|
||||
repository](https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/exporters/metric).
|
||||
Additionally, there are many vendor specific or 3rd party exporters for
|
||||
OpenTelemetry. These exporters are broken down by
|
||||
[trace](https://pkg.go.dev/go.opentelemetry.io/otel/sdk/export/trace?tab=importedby)
|
||||
and
|
||||
[metric](https://pkg.go.dev/go.opentelemetry.io/otel/sdk/export/metric?tab=importedby)
|
||||
support.
|
||||
|
||||
## Contributing
|
||||
|
||||
See the [contributing documentation](CONTRIBUTING.md).
|
81
vendor/go.opentelemetry.io/otel/RELEASING.md
generated
vendored
Normal file
81
vendor/go.opentelemetry.io/otel/RELEASING.md
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
# Release Process
|
||||
|
||||
## Pre-Release
|
||||
|
||||
Update go.mod for submodules to depend on the new release which will happen in the next step.
|
||||
|
||||
1. Run the pre-release script. It creates a branch `pre_release_<new tag>` that will contain all release changes.
|
||||
|
||||
```
|
||||
./pre_release.sh -t <new tag>
|
||||
```
|
||||
|
||||
2. Verify the changes.
|
||||
|
||||
```
|
||||
git diff main
|
||||
```
|
||||
|
||||
This should have changed the version for all modules to be `<new tag>`.
|
||||
|
||||
3. Update the [Changelog](./CHANGELOG.md).
|
||||
- Make sure all relevant changes for this release are included and are in language that non-contributors to the project can understand.
|
||||
To verify this, you can look directly at the commits since the `<last tag>`.
|
||||
|
||||
```
|
||||
git --no-pager log --pretty=oneline "<last tag>..HEAD"
|
||||
```
|
||||
|
||||
- Move all the `Unreleased` changes into a new section following the title scheme (`[<new tag>] - <date of release>`).
|
||||
- Update all the appropriate links at the bottom.
|
||||
|
||||
4. Push the changes to upstream and create a Pull Request on GitHub.
|
||||
Be sure to include the curated changes from the [Changelog](./CHANGELOG.md) in the description.
|
||||
|
||||
|
||||
## Tag
|
||||
|
||||
Once the Pull Request with all the version changes has been approved and merged it is time to tag the merged commit.
|
||||
|
||||
***IMPORTANT***: It is critical you use the same tag that you used in the Pre-Release step!
|
||||
Failure to do so will leave things in a broken state.
|
||||
|
||||
***IMPORTANT***: [There is currently no way to remove an incorrectly tagged version of a Go module](https://github.com/golang/go/issues/34189).
|
||||
It is critical you make sure the version you push upstream is correct.
|
||||
[Failure to do so will lead to minor emergencies and tough to work around](https://github.com/open-telemetry/opentelemetry-go/issues/331).
|
||||
|
||||
1. Run the tag.sh script using the `<commit-hash>` of the commit on the main branch for the merged Pull Request.
|
||||
|
||||
```
|
||||
./tag.sh <new tag> <commit-hash>
|
||||
```
|
||||
|
||||
2. Push tags to the upstream remote (not your fork: `github.com/open-telemetry/opentelemetry-go.git`).
|
||||
Make sure you push all sub-modules as well.
|
||||
|
||||
```
|
||||
git push upstream <new tag>
|
||||
git push upstream <submodules-path/new tag>
|
||||
...
|
||||
```
|
||||
|
||||
## Release
|
||||
|
||||
Finally create a Release for the new `<new tag>` on GitHub.
|
||||
The release body should include all the release notes from the Changelog for this release.
|
||||
Additionally, the `tag.sh` script generates commit logs since last release which can be used to supplement the release notes.
|
||||
|
||||
## Verify Examples
|
||||
|
||||
After releasing verify that examples build outside of the repository.
|
||||
|
||||
```
|
||||
./verify_examples.sh
|
||||
```
|
||||
|
||||
The script copies examples into a different directory removes any `replace` declarations in `go.mod` and builds them.
|
||||
This ensures they build with the published release, not the local copy.
|
||||
|
||||
## Contrib Repository
|
||||
|
||||
Once verified be sure to [make a release for the `contrib` repository](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/RELEASING.md) that uses this release.
|
217
vendor/go.opentelemetry.io/otel/VERSIONING.md
generated
vendored
Normal file
217
vendor/go.opentelemetry.io/otel/VERSIONING.md
generated
vendored
Normal file
@ -0,0 +1,217 @@
|
||||
# Versioning
|
||||
|
||||
This document describes the versioning policy for this repository. This policy
|
||||
is designed so the following goals can be achieved.
|
||||
|
||||
**Users are provided a codebase of value that is stable and secure.**
|
||||
|
||||
## Policy
|
||||
|
||||
* Versioning of this project will be idiomatic of a Go project using [Go
|
||||
modules](https://github.com/golang/go/wiki/Modules).
|
||||
* [Semantic import
|
||||
versioning](https://github.com/golang/go/wiki/Modules#semantic-import-versioning)
|
||||
will be used.
|
||||
* Versions will comply with [semver 2.0](https://semver.org/spec/v2.0.0.html).
|
||||
* If a module is version `v2` or higher, the major version of the module
|
||||
must be included as a `/vN` at the end of the module paths used in
|
||||
`go.mod` files (e.g., `module go.opentelemetry.io/otel/v2`, `require
|
||||
go.opentelemetry.io/otel/v2 v2.0.1`) and in the package import path
|
||||
(e.g., `import "go.opentelemetry.io/otel/v2/trace"`). This includes the
|
||||
paths used in `go get` commands (e.g., `go get
|
||||
go.opentelemetry.io/otel/v2@v2.0.1`. Note there is both a `/v2` and a
|
||||
`@v2.0.1` in that example. One way to think about it is that the module
|
||||
name now includes the `/v2`, so include `/v2` whenever you are using the
|
||||
module name).
|
||||
* If a module is version `v0` or `v1`, do not include the major version in
|
||||
either the module path or the import path.
|
||||
* Modules will be used to encapsulate signals and components.
|
||||
* Experimental modules still under active development will be versioned at
|
||||
`v0` to imply the stability guarantee defined by
|
||||
[semver](https://semver.org/spec/v2.0.0.html#spec-item-4).
|
||||
|
||||
> Major version zero (0.y.z) is for initial development. Anything MAY
|
||||
> change at any time. The public API SHOULD NOT be considered stable.
|
||||
|
||||
* Mature modules for which we guarantee a stable public API will be versioned
|
||||
with a major version greater than `v0`.
|
||||
* The decision to make a module stable will be made on a case-by-case
|
||||
basis by the maintainers of this project.
|
||||
* Experimental modules will start their versioning at `v0.0.0` and will
|
||||
increment their minor version when backwards incompatible changes are
|
||||
released and increment their patch version when backwards compatible
|
||||
changes are released.
|
||||
* All stable modules that use the same major version number will use the
|
||||
same entire version number.
|
||||
* Stable modules may be released with an incremented minor or patch
|
||||
version even though that module has not been changed, but rather so
|
||||
that it will remain at the same version as other stable modules that
|
||||
did undergo change.
|
||||
* When an experimental module becomes stable a new stable module version
|
||||
will be released and will include this now stable module. The new
|
||||
stable module version will be an increment of the minor version number
|
||||
and will be applied to all existing stable modules as well as the newly
|
||||
stable module being released.
|
||||
* Versioning of the associated [contrib
|
||||
repository](https://github.com/open-telemetry/opentelemetry-go-contrib) of
|
||||
this project will be idiomatic of a Go project using [Go
|
||||
modules](https://github.com/golang/go/wiki/Modules).
|
||||
* [Semantic import
|
||||
versioning](https://github.com/golang/go/wiki/Modules#semantic-import-versioning)
|
||||
will be used.
|
||||
* Versions will comply with [semver 2.0](https://semver.org/spec/v2.0.0.html).
|
||||
* If a module is version `v2` or higher, the
|
||||
major version of the module must be included as a `/vN` at the end of the
|
||||
module paths used in `go.mod` files (e.g., `module
|
||||
go.opentelemetry.io/contrib/instrumentation/host/v2`, `require
|
||||
go.opentelemetry.io/contrib/instrumentation/host/v2 v2.0.1`) and in the
|
||||
package import path (e.g., `import
|
||||
"go.opentelemetry.io/contrib/instrumentation/host/v2"`). This includes
|
||||
the paths used in `go get` commands (e.g., `go get
|
||||
go.opentelemetry.io/contrib/instrumentation/host/v2@v2.0.1`. Note there
|
||||
is both a `/v2` and a `@v2.0.1` in that example. One way to think about
|
||||
it is that the module name now includes the `/v2`, so include `/v2`
|
||||
whenever you are using the module name).
|
||||
* If a module is version `v0` or `v1`, do not include the major version
|
||||
in either the module path or the import path.
|
||||
* In addition to public APIs, telemetry produced by stable instrumentation
|
||||
will remain stable and backwards compatible. This is to avoid breaking
|
||||
alerts and dashboard.
|
||||
* Modules will be used to encapsulate instrumentation, detectors, exporters,
|
||||
propagators, and any other independent sets of related components.
|
||||
* Experimental modules still under active development will be versioned at
|
||||
`v0` to imply the stability guarantee defined by
|
||||
[semver](https://semver.org/spec/v2.0.0.html#spec-item-4).
|
||||
|
||||
> Major version zero (0.y.z) is for initial development. Anything MAY
|
||||
> change at any time. The public API SHOULD NOT be considered stable.
|
||||
|
||||
* Mature modules for which we guarantee a stable public API and telemetry will
|
||||
be versioned with a major version greater than `v0`.
|
||||
* Experimental modules will start their versioning at `v0.0.0` and will
|
||||
increment their minor version when backwards incompatible changes are
|
||||
released and increment their patch version when backwards compatible
|
||||
changes are released.
|
||||
* Stable contrib modules cannot depend on experimental modules from this
|
||||
project.
|
||||
* All stable contrib modules of the same major version with this project
|
||||
will use the same entire version as this project.
|
||||
* Stable modules may be released with an incremented minor or patch
|
||||
version even though that module's code has not been changed. Instead
|
||||
the only change that will have been included is to have updated that
|
||||
modules dependency on this project's stable APIs.
|
||||
* When an experimental module in contrib becomes stable a new stable
|
||||
module version will be released and will include this now stable
|
||||
module. The new stable module version will be an increment of the minor
|
||||
version number and will be applied to all existing stable contrib
|
||||
modules, this project's modules, and the newly stable module being
|
||||
released.
|
||||
* Contrib modules will be kept up to date with this project's releases.
|
||||
* Due to the dependency contrib modules will implicitly have on this
|
||||
project's modules the release of stable contrib modules to match the
|
||||
released version number will be staggered after this project's release.
|
||||
There is no explicit time guarantee for how long after this projects
|
||||
release the contrib release will be. Effort should be made to keep them
|
||||
as close in time as possible.
|
||||
* No additional stable release in this project can be made until the
|
||||
contrib repository has a matching stable release.
|
||||
* No release can be made in the contrib repository after this project's
|
||||
stable release except for a stable release of the contrib repository.
|
||||
* GitHub releases will be made for all releases.
|
||||
* Go modules will be made available at Go package mirrors.
|
||||
|
||||
## Example Versioning Lifecycle
|
||||
|
||||
To better understand the implementation of the above policy the following
|
||||
example is provided. This project is simplified to include only the following
|
||||
modules and their versions:
|
||||
|
||||
* `otel`: `v0.14.0`
|
||||
* `otel/trace`: `v0.14.0`
|
||||
* `otel/metric`: `v0.14.0`
|
||||
* `otel/baggage`: `v0.14.0`
|
||||
* `otel/sdk/trace`: `v0.14.0`
|
||||
* `otel/sdk/metric`: `v0.14.0`
|
||||
|
||||
These modules have been developed to a point where the `otel/trace`,
|
||||
`otel/baggage`, and `otel/sdk/trace` modules have reached a point that they
|
||||
should be considered for a stable release. The `otel/metric` and
|
||||
`otel/sdk/metric` are still under active development and the `otel` module
|
||||
depends on both `otel/trace` and `otel/metric`.
|
||||
|
||||
The `otel` package is refactored to remove its dependencies on `otel/metric` so
|
||||
it can be released as stable as well. With that done the following release
|
||||
candidates are made:
|
||||
|
||||
* `otel`: `v1.0.0-rc.1`
|
||||
* `otel/trace`: `v1.0.0-rc.1`
|
||||
* `otel/baggage`: `v1.0.0-rc.1`
|
||||
* `otel/sdk/trace`: `v1.0.0-rc.1`
|
||||
|
||||
The `otel/metric` and `otel/sdk/metric` modules remain at `v0.14.0`.
|
||||
|
||||
A few minor issues are discovered in the `otel/trace` package. These issues are
|
||||
resolved with some minor, but backwards incompatible, changes and are released
|
||||
as a second release candidate:
|
||||
|
||||
* `otel`: `v1.0.0-rc.2`
|
||||
* `otel/trace`: `v1.0.0-rc.2`
|
||||
* `otel/baggage`: `v1.0.0-rc.2`
|
||||
* `otel/sdk/trace`: `v1.0.0-rc.2`
|
||||
|
||||
Notice that all module version numbers are incremented to adhere to our
|
||||
versioning policy.
|
||||
|
||||
After these release candidates have been evaluated to satisfaction, they are
|
||||
released as version `v1.0.0`.
|
||||
|
||||
* `otel`: `v1.0.0`
|
||||
* `otel/trace`: `v1.0.0`
|
||||
* `otel/baggage`: `v1.0.0`
|
||||
* `otel/sdk/trace`: `v1.0.0`
|
||||
|
||||
Since both the `go` utility and the Go module system support [the semantic
|
||||
versioning definition of
|
||||
precedence](https://semver.org/spec/v2.0.0.html#spec-item-11), this release
|
||||
will correctly be interpreted as the successor to the previous release
|
||||
candidates.
|
||||
|
||||
Active development of this project continues. The `otel/metric` module now has
|
||||
backwards incompatible changes to its API that need to be released and the
|
||||
`otel/baggage` module has a minor bug fix that needs to be released. The
|
||||
following release is made:
|
||||
|
||||
* `otel`: `v1.0.1`
|
||||
* `otel/trace`: `v1.0.1`
|
||||
* `otel/metric`: `v0.15.0`
|
||||
* `otel/baggage`: `v1.0.1`
|
||||
* `otel/sdk/trace`: `v1.0.1`
|
||||
* `otel/sdk/metric`: `v0.15.0`
|
||||
|
||||
Notice that, again, all stable module versions are incremented in unison and
|
||||
the `otel/sdk/metric` package, which depends on the `otel/metric` package, also
|
||||
bumped its version. This bump of the `otel/sdk/metric` package makes sense
|
||||
given their coupling, though it is not explicitly required by our versioning
|
||||
policy.
|
||||
|
||||
As we progress, the `otel/metric` and `otel/sdk/metric` packages have reached a
|
||||
point where they should be evaluated for stability. The `otel` module is
|
||||
reintegrated with the `otel/metric` package and the following release is made:
|
||||
|
||||
* `otel`: `v1.1.0-rc.1`
|
||||
* `otel/trace`: `v1.1.0-rc.1`
|
||||
* `otel/metric`: `v1.1.0-rc.1`
|
||||
* `otel/baggage`: `v1.1.0-rc.1`
|
||||
* `otel/sdk/trace`: `v1.1.0-rc.1`
|
||||
* `otel/sdk/metric`: `v1.1.0-rc.1`
|
||||
|
||||
All the modules are evaluated and determined to a viable stable release. They
|
||||
are then released as version `v1.1.0` (the minor version is incremented to
|
||||
indicate the addition of new signal).
|
||||
|
||||
* `otel`: `v1.1.0`
|
||||
* `otel/trace`: `v1.1.0`
|
||||
* `otel/metric`: `v1.1.0`
|
||||
* `otel/baggage`: `v1.1.0`
|
||||
* `otel/sdk/trace`: `v1.1.0`
|
||||
* `otel/sdk/metric`: `v1.1.0`
|
20
vendor/go.opentelemetry.io/otel/attribute/doc.go
generated
vendored
Normal file
20
vendor/go.opentelemetry.io/otel/attribute/doc.go
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// package attribute provides key and value attributes.
|
||||
//
|
||||
// This package is currently in a pre-GA phase. Backwards incompatible changes
|
||||
// may be introduced in subsequent minor version releases as we work to track
|
||||
// the evolving OpenTelemetry specification and user feedback.
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
150
vendor/go.opentelemetry.io/otel/attribute/encoder.go
generated
vendored
Normal file
150
vendor/go.opentelemetry.io/otel/attribute/encoder.go
generated
vendored
Normal file
@ -0,0 +1,150 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type (
|
||||
// Encoder is a mechanism for serializing a label set into a
|
||||
// specific string representation that supports caching, to
|
||||
// avoid repeated serialization. An example could be an
|
||||
// exporter encoding the label set into a wire representation.
|
||||
Encoder interface {
|
||||
// Encode returns the serialized encoding of the label
|
||||
// set using its Iterator. This result may be cached
|
||||
// by a attribute.Set.
|
||||
Encode(iterator Iterator) string
|
||||
|
||||
// ID returns a value that is unique for each class of
|
||||
// label encoder. Label encoders allocate these using
|
||||
// `NewEncoderID`.
|
||||
ID() EncoderID
|
||||
}
|
||||
|
||||
// EncoderID is used to identify distinct Encoder
|
||||
// implementations, for caching encoded results.
|
||||
EncoderID struct {
|
||||
value uint64
|
||||
}
|
||||
|
||||
// defaultLabelEncoder uses a sync.Pool of buffers to reduce
|
||||
// the number of allocations used in encoding labels. This
|
||||
// implementation encodes a comma-separated list of key=value,
|
||||
// with '/'-escaping of '=', ',', and '\'.
|
||||
defaultLabelEncoder struct {
|
||||
// pool is a pool of labelset builders. The buffers in this
|
||||
// pool grow to a size that most label encodings will not
|
||||
// allocate new memory.
|
||||
pool sync.Pool // *bytes.Buffer
|
||||
}
|
||||
)
|
||||
|
||||
// escapeChar is used to ensure uniqueness of the label encoding where
|
||||
// keys or values contain either '=' or ','. Since there is no parser
|
||||
// needed for this encoding and its only requirement is to be unique,
|
||||
// this choice is arbitrary. Users will see these in some exporters
|
||||
// (e.g., stdout), so the backslash ('\') is used as a conventional choice.
|
||||
const escapeChar = '\\'
|
||||
|
||||
var (
|
||||
_ Encoder = &defaultLabelEncoder{}
|
||||
|
||||
// encoderIDCounter is for generating IDs for other label
|
||||
// encoders.
|
||||
encoderIDCounter uint64
|
||||
|
||||
defaultEncoderOnce sync.Once
|
||||
defaultEncoderID = NewEncoderID()
|
||||
defaultEncoderInstance *defaultLabelEncoder
|
||||
)
|
||||
|
||||
// NewEncoderID returns a unique label encoder ID. It should be
|
||||
// called once per each type of label encoder. Preferably in init() or
|
||||
// in var definition.
|
||||
func NewEncoderID() EncoderID {
|
||||
return EncoderID{value: atomic.AddUint64(&encoderIDCounter, 1)}
|
||||
}
|
||||
|
||||
// DefaultEncoder returns a label encoder that encodes labels
|
||||
// in such a way that each escaped label's key is followed by an equal
|
||||
// sign and then by an escaped label's value. All key-value pairs are
|
||||
// separated by a comma.
|
||||
//
|
||||
// Escaping is done by prepending a backslash before either a
|
||||
// backslash, equal sign or a comma.
|
||||
func DefaultEncoder() Encoder {
|
||||
defaultEncoderOnce.Do(func() {
|
||||
defaultEncoderInstance = &defaultLabelEncoder{
|
||||
pool: sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &bytes.Buffer{}
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
return defaultEncoderInstance
|
||||
}
|
||||
|
||||
// Encode is a part of an implementation of the LabelEncoder
|
||||
// interface.
|
||||
func (d *defaultLabelEncoder) Encode(iter Iterator) string {
|
||||
buf := d.pool.Get().(*bytes.Buffer)
|
||||
defer d.pool.Put(buf)
|
||||
buf.Reset()
|
||||
|
||||
for iter.Next() {
|
||||
i, keyValue := iter.IndexedLabel()
|
||||
if i > 0 {
|
||||
_, _ = buf.WriteRune(',')
|
||||
}
|
||||
copyAndEscape(buf, string(keyValue.Key))
|
||||
|
||||
_, _ = buf.WriteRune('=')
|
||||
|
||||
if keyValue.Value.Type() == STRING {
|
||||
copyAndEscape(buf, keyValue.Value.AsString())
|
||||
} else {
|
||||
_, _ = buf.WriteString(keyValue.Value.Emit())
|
||||
}
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// ID is a part of an implementation of the LabelEncoder interface.
|
||||
func (*defaultLabelEncoder) ID() EncoderID {
|
||||
return defaultEncoderID
|
||||
}
|
||||
|
||||
// copyAndEscape escapes `=`, `,` and its own escape character (`\`),
|
||||
// making the default encoding unique.
|
||||
func copyAndEscape(buf *bytes.Buffer, val string) {
|
||||
for _, ch := range val {
|
||||
switch ch {
|
||||
case '=', ',', escapeChar:
|
||||
buf.WriteRune(escapeChar)
|
||||
}
|
||||
buf.WriteRune(ch)
|
||||
}
|
||||
}
|
||||
|
||||
// Valid returns true if this encoder ID was allocated by
|
||||
// `NewEncoderID`. Invalid encoder IDs will not be cached.
|
||||
func (id EncoderID) Valid() bool {
|
||||
return id.value != 0
|
||||
}
|
143
vendor/go.opentelemetry.io/otel/attribute/iterator.go
generated
vendored
Normal file
143
vendor/go.opentelemetry.io/otel/attribute/iterator.go
generated
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
// Iterator allows iterating over the set of labels in order,
|
||||
// sorted by key.
|
||||
type Iterator struct {
|
||||
storage *Set
|
||||
idx int
|
||||
}
|
||||
|
||||
// MergeIterator supports iterating over two sets of labels while
|
||||
// eliminating duplicate values from the combined set. The first
|
||||
// iterator value takes precedence.
|
||||
type MergeIterator struct {
|
||||
one oneIterator
|
||||
two oneIterator
|
||||
current KeyValue
|
||||
}
|
||||
|
||||
type oneIterator struct {
|
||||
iter Iterator
|
||||
done bool
|
||||
label KeyValue
|
||||
}
|
||||
|
||||
// Next moves the iterator to the next position. Returns false if there
|
||||
// are no more labels.
|
||||
func (i *Iterator) Next() bool {
|
||||
i.idx++
|
||||
return i.idx < i.Len()
|
||||
}
|
||||
|
||||
// Label returns current KeyValue. Must be called only after Next returns
|
||||
// true.
|
||||
func (i *Iterator) Label() KeyValue {
|
||||
kv, _ := i.storage.Get(i.idx)
|
||||
return kv
|
||||
}
|
||||
|
||||
// Attribute is a synonym for Label().
|
||||
func (i *Iterator) Attribute() KeyValue {
|
||||
return i.Label()
|
||||
}
|
||||
|
||||
// IndexedLabel returns current index and attribute. Must be called only
|
||||
// after Next returns true.
|
||||
func (i *Iterator) IndexedLabel() (int, KeyValue) {
|
||||
return i.idx, i.Label()
|
||||
}
|
||||
|
||||
// Len returns a number of labels in the iterator's `*Set`.
|
||||
func (i *Iterator) Len() int {
|
||||
return i.storage.Len()
|
||||
}
|
||||
|
||||
// ToSlice is a convenience function that creates a slice of labels
|
||||
// from the passed iterator. The iterator is set up to start from the
|
||||
// beginning before creating the slice.
|
||||
func (i *Iterator) ToSlice() []KeyValue {
|
||||
l := i.Len()
|
||||
if l == 0 {
|
||||
return nil
|
||||
}
|
||||
i.idx = -1
|
||||
slice := make([]KeyValue, 0, l)
|
||||
for i.Next() {
|
||||
slice = append(slice, i.Label())
|
||||
}
|
||||
return slice
|
||||
}
|
||||
|
||||
// NewMergeIterator returns a MergeIterator for merging two label sets
|
||||
// Duplicates are resolved by taking the value from the first set.
|
||||
func NewMergeIterator(s1, s2 *Set) MergeIterator {
|
||||
mi := MergeIterator{
|
||||
one: makeOne(s1.Iter()),
|
||||
two: makeOne(s2.Iter()),
|
||||
}
|
||||
return mi
|
||||
}
|
||||
|
||||
func makeOne(iter Iterator) oneIterator {
|
||||
oi := oneIterator{
|
||||
iter: iter,
|
||||
}
|
||||
oi.advance()
|
||||
return oi
|
||||
}
|
||||
|
||||
func (oi *oneIterator) advance() {
|
||||
if oi.done = !oi.iter.Next(); !oi.done {
|
||||
oi.label = oi.iter.Label()
|
||||
}
|
||||
}
|
||||
|
||||
// Next returns true if there is another label available.
|
||||
func (m *MergeIterator) Next() bool {
|
||||
if m.one.done && m.two.done {
|
||||
return false
|
||||
}
|
||||
if m.one.done {
|
||||
m.current = m.two.label
|
||||
m.two.advance()
|
||||
return true
|
||||
}
|
||||
if m.two.done {
|
||||
m.current = m.one.label
|
||||
m.one.advance()
|
||||
return true
|
||||
}
|
||||
if m.one.label.Key == m.two.label.Key {
|
||||
m.current = m.one.label // first iterator label value wins
|
||||
m.one.advance()
|
||||
m.two.advance()
|
||||
return true
|
||||
}
|
||||
if m.one.label.Key < m.two.label.Key {
|
||||
m.current = m.one.label
|
||||
m.one.advance()
|
||||
return true
|
||||
}
|
||||
m.current = m.two.label
|
||||
m.two.advance()
|
||||
return true
|
||||
}
|
||||
|
||||
// Label returns the current value after Next() returns true.
|
||||
func (m *MergeIterator) Label() KeyValue {
|
||||
return m.current
|
||||
}
|
102
vendor/go.opentelemetry.io/otel/attribute/key.go
generated
vendored
Normal file
102
vendor/go.opentelemetry.io/otel/attribute/key.go
generated
vendored
Normal file
@ -0,0 +1,102 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
// Key represents the key part in key-value pairs. It's a string. The
|
||||
// allowed character set in the key depends on the use of the key.
|
||||
type Key string
|
||||
|
||||
// Bool creates a KeyValue instance with a BOOL Value.
|
||||
//
|
||||
// If creating both key and a bool value at the same time, then
|
||||
// instead of calling Key(name).Bool(value) consider using a
|
||||
// convenience function provided by the api/key package -
|
||||
// key.Bool(name, value).
|
||||
func (k Key) Bool(v bool) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: BoolValue(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Int64 creates a KeyValue instance with an INT64 Value.
|
||||
//
|
||||
// If creating both key and an int64 value at the same time, then
|
||||
// instead of calling Key(name).Int64(value) consider using a
|
||||
// convenience function provided by the api/key package -
|
||||
// key.Int64(name, value).
|
||||
func (k Key) Int64(v int64) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: Int64Value(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Float64 creates a KeyValue instance with a FLOAT64 Value.
|
||||
//
|
||||
// If creating both key and a float64 value at the same time, then
|
||||
// instead of calling Key(name).Float64(value) consider using a
|
||||
// convenience function provided by the api/key package -
|
||||
// key.Float64(name, value).
|
||||
func (k Key) Float64(v float64) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: Float64Value(v),
|
||||
}
|
||||
}
|
||||
|
||||
// String creates a KeyValue instance with a STRING Value.
|
||||
//
|
||||
// If creating both key and a string value at the same time, then
|
||||
// instead of calling Key(name).String(value) consider using a
|
||||
// convenience function provided by the api/key package -
|
||||
// key.String(name, value).
|
||||
func (k Key) String(v string) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: StringValue(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Int creates a KeyValue instance with an INT64 Value.
|
||||
//
|
||||
// If creating both key and an int value at the same time, then
|
||||
// instead of calling Key(name).Int(value) consider using a
|
||||
// convenience function provided by the api/key package -
|
||||
// key.Int(name, value).
|
||||
func (k Key) Int(v int) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: IntValue(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Defined returns true for non-empty keys.
|
||||
func (k Key) Defined() bool {
|
||||
return len(k) != 0
|
||||
}
|
||||
|
||||
// Array creates a KeyValue instance with a ARRAY Value.
|
||||
//
|
||||
// If creating both key and a array value at the same time, then
|
||||
// instead of calling Key(name).String(value) consider using a
|
||||
// convenience function provided by the api/key package -
|
||||
// key.Array(name, value).
|
||||
func (k Key) Array(v interface{}) KeyValue {
|
||||
return KeyValue{
|
||||
Key: k,
|
||||
Value: ArrayValue(v),
|
||||
}
|
||||
}
|
108
vendor/go.opentelemetry.io/otel/attribute/kv.go
generated
vendored
Normal file
108
vendor/go.opentelemetry.io/otel/attribute/kv.go
generated
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// KeyValue holds a key and value pair.
|
||||
type KeyValue struct {
|
||||
Key Key
|
||||
Value Value
|
||||
}
|
||||
|
||||
// Valid returns if kv is a valid OpenTelemetry attribute.
|
||||
func (kv KeyValue) Valid() bool {
|
||||
return kv.Key != "" && kv.Value.Type() != INVALID
|
||||
}
|
||||
|
||||
// Bool creates a new key-value pair with a passed name and a bool
|
||||
// value.
|
||||
func Bool(k string, v bool) KeyValue {
|
||||
return Key(k).Bool(v)
|
||||
}
|
||||
|
||||
// Int64 creates a new key-value pair with a passed name and an int64
|
||||
// value.
|
||||
func Int64(k string, v int64) KeyValue {
|
||||
return Key(k).Int64(v)
|
||||
}
|
||||
|
||||
// Float64 creates a new key-value pair with a passed name and a float64
|
||||
// value.
|
||||
func Float64(k string, v float64) KeyValue {
|
||||
return Key(k).Float64(v)
|
||||
}
|
||||
|
||||
// String creates a new key-value pair with a passed name and a string
|
||||
// value.
|
||||
func String(k, v string) KeyValue {
|
||||
return Key(k).String(v)
|
||||
}
|
||||
|
||||
// Stringer creates a new key-value pair with a passed name and a string
|
||||
// value generated by the passed Stringer interface.
|
||||
func Stringer(k string, v fmt.Stringer) KeyValue {
|
||||
return Key(k).String(v.String())
|
||||
}
|
||||
|
||||
// Int creates a new key-value pair instance with a passed name and
|
||||
// either an int32 or an int64 value, depending on whether the int
|
||||
// type is 32 or 64 bits wide.
|
||||
func Int(k string, v int) KeyValue {
|
||||
return Key(k).Int(v)
|
||||
}
|
||||
|
||||
// Array creates a new key-value pair with a passed name and a array.
|
||||
// Only arrays of primitive type are supported.
|
||||
func Array(k string, v interface{}) KeyValue {
|
||||
return Key(k).Array(v)
|
||||
}
|
||||
|
||||
// Any creates a new key-value pair instance with a passed name and
|
||||
// automatic type inference. This is slower, and not type-safe.
|
||||
func Any(k string, value interface{}) KeyValue {
|
||||
if value == nil {
|
||||
return String(k, "<nil>")
|
||||
}
|
||||
|
||||
if stringer, ok := value.(fmt.Stringer); ok {
|
||||
return String(k, stringer.String())
|
||||
}
|
||||
|
||||
rv := reflect.ValueOf(value)
|
||||
|
||||
switch rv.Kind() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
return Array(k, value)
|
||||
case reflect.Bool:
|
||||
return Bool(k, rv.Bool())
|
||||
case reflect.Int, reflect.Int8, reflect.Int16:
|
||||
return Int(k, int(rv.Int()))
|
||||
case reflect.Int64:
|
||||
return Int64(k, rv.Int())
|
||||
case reflect.Float64:
|
||||
return Float64(k, rv.Float())
|
||||
case reflect.String:
|
||||
return String(k, rv.String())
|
||||
}
|
||||
if b, err := json.Marshal(value); b != nil && err == nil {
|
||||
return String(k, string(b))
|
||||
}
|
||||
return String(k, fmt.Sprint(value))
|
||||
}
|
471
vendor/go.opentelemetry.io/otel/attribute/set.go
generated
vendored
Normal file
471
vendor/go.opentelemetry.io/otel/attribute/set.go
generated
vendored
Normal file
@ -0,0 +1,471 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type (
|
||||
// Set is the representation for a distinct label set. It
|
||||
// manages an immutable set of labels, with an internal cache
|
||||
// for storing label encodings.
|
||||
//
|
||||
// This type supports the `Equivalent` method of comparison
|
||||
// using values of type `Distinct`.
|
||||
//
|
||||
// This type is used to implement:
|
||||
// 1. Metric labels
|
||||
// 2. Resource sets
|
||||
// 3. Correlation map (TODO)
|
||||
Set struct {
|
||||
equivalent Distinct
|
||||
|
||||
lock sync.Mutex
|
||||
encoders [maxConcurrentEncoders]EncoderID
|
||||
encoded [maxConcurrentEncoders]string
|
||||
}
|
||||
|
||||
// Distinct wraps a variable-size array of `KeyValue`,
|
||||
// constructed with keys in sorted order. This can be used as
|
||||
// a map key or for equality checking between Sets.
|
||||
Distinct struct {
|
||||
iface interface{}
|
||||
}
|
||||
|
||||
// Filter supports removing certain labels from label sets.
|
||||
// When the filter returns true, the label will be kept in
|
||||
// the filtered label set. When the filter returns false, the
|
||||
// label is excluded from the filtered label set, and the
|
||||
// label instead appears in the `removed` list of excluded labels.
|
||||
Filter func(KeyValue) bool
|
||||
|
||||
// Sortable implements `sort.Interface`, used for sorting
|
||||
// `KeyValue`. This is an exported type to support a
|
||||
// memory optimization. A pointer to one of these is needed
|
||||
// for the call to `sort.Stable()`, which the caller may
|
||||
// provide in order to avoid an allocation. See
|
||||
// `NewSetWithSortable()`.
|
||||
Sortable []KeyValue
|
||||
)
|
||||
|
||||
var (
|
||||
// keyValueType is used in `computeDistinctReflect`.
|
||||
keyValueType = reflect.TypeOf(KeyValue{})
|
||||
|
||||
// emptySet is returned for empty label sets.
|
||||
emptySet = &Set{
|
||||
equivalent: Distinct{
|
||||
iface: [0]KeyValue{},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const maxConcurrentEncoders = 3
|
||||
|
||||
// EmptySet returns a reference to a Set with no elements.
|
||||
//
|
||||
// This is a convenience provided for optimized calling utility.
|
||||
func EmptySet() *Set {
|
||||
return emptySet
|
||||
}
|
||||
|
||||
// reflect abbreviates `reflect.ValueOf`.
|
||||
func (d Distinct) reflect() reflect.Value {
|
||||
return reflect.ValueOf(d.iface)
|
||||
}
|
||||
|
||||
// Valid returns true if this value refers to a valid `*Set`.
|
||||
func (d Distinct) Valid() bool {
|
||||
return d.iface != nil
|
||||
}
|
||||
|
||||
// Len returns the number of labels in this set.
|
||||
func (l *Set) Len() int {
|
||||
if l == nil || !l.equivalent.Valid() {
|
||||
return 0
|
||||
}
|
||||
return l.equivalent.reflect().Len()
|
||||
}
|
||||
|
||||
// Get returns the KeyValue at ordered position `idx` in this set.
|
||||
func (l *Set) Get(idx int) (KeyValue, bool) {
|
||||
if l == nil {
|
||||
return KeyValue{}, false
|
||||
}
|
||||
value := l.equivalent.reflect()
|
||||
|
||||
if idx >= 0 && idx < value.Len() {
|
||||
// Note: The Go compiler successfully avoids an allocation for
|
||||
// the interface{} conversion here:
|
||||
return value.Index(idx).Interface().(KeyValue), true
|
||||
}
|
||||
|
||||
return KeyValue{}, false
|
||||
}
|
||||
|
||||
// Value returns the value of a specified key in this set.
|
||||
func (l *Set) Value(k Key) (Value, bool) {
|
||||
if l == nil {
|
||||
return Value{}, false
|
||||
}
|
||||
rValue := l.equivalent.reflect()
|
||||
vlen := rValue.Len()
|
||||
|
||||
idx := sort.Search(vlen, func(idx int) bool {
|
||||
return rValue.Index(idx).Interface().(KeyValue).Key >= k
|
||||
})
|
||||
if idx >= vlen {
|
||||
return Value{}, false
|
||||
}
|
||||
keyValue := rValue.Index(idx).Interface().(KeyValue)
|
||||
if k == keyValue.Key {
|
||||
return keyValue.Value, true
|
||||
}
|
||||
return Value{}, false
|
||||
}
|
||||
|
||||
// HasValue tests whether a key is defined in this set.
|
||||
func (l *Set) HasValue(k Key) bool {
|
||||
if l == nil {
|
||||
return false
|
||||
}
|
||||
_, ok := l.Value(k)
|
||||
return ok
|
||||
}
|
||||
|
||||
// Iter returns an iterator for visiting the labels in this set.
|
||||
func (l *Set) Iter() Iterator {
|
||||
return Iterator{
|
||||
storage: l,
|
||||
idx: -1,
|
||||
}
|
||||
}
|
||||
|
||||
// ToSlice returns the set of labels belonging to this set, sorted,
|
||||
// where keys appear no more than once.
|
||||
func (l *Set) ToSlice() []KeyValue {
|
||||
iter := l.Iter()
|
||||
return iter.ToSlice()
|
||||
}
|
||||
|
||||
// Equivalent returns a value that may be used as a map key. The
|
||||
// Distinct type guarantees that the result will equal the equivalent
|
||||
// Distinct value of any label set with the same elements as this,
|
||||
// where sets are made unique by choosing the last value in the input
|
||||
// for any given key.
|
||||
func (l *Set) Equivalent() Distinct {
|
||||
if l == nil || !l.equivalent.Valid() {
|
||||
return emptySet.equivalent
|
||||
}
|
||||
return l.equivalent
|
||||
}
|
||||
|
||||
// Equals returns true if the argument set is equivalent to this set.
|
||||
func (l *Set) Equals(o *Set) bool {
|
||||
return l.Equivalent() == o.Equivalent()
|
||||
}
|
||||
|
||||
// Encoded returns the encoded form of this set, according to
|
||||
// `encoder`. The result will be cached in this `*Set`.
|
||||
func (l *Set) Encoded(encoder Encoder) string {
|
||||
if l == nil || encoder == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
id := encoder.ID()
|
||||
if !id.Valid() {
|
||||
// Invalid IDs are not cached.
|
||||
return encoder.Encode(l.Iter())
|
||||
}
|
||||
|
||||
var lookup *string
|
||||
l.lock.Lock()
|
||||
for idx := 0; idx < maxConcurrentEncoders; idx++ {
|
||||
if l.encoders[idx] == id {
|
||||
lookup = &l.encoded[idx]
|
||||
break
|
||||
}
|
||||
}
|
||||
l.lock.Unlock()
|
||||
|
||||
if lookup != nil {
|
||||
return *lookup
|
||||
}
|
||||
|
||||
r := encoder.Encode(l.Iter())
|
||||
|
||||
l.lock.Lock()
|
||||
defer l.lock.Unlock()
|
||||
|
||||
for idx := 0; idx < maxConcurrentEncoders; idx++ {
|
||||
if l.encoders[idx] == id {
|
||||
return l.encoded[idx]
|
||||
}
|
||||
if !l.encoders[idx].Valid() {
|
||||
l.encoders[idx] = id
|
||||
l.encoded[idx] = r
|
||||
return r
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: This is a performance cliff. Find a way for this to
|
||||
// generate a warning.
|
||||
return r
|
||||
}
|
||||
|
||||
func empty() Set {
|
||||
return Set{
|
||||
equivalent: emptySet.equivalent,
|
||||
}
|
||||
}
|
||||
|
||||
// NewSet returns a new `Set`. See the documentation for
|
||||
// `NewSetWithSortableFiltered` for more details.
|
||||
//
|
||||
// Except for empty sets, this method adds an additional allocation
|
||||
// compared with calls that include a `*Sortable`.
|
||||
func NewSet(kvs ...KeyValue) Set {
|
||||
// Check for empty set.
|
||||
if len(kvs) == 0 {
|
||||
return empty()
|
||||
}
|
||||
s, _ := NewSetWithSortableFiltered(kvs, new(Sortable), nil)
|
||||
return s //nolint
|
||||
}
|
||||
|
||||
// NewSetWithSortable returns a new `Set`. See the documentation for
|
||||
// `NewSetWithSortableFiltered` for more details.
|
||||
//
|
||||
// This call includes a `*Sortable` option as a memory optimization.
|
||||
func NewSetWithSortable(kvs []KeyValue, tmp *Sortable) Set {
|
||||
// Check for empty set.
|
||||
if len(kvs) == 0 {
|
||||
return empty()
|
||||
}
|
||||
s, _ := NewSetWithSortableFiltered(kvs, tmp, nil)
|
||||
return s //nolint
|
||||
}
|
||||
|
||||
// NewSetWithFiltered returns a new `Set`. See the documentation for
|
||||
// `NewSetWithSortableFiltered` for more details.
|
||||
//
|
||||
// This call includes a `Filter` to include/exclude label keys from
|
||||
// the return value. Excluded keys are returned as a slice of label
|
||||
// values.
|
||||
func NewSetWithFiltered(kvs []KeyValue, filter Filter) (Set, []KeyValue) {
|
||||
// Check for empty set.
|
||||
if len(kvs) == 0 {
|
||||
return empty(), nil
|
||||
}
|
||||
return NewSetWithSortableFiltered(kvs, new(Sortable), filter)
|
||||
}
|
||||
|
||||
// NewSetWithSortableFiltered returns a new `Set`.
|
||||
//
|
||||
// Duplicate keys are eliminated by taking the last value. This
|
||||
// re-orders the input slice so that unique last-values are contiguous
|
||||
// at the end of the slice.
|
||||
//
|
||||
// This ensures the following:
|
||||
//
|
||||
// - Last-value-wins semantics
|
||||
// - Caller sees the reordering, but doesn't lose values
|
||||
// - Repeated call preserve last-value wins.
|
||||
//
|
||||
// Note that methods are defined on `*Set`, although this returns `Set`.
|
||||
// Callers can avoid memory allocations by:
|
||||
//
|
||||
// - allocating a `Sortable` for use as a temporary in this method
|
||||
// - allocating a `Set` for storing the return value of this
|
||||
// constructor.
|
||||
//
|
||||
// The result maintains a cache of encoded labels, by attribute.EncoderID.
|
||||
// This value should not be copied after its first use.
|
||||
//
|
||||
// The second `[]KeyValue` return value is a list of labels that were
|
||||
// excluded by the Filter (if non-nil).
|
||||
func NewSetWithSortableFiltered(kvs []KeyValue, tmp *Sortable, filter Filter) (Set, []KeyValue) {
|
||||
// Check for empty set.
|
||||
if len(kvs) == 0 {
|
||||
return empty(), nil
|
||||
}
|
||||
|
||||
*tmp = kvs
|
||||
|
||||
// Stable sort so the following de-duplication can implement
|
||||
// last-value-wins semantics.
|
||||
sort.Stable(tmp)
|
||||
|
||||
*tmp = nil
|
||||
|
||||
position := len(kvs) - 1
|
||||
offset := position - 1
|
||||
|
||||
// The requirements stated above require that the stable
|
||||
// result be placed in the end of the input slice, while
|
||||
// overwritten values are swapped to the beginning.
|
||||
//
|
||||
// De-duplicate with last-value-wins semantics. Preserve
|
||||
// duplicate values at the beginning of the input slice.
|
||||
for ; offset >= 0; offset-- {
|
||||
if kvs[offset].Key == kvs[position].Key {
|
||||
continue
|
||||
}
|
||||
position--
|
||||
kvs[offset], kvs[position] = kvs[position], kvs[offset]
|
||||
}
|
||||
if filter != nil {
|
||||
return filterSet(kvs[position:], filter)
|
||||
}
|
||||
return Set{
|
||||
equivalent: computeDistinct(kvs[position:]),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// filterSet reorders `kvs` so that included keys are contiguous at
|
||||
// the end of the slice, while excluded keys precede the included keys.
|
||||
func filterSet(kvs []KeyValue, filter Filter) (Set, []KeyValue) {
|
||||
var excluded []KeyValue
|
||||
|
||||
// Move labels that do not match the filter so
|
||||
// they're adjacent before calling computeDistinct().
|
||||
distinctPosition := len(kvs)
|
||||
|
||||
// Swap indistinct keys forward and distinct keys toward the
|
||||
// end of the slice.
|
||||
offset := len(kvs) - 1
|
||||
for ; offset >= 0; offset-- {
|
||||
if filter(kvs[offset]) {
|
||||
distinctPosition--
|
||||
kvs[offset], kvs[distinctPosition] = kvs[distinctPosition], kvs[offset]
|
||||
continue
|
||||
}
|
||||
}
|
||||
excluded = kvs[:distinctPosition]
|
||||
|
||||
return Set{
|
||||
equivalent: computeDistinct(kvs[distinctPosition:]),
|
||||
}, excluded
|
||||
}
|
||||
|
||||
// Filter returns a filtered copy of this `Set`. See the
|
||||
// documentation for `NewSetWithSortableFiltered` for more details.
|
||||
func (l *Set) Filter(re Filter) (Set, []KeyValue) {
|
||||
if re == nil {
|
||||
return Set{
|
||||
equivalent: l.equivalent,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Note: This could be refactored to avoid the temporary slice
|
||||
// allocation, if it proves to be expensive.
|
||||
return filterSet(l.ToSlice(), re)
|
||||
}
|
||||
|
||||
// computeDistinct returns a `Distinct` using either the fixed- or
|
||||
// reflect-oriented code path, depending on the size of the input.
|
||||
// The input slice is assumed to already be sorted and de-duplicated.
|
||||
func computeDistinct(kvs []KeyValue) Distinct {
|
||||
iface := computeDistinctFixed(kvs)
|
||||
if iface == nil {
|
||||
iface = computeDistinctReflect(kvs)
|
||||
}
|
||||
return Distinct{
|
||||
iface: iface,
|
||||
}
|
||||
}
|
||||
|
||||
// computeDistinctFixed computes a `Distinct` for small slices. It
|
||||
// returns nil if the input is too large for this code path.
|
||||
func computeDistinctFixed(kvs []KeyValue) interface{} {
|
||||
switch len(kvs) {
|
||||
case 1:
|
||||
ptr := new([1]KeyValue)
|
||||
copy((*ptr)[:], kvs)
|
||||
return *ptr
|
||||
case 2:
|
||||
ptr := new([2]KeyValue)
|
||||
copy((*ptr)[:], kvs)
|
||||
return *ptr
|
||||
case 3:
|
||||
ptr := new([3]KeyValue)
|
||||
copy((*ptr)[:], kvs)
|
||||
return *ptr
|
||||
case 4:
|
||||
ptr := new([4]KeyValue)
|
||||
copy((*ptr)[:], kvs)
|
||||
return *ptr
|
||||
case 5:
|
||||
ptr := new([5]KeyValue)
|
||||
copy((*ptr)[:], kvs)
|
||||
return *ptr
|
||||
case 6:
|
||||
ptr := new([6]KeyValue)
|
||||
copy((*ptr)[:], kvs)
|
||||
return *ptr
|
||||
case 7:
|
||||
ptr := new([7]KeyValue)
|
||||
copy((*ptr)[:], kvs)
|
||||
return *ptr
|
||||
case 8:
|
||||
ptr := new([8]KeyValue)
|
||||
copy((*ptr)[:], kvs)
|
||||
return *ptr
|
||||
case 9:
|
||||
ptr := new([9]KeyValue)
|
||||
copy((*ptr)[:], kvs)
|
||||
return *ptr
|
||||
case 10:
|
||||
ptr := new([10]KeyValue)
|
||||
copy((*ptr)[:], kvs)
|
||||
return *ptr
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// computeDistinctReflect computes a `Distinct` using reflection,
|
||||
// works for any size input.
|
||||
func computeDistinctReflect(kvs []KeyValue) interface{} {
|
||||
at := reflect.New(reflect.ArrayOf(len(kvs), keyValueType)).Elem()
|
||||
for i, keyValue := range kvs {
|
||||
*(at.Index(i).Addr().Interface().(*KeyValue)) = keyValue
|
||||
}
|
||||
return at.Interface()
|
||||
}
|
||||
|
||||
// MarshalJSON returns the JSON encoding of the `*Set`.
|
||||
func (l *Set) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(l.equivalent.iface)
|
||||
}
|
||||
|
||||
// Len implements `sort.Interface`.
|
||||
func (l *Sortable) Len() int {
|
||||
return len(*l)
|
||||
}
|
||||
|
||||
// Swap implements `sort.Interface`.
|
||||
func (l *Sortable) Swap(i, j int) {
|
||||
(*l)[i], (*l)[j] = (*l)[j], (*l)[i]
|
||||
}
|
||||
|
||||
// Less implements `sort.Interface`.
|
||||
func (l *Sortable) Less(i, j int) bool {
|
||||
return (*l)[i].Key < (*l)[j].Key
|
||||
}
|
28
vendor/go.opentelemetry.io/otel/attribute/type_string.go
generated
vendored
Normal file
28
vendor/go.opentelemetry.io/otel/attribute/type_string.go
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
// Code generated by "stringer -type=Type"; DO NOT EDIT.
|
||||
|
||||
package attribute
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[INVALID-0]
|
||||
_ = x[BOOL-1]
|
||||
_ = x[INT64-2]
|
||||
_ = x[FLOAT64-3]
|
||||
_ = x[STRING-4]
|
||||
_ = x[ARRAY-5]
|
||||
}
|
||||
|
||||
const _Type_name = "INVALIDBOOLINT64FLOAT64STRINGARRAY"
|
||||
|
||||
var _Type_index = [...]uint8{0, 7, 11, 16, 23, 29, 34}
|
||||
|
||||
func (i Type) String() string {
|
||||
if i < 0 || i >= Type(len(_Type_index)-1) {
|
||||
return "Type(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Type_name[_Type_index[i]:_Type_index[i+1]]
|
||||
}
|
204
vendor/go.opentelemetry.io/otel/attribute/value.go
generated
vendored
Normal file
204
vendor/go.opentelemetry.io/otel/attribute/value.go
generated
vendored
Normal file
@ -0,0 +1,204 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package attribute // import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
"go.opentelemetry.io/otel/internal"
|
||||
)
|
||||
|
||||
//go:generate stringer -type=Type
|
||||
|
||||
// Type describes the type of the data Value holds.
|
||||
type Type int
|
||||
|
||||
// Value represents the value part in key-value pairs.
|
||||
type Value struct {
|
||||
vtype Type
|
||||
numeric uint64
|
||||
stringly string
|
||||
// TODO Lazy value type?
|
||||
|
||||
array interface{}
|
||||
}
|
||||
|
||||
const (
|
||||
// INVALID is used for a Value with no value set.
|
||||
INVALID Type = iota
|
||||
// BOOL is a boolean Type Value.
|
||||
BOOL
|
||||
// INT64 is a 64-bit signed integral Type Value.
|
||||
INT64
|
||||
// FLOAT64 is a 64-bit floating point Type Value.
|
||||
FLOAT64
|
||||
// STRING is a string Type Value.
|
||||
STRING
|
||||
// ARRAY is an array Type Value used to store 1-dimensional slices or
|
||||
// arrays of bool, int, int32, int64, uint, uint32, uint64, float,
|
||||
// float32, float64, or string types.
|
||||
ARRAY
|
||||
)
|
||||
|
||||
// BoolValue creates a BOOL Value.
|
||||
func BoolValue(v bool) Value {
|
||||
return Value{
|
||||
vtype: BOOL,
|
||||
numeric: internal.BoolToRaw(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Int64Value creates an INT64 Value.
|
||||
func Int64Value(v int64) Value {
|
||||
return Value{
|
||||
vtype: INT64,
|
||||
numeric: internal.Int64ToRaw(v),
|
||||
}
|
||||
}
|
||||
|
||||
// Float64Value creates a FLOAT64 Value.
|
||||
func Float64Value(v float64) Value {
|
||||
return Value{
|
||||
vtype: FLOAT64,
|
||||
numeric: internal.Float64ToRaw(v),
|
||||
}
|
||||
}
|
||||
|
||||
// StringValue creates a STRING Value.
|
||||
func StringValue(v string) Value {
|
||||
return Value{
|
||||
vtype: STRING,
|
||||
stringly: v,
|
||||
}
|
||||
}
|
||||
|
||||
// IntValue creates an INT64 Value.
|
||||
func IntValue(v int) Value {
|
||||
return Int64Value(int64(v))
|
||||
}
|
||||
|
||||
// ArrayValue creates an ARRAY value from an array or slice.
|
||||
// Only arrays or slices of bool, int, int64, float, float64, or string types are allowed.
|
||||
// Specifically, arrays and slices can not contain other arrays, slices, structs, or non-standard
|
||||
// types. If the passed value is not an array or slice of these types an
|
||||
// INVALID value is returned.
|
||||
func ArrayValue(v interface{}) Value {
|
||||
switch reflect.TypeOf(v).Kind() {
|
||||
case reflect.Array, reflect.Slice:
|
||||
// get array type regardless of dimensions
|
||||
typ := reflect.TypeOf(v).Elem()
|
||||
kind := typ.Kind()
|
||||
switch kind {
|
||||
case reflect.Bool, reflect.Int, reflect.Int64,
|
||||
reflect.Float64, reflect.String:
|
||||
val := reflect.ValueOf(v)
|
||||
length := val.Len()
|
||||
frozen := reflect.Indirect(reflect.New(reflect.ArrayOf(length, typ)))
|
||||
reflect.Copy(frozen, val)
|
||||
return Value{
|
||||
vtype: ARRAY,
|
||||
array: frozen.Interface(),
|
||||
}
|
||||
default:
|
||||
return Value{vtype: INVALID}
|
||||
}
|
||||
}
|
||||
return Value{vtype: INVALID}
|
||||
}
|
||||
|
||||
// Type returns a type of the Value.
|
||||
func (v Value) Type() Type {
|
||||
return v.vtype
|
||||
}
|
||||
|
||||
// AsBool returns the bool value. Make sure that the Value's type is
|
||||
// BOOL.
|
||||
func (v Value) AsBool() bool {
|
||||
return internal.RawToBool(v.numeric)
|
||||
}
|
||||
|
||||
// AsInt64 returns the int64 value. Make sure that the Value's type is
|
||||
// INT64.
|
||||
func (v Value) AsInt64() int64 {
|
||||
return internal.RawToInt64(v.numeric)
|
||||
}
|
||||
|
||||
// AsFloat64 returns the float64 value. Make sure that the Value's
|
||||
// type is FLOAT64.
|
||||
func (v Value) AsFloat64() float64 {
|
||||
return internal.RawToFloat64(v.numeric)
|
||||
}
|
||||
|
||||
// AsString returns the string value. Make sure that the Value's type
|
||||
// is STRING.
|
||||
func (v Value) AsString() string {
|
||||
return v.stringly
|
||||
}
|
||||
|
||||
// AsArray returns the array Value as an interface{}.
|
||||
func (v Value) AsArray() interface{} {
|
||||
return v.array
|
||||
}
|
||||
|
||||
type unknownValueType struct{}
|
||||
|
||||
// AsInterface returns Value's data as interface{}.
|
||||
func (v Value) AsInterface() interface{} {
|
||||
switch v.Type() {
|
||||
case ARRAY:
|
||||
return v.AsArray()
|
||||
case BOOL:
|
||||
return v.AsBool()
|
||||
case INT64:
|
||||
return v.AsInt64()
|
||||
case FLOAT64:
|
||||
return v.AsFloat64()
|
||||
case STRING:
|
||||
return v.stringly
|
||||
}
|
||||
return unknownValueType{}
|
||||
}
|
||||
|
||||
// Emit returns a string representation of Value's data.
|
||||
func (v Value) Emit() string {
|
||||
switch v.Type() {
|
||||
case ARRAY:
|
||||
return fmt.Sprint(v.array)
|
||||
case BOOL:
|
||||
return strconv.FormatBool(v.AsBool())
|
||||
case INT64:
|
||||
return strconv.FormatInt(v.AsInt64(), 10)
|
||||
case FLOAT64:
|
||||
return fmt.Sprint(v.AsFloat64())
|
||||
case STRING:
|
||||
return v.stringly
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalJSON returns the JSON encoding of the Value.
|
||||
func (v Value) MarshalJSON() ([]byte, error) {
|
||||
var jsonVal struct {
|
||||
Type string
|
||||
Value interface{}
|
||||
}
|
||||
jsonVal.Type = v.Type().String()
|
||||
jsonVal.Value = v.AsInterface()
|
||||
return json.Marshal(jsonVal)
|
||||
}
|
106
vendor/go.opentelemetry.io/otel/codes/codes.go
generated
vendored
Normal file
106
vendor/go.opentelemetry.io/otel/codes/codes.go
generated
vendored
Normal file
@ -0,0 +1,106 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package codes // import "go.opentelemetry.io/otel/codes"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
// Unset is the default status code.
|
||||
Unset Code = 0
|
||||
// Error indicates the operation contains an error.
|
||||
Error Code = 1
|
||||
// Ok indicates operation has been validated by an Application developers
|
||||
// or Operator to have completed successfully, or contain no error.
|
||||
Ok Code = 2
|
||||
|
||||
maxCode = 3
|
||||
)
|
||||
|
||||
// Code is an 32-bit representation of a status state.
|
||||
type Code uint32
|
||||
|
||||
var codeToStr = map[Code]string{
|
||||
Unset: "Unset",
|
||||
Error: "Error",
|
||||
Ok: "Ok",
|
||||
}
|
||||
|
||||
var strToCode = map[string]Code{
|
||||
`"Unset"`: Unset,
|
||||
`"Error"`: Error,
|
||||
`"Ok"`: Ok,
|
||||
}
|
||||
|
||||
// String returns the Code as a string.
|
||||
func (c Code) String() string {
|
||||
return codeToStr[c]
|
||||
}
|
||||
|
||||
// UnmarshalJSON unmarshals b into the Code.
|
||||
//
|
||||
// This is based on the functionality in the gRPC codes package:
|
||||
// https://github.com/grpc/grpc-go/blob/bb64fee312b46ebee26be43364a7a966033521b1/codes/codes.go#L218-L244
|
||||
func (c *Code) UnmarshalJSON(b []byte) error {
|
||||
// From json.Unmarshaler: By convention, to approximate the behavior of
|
||||
// Unmarshal itself, Unmarshalers implement UnmarshalJSON([]byte("null")) as
|
||||
// a no-op.
|
||||
if string(b) == "null" {
|
||||
return nil
|
||||
}
|
||||
if c == nil {
|
||||
return fmt.Errorf("nil receiver passed to UnmarshalJSON")
|
||||
}
|
||||
|
||||
var x interface{}
|
||||
if err := json.Unmarshal(b, &x); err != nil {
|
||||
return err
|
||||
}
|
||||
switch x.(type) {
|
||||
case string:
|
||||
if jc, ok := strToCode[string(b)]; ok {
|
||||
*c = jc
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid code: %q", string(b))
|
||||
case float64:
|
||||
if ci, err := strconv.ParseUint(string(b), 10, 32); err == nil {
|
||||
if ci >= maxCode {
|
||||
return fmt.Errorf("invalid code: %q", ci)
|
||||
}
|
||||
|
||||
*c = Code(ci)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("invalid code: %q", string(b))
|
||||
default:
|
||||
return fmt.Errorf("invalid code: %q", string(b))
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalJSON returns c as the JSON encoding of c.
|
||||
func (c *Code) MarshalJSON() ([]byte, error) {
|
||||
if c == nil {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
str, ok := codeToStr[*c]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("invalid code: %d", *c)
|
||||
}
|
||||
return []byte(fmt.Sprintf("%q", str)), nil
|
||||
}
|
25
vendor/go.opentelemetry.io/otel/codes/doc.go
generated
vendored
Normal file
25
vendor/go.opentelemetry.io/otel/codes/doc.go
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/*
|
||||
Package codes defines the canonical error codes used by OpenTelemetry.
|
||||
|
||||
This package is currently in a pre-GA phase. Backwards incompatible changes
|
||||
may be introduced in subsequent minor version releases as we work to track
|
||||
the evolving OpenTelemetry specification and user feedback.
|
||||
|
||||
It conforms to [the OpenTelemetry
|
||||
specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#statuscanonicalcode).
|
||||
*/
|
||||
package codes // import "go.opentelemetry.io/otel/codes"
|
38
vendor/go.opentelemetry.io/otel/doc.go
generated
vendored
Normal file
38
vendor/go.opentelemetry.io/otel/doc.go
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/*
|
||||
Package otel provides global access to the OpenTelemetry API. The subpackages of
|
||||
the otel package provide an implementation of the OpenTelemetry API.
|
||||
|
||||
This package is currently in a pre-GA phase. Backwards incompatible changes
|
||||
may be introduced in subsequent minor version releases as we work to track the
|
||||
evolving OpenTelemetry specification and user feedback.
|
||||
|
||||
The provided API is used to instrument code and measure data about that code's
|
||||
performance and operation. The measured data, by default, is not processed or
|
||||
transmitted anywhere. An implementation of the OpenTelemetry SDK, like the
|
||||
default SDK implementation (go.opentelemetry.io/otel/sdk), and associated
|
||||
exporters are used to process and transport this data.
|
||||
|
||||
To read the getting started guide, see https://opentelemetry.io/docs/go/getting-started/.
|
||||
|
||||
To read more about tracing, see go.opentelemetry.io/otel/trace.
|
||||
|
||||
To read more about metrics, see go.opentelemetry.io/otel/metric.
|
||||
|
||||
To read more about propagation, see go.opentelemetry.io/otel/propagation and
|
||||
go.opentelemetry.io/otel/baggage.
|
||||
*/
|
||||
package otel // import "go.opentelemetry.io/otel"
|
22
vendor/go.opentelemetry.io/otel/error_handler.go
generated
vendored
Normal file
22
vendor/go.opentelemetry.io/otel/error_handler.go
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otel // import "go.opentelemetry.io/otel"
|
||||
|
||||
// ErrorHandler handles irremediable events.
|
||||
type ErrorHandler interface {
|
||||
// Handle handles any error deemed irremediable by an OpenTelemetry
|
||||
// component.
|
||||
Handle(error)
|
||||
}
|
201
vendor/go.opentelemetry.io/otel/exporters/otlp/LICENSE
generated
vendored
Normal file
201
vendor/go.opentelemetry.io/otel/exporters/otlp/LICENSE
generated
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
31
vendor/go.opentelemetry.io/otel/exporters/otlp/README.md
generated
vendored
Normal file
31
vendor/go.opentelemetry.io/otel/exporters/otlp/README.md
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
# OpenTelemetry Collector Go Exporter
|
||||
|
||||
[](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp)
|
||||
|
||||
This exporter exports OpenTelemetry spans and metrics to the OpenTelemetry Collector.
|
||||
|
||||
|
||||
## Installation and Setup
|
||||
|
||||
The exporter can be installed using standard `go` functionality.
|
||||
|
||||
```bash
|
||||
$ go get -u go.opentelemetry.io/otel/exporters/otlp
|
||||
```
|
||||
|
||||
A new exporter can be created using the `NewExporter` function.
|
||||
|
||||
## Retries
|
||||
|
||||
The exporter will not, by default, retry failed requests to the collector.
|
||||
However, it is configured in a way that it can be easily enabled.
|
||||
|
||||
To enable retries, the `GRPC_GO_RETRY` environment variable needs to be set to `on`. For example,
|
||||
|
||||
```
|
||||
GRPC_GO_RETRY=on go run .
|
||||
```
|
||||
|
||||
The [default service config](https://github.com/grpc/proposal/blob/master/A6-client-retries.md) used by default is defined to retry failed requests with exponential backoff (`0.3seconds * (2)^retry`) with [a max of `5` retries](https://github.com/open-telemetry/oteps/blob/be2a3fcbaa417ebbf5845cd485d34fdf0ab4a2a4/text/0035-opentelemetry-protocol.md#export-response)).
|
||||
|
||||
These retries are only attempted for reponses that are [deemed "retry-able" by the collector](https://github.com/grpc/proposal/blob/master/A6-client-retries.md#validation-of-retrypolicy).
|
20
vendor/go.opentelemetry.io/otel/exporters/otlp/doc.go
generated
vendored
Normal file
20
vendor/go.opentelemetry.io/otel/exporters/otlp/doc.go
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package otlp contains an exporter for the OpenTelemetry protocol buffers.
|
||||
//
|
||||
// This package is currently in a pre-GA phase. Backwards incompatible changes
|
||||
// may be introduced in subsequent minor version releases as we work to track
|
||||
// the evolving OpenTelemetry specification and user feedback.
|
||||
package otlp // import "go.opentelemetry.io/otel/exporters/otlp"
|
62
vendor/go.opentelemetry.io/otel/exporters/otlp/go.mod
generated
vendored
Normal file
62
vendor/go.opentelemetry.io/otel/exporters/otlp/go.mod
generated
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
module go.opentelemetry.io/otel/exporters/otlp
|
||||
|
||||
go 1.14
|
||||
|
||||
replace (
|
||||
go.opentelemetry.io/otel => ../..
|
||||
go.opentelemetry.io/otel/sdk => ../../sdk
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.5.5
|
||||
github.com/stretchr/testify v1.7.0
|
||||
go.opentelemetry.io/otel v0.20.0
|
||||
go.opentelemetry.io/otel/metric v0.20.0
|
||||
go.opentelemetry.io/otel/sdk v0.20.0
|
||||
go.opentelemetry.io/otel/sdk/export/metric v0.20.0
|
||||
go.opentelemetry.io/otel/sdk/metric v0.20.0
|
||||
go.opentelemetry.io/otel/trace v0.20.0
|
||||
go.opentelemetry.io/proto/otlp v0.7.0
|
||||
google.golang.org/grpc v1.37.0
|
||||
google.golang.org/protobuf v1.26.0
|
||||
)
|
||||
|
||||
replace go.opentelemetry.io/otel/bridge/opencensus => ../../bridge/opencensus
|
||||
|
||||
replace go.opentelemetry.io/otel/bridge/opentracing => ../../bridge/opentracing
|
||||
|
||||
replace go.opentelemetry.io/otel/example/jaeger => ../../example/jaeger
|
||||
|
||||
replace go.opentelemetry.io/otel/example/namedtracer => ../../example/namedtracer
|
||||
|
||||
replace go.opentelemetry.io/otel/example/opencensus => ../../example/opencensus
|
||||
|
||||
replace go.opentelemetry.io/otel/example/otel-collector => ../../example/otel-collector
|
||||
|
||||
replace go.opentelemetry.io/otel/example/prom-collector => ../../example/prom-collector
|
||||
|
||||
replace go.opentelemetry.io/otel/example/prometheus => ../../example/prometheus
|
||||
|
||||
replace go.opentelemetry.io/otel/example/zipkin => ../../example/zipkin
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../metric/prometheus
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/otlp => ./
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/stdout => ../stdout
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../trace/jaeger
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../trace/zipkin
|
||||
|
||||
replace go.opentelemetry.io/otel/internal/tools => ../../internal/tools
|
||||
|
||||
replace go.opentelemetry.io/otel/metric => ../../metric
|
||||
|
||||
replace go.opentelemetry.io/otel/oteltest => ../../oteltest
|
||||
|
||||
replace go.opentelemetry.io/otel/sdk/export/metric => ../../sdk/export/metric
|
||||
|
||||
replace go.opentelemetry.io/otel/sdk/metric => ../../sdk/metric
|
||||
|
||||
replace go.opentelemetry.io/otel/trace => ../../trace
|
123
vendor/go.opentelemetry.io/otel/exporters/otlp/go.sum
generated
vendored
Normal file
123
vendor/go.opentelemetry.io/otel/exporters/otlp/go.sum
generated
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||
github.com/benbjohnson/clock v1.0.3 h1:vkLuvpK4fmtSCuo60+yC63p7y0BmQ8gm5ZXGuBCJyXg=
|
||||
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0 h1:rwOQPCuKAKmwGKq2aVNnYIibI6wnV7EvzgfTCzcdGg8=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.37.0 h1:uSZWeQJX5j11bIQ4AJoj+McDBo29cY1MCoC1wO3ts+c=
|
||||
google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
196
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/envconfig.go
generated
vendored
Normal file
196
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/envconfig.go
generated
vendored
Normal file
@ -0,0 +1,196 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlpconfig
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
)
|
||||
|
||||
func ApplyGRPCEnvConfigs(cfg *Config) {
|
||||
e := EnvOptionsReader{
|
||||
GetEnv: os.Getenv,
|
||||
ReadFile: ioutil.ReadFile,
|
||||
}
|
||||
|
||||
e.ApplyGRPCEnvConfigs(cfg)
|
||||
}
|
||||
|
||||
func ApplyHTTPEnvConfigs(cfg *Config) {
|
||||
e := EnvOptionsReader{
|
||||
GetEnv: os.Getenv,
|
||||
ReadFile: ioutil.ReadFile,
|
||||
}
|
||||
|
||||
e.ApplyHTTPEnvConfigs(cfg)
|
||||
}
|
||||
|
||||
type EnvOptionsReader struct {
|
||||
GetEnv func(string) string
|
||||
ReadFile func(filename string) ([]byte, error)
|
||||
}
|
||||
|
||||
func (e *EnvOptionsReader) ApplyHTTPEnvConfigs(cfg *Config) {
|
||||
opts := e.GetOptionsFromEnv()
|
||||
for _, opt := range opts {
|
||||
opt.ApplyHTTPOption(cfg)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *EnvOptionsReader) ApplyGRPCEnvConfigs(cfg *Config) {
|
||||
opts := e.GetOptionsFromEnv()
|
||||
for _, opt := range opts {
|
||||
opt.ApplyGRPCOption(cfg)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *EnvOptionsReader) GetOptionsFromEnv() []GenericOption {
|
||||
var opts []GenericOption
|
||||
|
||||
// Endpoint
|
||||
if v, ok := e.getEnvValue("ENDPOINT"); ok {
|
||||
opts = append(opts, WithEndpoint(v))
|
||||
}
|
||||
if v, ok := e.getEnvValue("TRACES_ENDPOINT"); ok {
|
||||
opts = append(opts, WithTracesEndpoint(v))
|
||||
}
|
||||
if v, ok := e.getEnvValue("METRICS_ENDPOINT"); ok {
|
||||
opts = append(opts, WithMetricsEndpoint(v))
|
||||
}
|
||||
|
||||
// Certificate File
|
||||
if path, ok := e.getEnvValue("CERTIFICATE"); ok {
|
||||
if tls, err := e.readTLSConfig(path); err == nil {
|
||||
opts = append(opts, WithTLSClientConfig(tls))
|
||||
} else {
|
||||
otel.Handle(fmt.Errorf("failed to configure otlp exporter certificate '%s': %w", path, err))
|
||||
}
|
||||
}
|
||||
if path, ok := e.getEnvValue("TRACES_CERTIFICATE"); ok {
|
||||
if tls, err := e.readTLSConfig(path); err == nil {
|
||||
opts = append(opts, WithTracesTLSClientConfig(tls))
|
||||
} else {
|
||||
otel.Handle(fmt.Errorf("failed to configure otlp traces exporter certificate '%s': %w", path, err))
|
||||
}
|
||||
}
|
||||
if path, ok := e.getEnvValue("METRICS_CERTIFICATE"); ok {
|
||||
if tls, err := e.readTLSConfig(path); err == nil {
|
||||
opts = append(opts, WithMetricsTLSClientConfig(tls))
|
||||
} else {
|
||||
otel.Handle(fmt.Errorf("failed to configure otlp metrics exporter certificate '%s': %w", path, err))
|
||||
}
|
||||
}
|
||||
|
||||
// Headers
|
||||
if h, ok := e.getEnvValue("HEADERS"); ok {
|
||||
opts = append(opts, WithHeaders(stringToHeader(h)))
|
||||
}
|
||||
if h, ok := e.getEnvValue("TRACES_HEADERS"); ok {
|
||||
opts = append(opts, WithTracesHeaders(stringToHeader(h)))
|
||||
}
|
||||
if h, ok := e.getEnvValue("METRICS_HEADERS"); ok {
|
||||
opts = append(opts, WithMetricsHeaders(stringToHeader(h)))
|
||||
}
|
||||
|
||||
// Compression
|
||||
if c, ok := e.getEnvValue("COMPRESSION"); ok {
|
||||
opts = append(opts, WithCompression(stringToCompression(c)))
|
||||
}
|
||||
if c, ok := e.getEnvValue("TRACES_COMPRESSION"); ok {
|
||||
opts = append(opts, WithTracesCompression(stringToCompression(c)))
|
||||
}
|
||||
if c, ok := e.getEnvValue("METRICS_COMPRESSION"); ok {
|
||||
opts = append(opts, WithMetricsCompression(stringToCompression(c)))
|
||||
}
|
||||
|
||||
// Timeout
|
||||
if t, ok := e.getEnvValue("TIMEOUT"); ok {
|
||||
if d, err := strconv.Atoi(t); err == nil {
|
||||
opts = append(opts, WithTimeout(time.Duration(d)*time.Millisecond))
|
||||
}
|
||||
}
|
||||
if t, ok := e.getEnvValue("TRACES_TIMEOUT"); ok {
|
||||
if d, err := strconv.Atoi(t); err == nil {
|
||||
opts = append(opts, WithTracesTimeout(time.Duration(d)*time.Millisecond))
|
||||
}
|
||||
}
|
||||
if t, ok := e.getEnvValue("METRICS_TIMEOUT"); ok {
|
||||
if d, err := strconv.Atoi(t); err == nil {
|
||||
opts = append(opts, WithMetricsTimeout(time.Duration(d)*time.Millisecond))
|
||||
}
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
// getEnvValue gets an OTLP environment variable value of the specified key using the GetEnv function.
|
||||
// This function already prepends the OTLP prefix to all key lookup.
|
||||
func (e *EnvOptionsReader) getEnvValue(key string) (string, bool) {
|
||||
v := strings.TrimSpace(e.GetEnv(fmt.Sprintf("OTEL_EXPORTER_OTLP_%s", key)))
|
||||
return v, v != ""
|
||||
}
|
||||
|
||||
func (e *EnvOptionsReader) readTLSConfig(path string) (*tls.Config, error) {
|
||||
b, err := e.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return CreateTLSConfig(b)
|
||||
}
|
||||
|
||||
func stringToCompression(value string) otlp.Compression {
|
||||
switch value {
|
||||
case "gzip":
|
||||
return otlp.GzipCompression
|
||||
}
|
||||
|
||||
return otlp.NoCompression
|
||||
}
|
||||
|
||||
func stringToHeader(value string) map[string]string {
|
||||
headersPairs := strings.Split(value, ",")
|
||||
headers := make(map[string]string)
|
||||
|
||||
for _, header := range headersPairs {
|
||||
nameValue := strings.SplitN(header, "=", 2)
|
||||
if len(nameValue) < 2 {
|
||||
continue
|
||||
}
|
||||
name, err := url.QueryUnescape(nameValue[0])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
trimmedName := strings.TrimSpace(name)
|
||||
value, err := url.QueryUnescape(nameValue[1])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
trimmedValue := strings.TrimSpace(value)
|
||||
|
||||
headers[trimmedName] = trimmedValue
|
||||
}
|
||||
|
||||
return headers
|
||||
}
|
376
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/options.go
generated
vendored
Normal file
376
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/options.go
generated
vendored
Normal file
@ -0,0 +1,376 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig"
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultMaxAttempts describes how many times the driver
|
||||
// should retry the sending of the payload in case of a
|
||||
// retryable error.
|
||||
DefaultMaxAttempts int = 5
|
||||
// DefaultTracesPath is a default URL path for endpoint that
|
||||
// receives spans.
|
||||
DefaultTracesPath string = "/v1/traces"
|
||||
// DefaultMetricsPath is a default URL path for endpoint that
|
||||
// receives metrics.
|
||||
DefaultMetricsPath string = "/v1/metrics"
|
||||
// DefaultBackoff is a default base backoff time used in the
|
||||
// exponential backoff strategy.
|
||||
DefaultBackoff time.Duration = 300 * time.Millisecond
|
||||
// DefaultTimeout is a default max waiting time for the backend to process
|
||||
// each span or metrics batch.
|
||||
DefaultTimeout time.Duration = 10 * time.Second
|
||||
// DefaultServiceConfig is the gRPC service config used if none is
|
||||
// provided by the user.
|
||||
DefaultServiceConfig = `{
|
||||
"methodConfig":[{
|
||||
"name":[
|
||||
{ "service":"opentelemetry.proto.collector.metrics.v1.MetricsService" },
|
||||
{ "service":"opentelemetry.proto.collector.trace.v1.TraceService" }
|
||||
],
|
||||
"retryPolicy":{
|
||||
"MaxAttempts":5,
|
||||
"InitialBackoff":"0.3s",
|
||||
"MaxBackoff":"5s",
|
||||
"BackoffMultiplier":2,
|
||||
"RetryableStatusCodes":[
|
||||
"CANCELLED",
|
||||
"DEADLINE_EXCEEDED",
|
||||
"RESOURCE_EXHAUSTED",
|
||||
"ABORTED",
|
||||
"OUT_OF_RANGE",
|
||||
"UNAVAILABLE",
|
||||
"DATA_LOSS"
|
||||
]
|
||||
}
|
||||
}]
|
||||
}`
|
||||
)
|
||||
|
||||
type (
|
||||
SignalConfig struct {
|
||||
Endpoint string
|
||||
Insecure bool
|
||||
TLSCfg *tls.Config
|
||||
Headers map[string]string
|
||||
Compression otlp.Compression
|
||||
Timeout time.Duration
|
||||
URLPath string
|
||||
|
||||
// gRPC configurations
|
||||
GRPCCredentials credentials.TransportCredentials
|
||||
}
|
||||
|
||||
Config struct {
|
||||
// Signal specific configurations
|
||||
Metrics SignalConfig
|
||||
Traces SignalConfig
|
||||
|
||||
// General configurations
|
||||
MaxAttempts int
|
||||
Backoff time.Duration
|
||||
|
||||
// HTTP configuration
|
||||
Marshaler otlp.Marshaler
|
||||
|
||||
// gRPC configurations
|
||||
ReconnectionPeriod time.Duration
|
||||
ServiceConfig string
|
||||
DialOptions []grpc.DialOption
|
||||
}
|
||||
)
|
||||
|
||||
func NewDefaultConfig() Config {
|
||||
c := Config{
|
||||
Traces: SignalConfig{
|
||||
Endpoint: fmt.Sprintf("%s:%d", otlp.DefaultCollectorHost, otlp.DefaultCollectorPort),
|
||||
URLPath: DefaultTracesPath,
|
||||
Compression: otlp.NoCompression,
|
||||
Timeout: DefaultTimeout,
|
||||
},
|
||||
Metrics: SignalConfig{
|
||||
Endpoint: fmt.Sprintf("%s:%d", otlp.DefaultCollectorHost, otlp.DefaultCollectorPort),
|
||||
URLPath: DefaultMetricsPath,
|
||||
Compression: otlp.NoCompression,
|
||||
Timeout: DefaultTimeout,
|
||||
},
|
||||
MaxAttempts: DefaultMaxAttempts,
|
||||
Backoff: DefaultBackoff,
|
||||
ServiceConfig: DefaultServiceConfig,
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
type (
|
||||
// GenericOption applies an option to the HTTP or gRPC driver.
|
||||
GenericOption interface {
|
||||
ApplyHTTPOption(*Config)
|
||||
ApplyGRPCOption(*Config)
|
||||
|
||||
// A private method to prevent users implementing the
|
||||
// interface and so future additions to it will not
|
||||
// violate compatibility.
|
||||
private()
|
||||
}
|
||||
|
||||
// HTTPOption applies an option to the HTTP driver.
|
||||
HTTPOption interface {
|
||||
ApplyHTTPOption(*Config)
|
||||
|
||||
// A private method to prevent users implementing the
|
||||
// interface and so future additions to it will not
|
||||
// violate compatibility.
|
||||
private()
|
||||
}
|
||||
|
||||
// GRPCOption applies an option to the gRPC driver.
|
||||
GRPCOption interface {
|
||||
ApplyGRPCOption(*Config)
|
||||
|
||||
// A private method to prevent users implementing the
|
||||
// interface and so future additions to it will not
|
||||
// violate compatibility.
|
||||
private()
|
||||
}
|
||||
)
|
||||
|
||||
// genericOption is an option that applies the same logic
|
||||
// for both gRPC and HTTP.
|
||||
type genericOption struct {
|
||||
fn func(*Config)
|
||||
}
|
||||
|
||||
func (g *genericOption) ApplyGRPCOption(cfg *Config) {
|
||||
g.fn(cfg)
|
||||
}
|
||||
|
||||
func (g *genericOption) ApplyHTTPOption(cfg *Config) {
|
||||
g.fn(cfg)
|
||||
}
|
||||
|
||||
func (genericOption) private() {}
|
||||
|
||||
func newGenericOption(fn func(cfg *Config)) GenericOption {
|
||||
return &genericOption{fn: fn}
|
||||
}
|
||||
|
||||
// splitOption is an option that applies different logics
|
||||
// for gRPC and HTTP.
|
||||
type splitOption struct {
|
||||
httpFn func(*Config)
|
||||
grpcFn func(*Config)
|
||||
}
|
||||
|
||||
func (g *splitOption) ApplyGRPCOption(cfg *Config) {
|
||||
g.grpcFn(cfg)
|
||||
}
|
||||
|
||||
func (g *splitOption) ApplyHTTPOption(cfg *Config) {
|
||||
g.httpFn(cfg)
|
||||
}
|
||||
|
||||
func (splitOption) private() {}
|
||||
|
||||
func newSplitOption(httpFn func(cfg *Config), grpcFn func(cfg *Config)) GenericOption {
|
||||
return &splitOption{httpFn: httpFn, grpcFn: grpcFn}
|
||||
}
|
||||
|
||||
// httpOption is an option that is only applied to the HTTP driver.
|
||||
type httpOption struct {
|
||||
fn func(*Config)
|
||||
}
|
||||
|
||||
func (h *httpOption) ApplyHTTPOption(cfg *Config) {
|
||||
h.fn(cfg)
|
||||
}
|
||||
|
||||
func (httpOption) private() {}
|
||||
|
||||
func NewHTTPOption(fn func(cfg *Config)) HTTPOption {
|
||||
return &httpOption{fn: fn}
|
||||
}
|
||||
|
||||
// grpcOption is an option that is only applied to the gRPC driver.
|
||||
type grpcOption struct {
|
||||
fn func(*Config)
|
||||
}
|
||||
|
||||
func (h *grpcOption) ApplyGRPCOption(cfg *Config) {
|
||||
h.fn(cfg)
|
||||
}
|
||||
|
||||
func (grpcOption) private() {}
|
||||
|
||||
func NewGRPCOption(fn func(cfg *Config)) GRPCOption {
|
||||
return &grpcOption{fn: fn}
|
||||
}
|
||||
|
||||
// Generic Options
|
||||
|
||||
func WithEndpoint(endpoint string) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Traces.Endpoint = endpoint
|
||||
cfg.Metrics.Endpoint = endpoint
|
||||
})
|
||||
}
|
||||
|
||||
func WithTracesEndpoint(endpoint string) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Traces.Endpoint = endpoint
|
||||
})
|
||||
}
|
||||
|
||||
func WithMetricsEndpoint(endpoint string) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Metrics.Endpoint = endpoint
|
||||
})
|
||||
}
|
||||
|
||||
func WithCompression(compression otlp.Compression) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Traces.Compression = compression
|
||||
cfg.Metrics.Compression = compression
|
||||
})
|
||||
}
|
||||
|
||||
func WithTracesCompression(compression otlp.Compression) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Traces.Compression = compression
|
||||
})
|
||||
}
|
||||
|
||||
func WithMetricsCompression(compression otlp.Compression) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Metrics.Compression = compression
|
||||
})
|
||||
}
|
||||
|
||||
func WithTracesURLPath(urlPath string) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Traces.URLPath = urlPath
|
||||
})
|
||||
}
|
||||
|
||||
func WithMetricsURLPath(urlPath string) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Metrics.URLPath = urlPath
|
||||
})
|
||||
}
|
||||
|
||||
func WithMaxAttempts(maxAttempts int) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.MaxAttempts = maxAttempts
|
||||
})
|
||||
}
|
||||
|
||||
func WithBackoff(duration time.Duration) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Backoff = duration
|
||||
})
|
||||
}
|
||||
|
||||
func WithTLSClientConfig(tlsCfg *tls.Config) GenericOption {
|
||||
return newSplitOption(func(cfg *Config) {
|
||||
cfg.Traces.TLSCfg = tlsCfg.Clone()
|
||||
cfg.Metrics.TLSCfg = tlsCfg.Clone()
|
||||
}, func(cfg *Config) {
|
||||
cfg.Traces.GRPCCredentials = credentials.NewTLS(tlsCfg)
|
||||
cfg.Metrics.GRPCCredentials = credentials.NewTLS(tlsCfg)
|
||||
})
|
||||
}
|
||||
|
||||
func WithTracesTLSClientConfig(tlsCfg *tls.Config) GenericOption {
|
||||
return newSplitOption(func(cfg *Config) {
|
||||
cfg.Traces.TLSCfg = tlsCfg.Clone()
|
||||
}, func(cfg *Config) {
|
||||
cfg.Traces.GRPCCredentials = credentials.NewTLS(tlsCfg)
|
||||
})
|
||||
}
|
||||
|
||||
func WithMetricsTLSClientConfig(tlsCfg *tls.Config) GenericOption {
|
||||
return newSplitOption(func(cfg *Config) {
|
||||
cfg.Metrics.TLSCfg = tlsCfg.Clone()
|
||||
}, func(cfg *Config) {
|
||||
cfg.Metrics.GRPCCredentials = credentials.NewTLS(tlsCfg)
|
||||
})
|
||||
}
|
||||
|
||||
func WithInsecure() GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Traces.Insecure = true
|
||||
cfg.Metrics.Insecure = true
|
||||
})
|
||||
}
|
||||
|
||||
func WithInsecureTraces() GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Traces.Insecure = true
|
||||
})
|
||||
}
|
||||
|
||||
func WithInsecureMetrics() GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Metrics.Insecure = true
|
||||
})
|
||||
}
|
||||
|
||||
func WithHeaders(headers map[string]string) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Traces.Headers = headers
|
||||
cfg.Metrics.Headers = headers
|
||||
})
|
||||
}
|
||||
|
||||
func WithTracesHeaders(headers map[string]string) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Traces.Headers = headers
|
||||
})
|
||||
}
|
||||
|
||||
func WithMetricsHeaders(headers map[string]string) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Metrics.Headers = headers
|
||||
})
|
||||
}
|
||||
|
||||
func WithTimeout(duration time.Duration) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Traces.Timeout = duration
|
||||
cfg.Metrics.Timeout = duration
|
||||
})
|
||||
}
|
||||
|
||||
func WithTracesTimeout(duration time.Duration) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Traces.Timeout = duration
|
||||
})
|
||||
}
|
||||
|
||||
func WithMetricsTimeout(duration time.Duration) GenericOption {
|
||||
return newGenericOption(func(cfg *Config) {
|
||||
cfg.Metrics.Timeout = duration
|
||||
})
|
||||
}
|
69
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/tls.go
generated
vendored
Normal file
69
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig/tls.go
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlpconfig
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
const (
|
||||
WeakCertificate = `
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIBhzCCASygAwIBAgIRANHpHgAWeTnLZpTSxCKs0ggwCgYIKoZIzj0EAwIwEjEQ
|
||||
MA4GA1UEChMHb3RlbC1nbzAeFw0yMTA0MDExMzU5MDNaFw0yMTA0MDExNDU5MDNa
|
||||
MBIxEDAOBgNVBAoTB290ZWwtZ28wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAS9
|
||||
nWSkmPCxShxnp43F+PrOtbGV7sNfkbQ/kxzi9Ego0ZJdiXxkmv/C05QFddCW7Y0Z
|
||||
sJCLHGogQsYnWJBXUZOVo2MwYTAOBgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYI
|
||||
KwYBBQUHAwEwDAYDVR0TAQH/BAIwADAsBgNVHREEJTAjgglsb2NhbGhvc3SHEAAA
|
||||
AAAAAAAAAAAAAAAAAAGHBH8AAAEwCgYIKoZIzj0EAwIDSQAwRgIhANwZVVKvfvQ/
|
||||
1HXsTvgH+xTQswOwSSKYJ1cVHQhqK7ZbAiEAus8NxpTRnp5DiTMuyVmhVNPB+bVH
|
||||
Lhnm4N/QDk5rek0=
|
||||
-----END CERTIFICATE-----
|
||||
`
|
||||
WeakPrivateKey = `
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgN8HEXiXhvByrJ1zK
|
||||
SFT6Y2l2KqDWwWzKf+t4CyWrNKehRANCAAS9nWSkmPCxShxnp43F+PrOtbGV7sNf
|
||||
kbQ/kxzi9Ego0ZJdiXxkmv/C05QFddCW7Y0ZsJCLHGogQsYnWJBXUZOV
|
||||
-----END PRIVATE KEY-----
|
||||
`
|
||||
)
|
||||
|
||||
// ReadTLSConfigFromFile reads a PEM certificate file and creates
|
||||
// a tls.Config that will use this certifate to verify a server certificate.
|
||||
func ReadTLSConfigFromFile(path string) (*tls.Config, error) {
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return CreateTLSConfig(b)
|
||||
}
|
||||
|
||||
// CreateTLSConfig creates a tls.Config from a raw certificate bytes
|
||||
// to verify a server certificate.
|
||||
func CreateTLSConfig(certBytes []byte) (*tls.Config, error) {
|
||||
cp := x509.NewCertPool()
|
||||
if ok := cp.AppendCertsFromPEM(certBytes); !ok {
|
||||
return nil, errors.New("failed to append certificate to the cert pool")
|
||||
}
|
||||
|
||||
return &tls.Config{
|
||||
RootCAs: cp,
|
||||
}, nil
|
||||
}
|
141
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/attribute.go
generated
vendored
Normal file
141
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/attribute.go
generated
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package transform
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
|
||||
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
)
|
||||
|
||||
// Attributes transforms a slice of KeyValues into a slice of OTLP attribute key-values.
|
||||
func Attributes(attrs []attribute.KeyValue) []*commonpb.KeyValue {
|
||||
if len(attrs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
out := make([]*commonpb.KeyValue, 0, len(attrs))
|
||||
for _, kv := range attrs {
|
||||
out = append(out, toAttribute(kv))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// ResourceAttributes transforms a Resource into a slice of OTLP attribute key-values.
|
||||
func ResourceAttributes(resource *resource.Resource) []*commonpb.KeyValue {
|
||||
if resource.Len() == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
out := make([]*commonpb.KeyValue, 0, resource.Len())
|
||||
for iter := resource.Iter(); iter.Next(); {
|
||||
out = append(out, toAttribute(iter.Attribute()))
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func toAttribute(v attribute.KeyValue) *commonpb.KeyValue {
|
||||
result := &commonpb.KeyValue{
|
||||
Key: string(v.Key),
|
||||
Value: new(commonpb.AnyValue),
|
||||
}
|
||||
switch v.Value.Type() {
|
||||
case attribute.BOOL:
|
||||
result.Value.Value = &commonpb.AnyValue_BoolValue{
|
||||
BoolValue: v.Value.AsBool(),
|
||||
}
|
||||
case attribute.INT64:
|
||||
result.Value.Value = &commonpb.AnyValue_IntValue{
|
||||
IntValue: v.Value.AsInt64(),
|
||||
}
|
||||
case attribute.FLOAT64:
|
||||
result.Value.Value = &commonpb.AnyValue_DoubleValue{
|
||||
DoubleValue: v.Value.AsFloat64(),
|
||||
}
|
||||
case attribute.STRING:
|
||||
result.Value.Value = &commonpb.AnyValue_StringValue{
|
||||
StringValue: v.Value.AsString(),
|
||||
}
|
||||
case attribute.ARRAY:
|
||||
result.Value.Value = &commonpb.AnyValue_ArrayValue{
|
||||
ArrayValue: &commonpb.ArrayValue{
|
||||
Values: arrayValues(v),
|
||||
},
|
||||
}
|
||||
default:
|
||||
result.Value.Value = &commonpb.AnyValue_StringValue{
|
||||
StringValue: "INVALID",
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func arrayValues(kv attribute.KeyValue) []*commonpb.AnyValue {
|
||||
a := kv.Value.AsArray()
|
||||
aType := reflect.TypeOf(a)
|
||||
var valueFunc func(reflect.Value) *commonpb.AnyValue
|
||||
switch aType.Elem().Kind() {
|
||||
case reflect.Bool:
|
||||
valueFunc = func(v reflect.Value) *commonpb.AnyValue {
|
||||
return &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_BoolValue{
|
||||
BoolValue: v.Bool(),
|
||||
},
|
||||
}
|
||||
}
|
||||
case reflect.Int, reflect.Int64:
|
||||
valueFunc = func(v reflect.Value) *commonpb.AnyValue {
|
||||
return &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_IntValue{
|
||||
IntValue: v.Int(),
|
||||
},
|
||||
}
|
||||
}
|
||||
case reflect.Uintptr:
|
||||
valueFunc = func(v reflect.Value) *commonpb.AnyValue {
|
||||
return &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_IntValue{
|
||||
IntValue: int64(v.Uint()),
|
||||
},
|
||||
}
|
||||
}
|
||||
case reflect.Float64:
|
||||
valueFunc = func(v reflect.Value) *commonpb.AnyValue {
|
||||
return &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_DoubleValue{
|
||||
DoubleValue: v.Float(),
|
||||
},
|
||||
}
|
||||
}
|
||||
case reflect.String:
|
||||
valueFunc = func(v reflect.Value) *commonpb.AnyValue {
|
||||
return &commonpb.AnyValue{
|
||||
Value: &commonpb.AnyValue_StringValue{
|
||||
StringValue: v.String(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
results := make([]*commonpb.AnyValue, aType.Len())
|
||||
for i, aValue := 0, reflect.ValueOf(a); i < aValue.Len(); i++ {
|
||||
results[i] = valueFunc(aValue.Index(i))
|
||||
}
|
||||
return results
|
||||
}
|
31
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/instrumentation.go
generated
vendored
Normal file
31
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/instrumentation.go
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package transform
|
||||
|
||||
import (
|
||||
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
|
||||
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
)
|
||||
|
||||
func instrumentationLibrary(il instrumentation.Library) *commonpb.InstrumentationLibrary {
|
||||
if il == (instrumentation.Library{}) {
|
||||
return nil
|
||||
}
|
||||
return &commonpb.InstrumentationLibrary{
|
||||
Name: il.Name,
|
||||
Version: il.Version,
|
||||
}
|
||||
}
|
631
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/metric.go
generated
vendored
Normal file
631
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/metric.go
generated
vendored
Normal file
@ -0,0 +1,631 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package transform provides translations for opentelemetry-go concepts and
|
||||
// structures to otlp structures.
|
||||
package transform
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
|
||||
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"
|
||||
resourcepb "go.opentelemetry.io/proto/otlp/resource/v1"
|
||||
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrUnimplementedAgg is returned when a transformation of an unimplemented
|
||||
// aggregator is attempted.
|
||||
ErrUnimplementedAgg = errors.New("unimplemented aggregator")
|
||||
|
||||
// ErrIncompatibleAgg is returned when
|
||||
// aggregation.Kind implies an interface conversion that has
|
||||
// failed
|
||||
ErrIncompatibleAgg = errors.New("incompatible aggregation type")
|
||||
|
||||
// ErrUnknownValueType is returned when a transformation of an unknown value
|
||||
// is attempted.
|
||||
ErrUnknownValueType = errors.New("invalid value type")
|
||||
|
||||
// ErrContextCanceled is returned when a context cancellation halts a
|
||||
// transformation.
|
||||
ErrContextCanceled = errors.New("context canceled")
|
||||
|
||||
// ErrTransforming is returned when an unexected error is encoutered transforming.
|
||||
ErrTransforming = errors.New("transforming failed")
|
||||
)
|
||||
|
||||
// result is the product of transforming Records into OTLP Metrics.
|
||||
type result struct {
|
||||
Resource *resource.Resource
|
||||
InstrumentationLibrary instrumentation.Library
|
||||
Metric *metricpb.Metric
|
||||
Err error
|
||||
}
|
||||
|
||||
// toNanos returns the number of nanoseconds since the UNIX epoch.
|
||||
func toNanos(t time.Time) uint64 {
|
||||
if t.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return uint64(t.UnixNano())
|
||||
}
|
||||
|
||||
// CheckpointSet transforms all records contained in a checkpoint into
|
||||
// batched OTLP ResourceMetrics.
|
||||
func CheckpointSet(ctx context.Context, exportSelector export.ExportKindSelector, cps export.CheckpointSet, numWorkers uint) ([]*metricpb.ResourceMetrics, error) {
|
||||
records, errc := source(ctx, exportSelector, cps)
|
||||
|
||||
// Start a fixed number of goroutines to transform records.
|
||||
transformed := make(chan result)
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(int(numWorkers))
|
||||
for i := uint(0); i < numWorkers; i++ {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
transformer(ctx, exportSelector, records, transformed)
|
||||
}()
|
||||
}
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(transformed)
|
||||
}()
|
||||
|
||||
// Synchronously collect the transformed records and transmit.
|
||||
rms, err := sink(ctx, transformed)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// source is complete, check for any errors.
|
||||
if err := <-errc; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rms, nil
|
||||
}
|
||||
|
||||
// source starts a goroutine that sends each one of the Records yielded by
|
||||
// the CheckpointSet on the returned chan. Any error encoutered will be sent
|
||||
// on the returned error chan after seeding is complete.
|
||||
func source(ctx context.Context, exportSelector export.ExportKindSelector, cps export.CheckpointSet) (<-chan export.Record, <-chan error) {
|
||||
errc := make(chan error, 1)
|
||||
out := make(chan export.Record)
|
||||
// Seed records into process.
|
||||
go func() {
|
||||
defer close(out)
|
||||
// No select is needed since errc is buffered.
|
||||
errc <- cps.ForEach(exportSelector, func(r export.Record) error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ErrContextCanceled
|
||||
case out <- r:
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}()
|
||||
return out, errc
|
||||
}
|
||||
|
||||
// transformer transforms records read from the passed in chan into
|
||||
// OTLP Metrics which are sent on the out chan.
|
||||
func transformer(ctx context.Context, exportSelector export.ExportKindSelector, in <-chan export.Record, out chan<- result) {
|
||||
for r := range in {
|
||||
m, err := Record(exportSelector, r)
|
||||
// Propagate errors, but do not send empty results.
|
||||
if err == nil && m == nil {
|
||||
continue
|
||||
}
|
||||
res := result{
|
||||
Resource: r.Resource(),
|
||||
InstrumentationLibrary: instrumentation.Library{
|
||||
Name: r.Descriptor().InstrumentationName(),
|
||||
Version: r.Descriptor().InstrumentationVersion(),
|
||||
},
|
||||
Metric: m,
|
||||
Err: err,
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case out <- res:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sink collects transformed Records and batches them.
|
||||
//
|
||||
// Any errors encoutered transforming input will be reported with an
|
||||
// ErrTransforming as well as the completed ResourceMetrics. It is up to the
|
||||
// caller to handle any incorrect data in these ResourceMetrics.
|
||||
func sink(ctx context.Context, in <-chan result) ([]*metricpb.ResourceMetrics, error) {
|
||||
var errStrings []string
|
||||
|
||||
type resourceBatch struct {
|
||||
Resource *resourcepb.Resource
|
||||
// Group by instrumentation library name and then the MetricDescriptor.
|
||||
InstrumentationLibraryBatches map[instrumentation.Library]map[string]*metricpb.Metric
|
||||
}
|
||||
|
||||
// group by unique Resource string.
|
||||
grouped := make(map[attribute.Distinct]resourceBatch)
|
||||
for res := range in {
|
||||
if res.Err != nil {
|
||||
errStrings = append(errStrings, res.Err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
rID := res.Resource.Equivalent()
|
||||
rb, ok := grouped[rID]
|
||||
if !ok {
|
||||
rb = resourceBatch{
|
||||
Resource: Resource(res.Resource),
|
||||
InstrumentationLibraryBatches: make(map[instrumentation.Library]map[string]*metricpb.Metric),
|
||||
}
|
||||
grouped[rID] = rb
|
||||
}
|
||||
|
||||
mb, ok := rb.InstrumentationLibraryBatches[res.InstrumentationLibrary]
|
||||
if !ok {
|
||||
mb = make(map[string]*metricpb.Metric)
|
||||
rb.InstrumentationLibraryBatches[res.InstrumentationLibrary] = mb
|
||||
}
|
||||
|
||||
mID := res.Metric.GetName()
|
||||
m, ok := mb[mID]
|
||||
if !ok {
|
||||
mb[mID] = res.Metric
|
||||
continue
|
||||
}
|
||||
switch res.Metric.Data.(type) {
|
||||
case *metricpb.Metric_IntGauge:
|
||||
m.GetIntGauge().DataPoints = append(m.GetIntGauge().DataPoints, res.Metric.GetIntGauge().DataPoints...)
|
||||
case *metricpb.Metric_IntHistogram:
|
||||
m.GetIntHistogram().DataPoints = append(m.GetIntHistogram().DataPoints, res.Metric.GetIntHistogram().DataPoints...)
|
||||
case *metricpb.Metric_IntSum:
|
||||
m.GetIntSum().DataPoints = append(m.GetIntSum().DataPoints, res.Metric.GetIntSum().DataPoints...)
|
||||
case *metricpb.Metric_DoubleGauge:
|
||||
m.GetDoubleGauge().DataPoints = append(m.GetDoubleGauge().DataPoints, res.Metric.GetDoubleGauge().DataPoints...)
|
||||
case *metricpb.Metric_DoubleHistogram:
|
||||
m.GetDoubleHistogram().DataPoints = append(m.GetDoubleHistogram().DataPoints, res.Metric.GetDoubleHistogram().DataPoints...)
|
||||
case *metricpb.Metric_DoubleSum:
|
||||
m.GetDoubleSum().DataPoints = append(m.GetDoubleSum().DataPoints, res.Metric.GetDoubleSum().DataPoints...)
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
if len(grouped) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var rms []*metricpb.ResourceMetrics
|
||||
for _, rb := range grouped {
|
||||
rm := &metricpb.ResourceMetrics{Resource: rb.Resource}
|
||||
for il, mb := range rb.InstrumentationLibraryBatches {
|
||||
ilm := &metricpb.InstrumentationLibraryMetrics{
|
||||
Metrics: make([]*metricpb.Metric, 0, len(mb)),
|
||||
}
|
||||
if il != (instrumentation.Library{}) {
|
||||
ilm.InstrumentationLibrary = &commonpb.InstrumentationLibrary{
|
||||
Name: il.Name,
|
||||
Version: il.Version,
|
||||
}
|
||||
}
|
||||
for _, m := range mb {
|
||||
ilm.Metrics = append(ilm.Metrics, m)
|
||||
}
|
||||
rm.InstrumentationLibraryMetrics = append(rm.InstrumentationLibraryMetrics, ilm)
|
||||
}
|
||||
rms = append(rms, rm)
|
||||
}
|
||||
|
||||
// Report any transform errors.
|
||||
if len(errStrings) > 0 {
|
||||
return rms, fmt.Errorf("%w:\n -%s", ErrTransforming, strings.Join(errStrings, "\n -"))
|
||||
}
|
||||
return rms, nil
|
||||
}
|
||||
|
||||
// Record transforms a Record into an OTLP Metric. An ErrIncompatibleAgg
|
||||
// error is returned if the Record Aggregator is not supported.
|
||||
func Record(exportSelector export.ExportKindSelector, r export.Record) (*metricpb.Metric, error) {
|
||||
agg := r.Aggregation()
|
||||
switch agg.Kind() {
|
||||
case aggregation.MinMaxSumCountKind:
|
||||
mmsc, ok := agg.(aggregation.MinMaxSumCount)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg)
|
||||
}
|
||||
return minMaxSumCount(r, mmsc)
|
||||
|
||||
case aggregation.HistogramKind:
|
||||
h, ok := agg.(aggregation.Histogram)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg)
|
||||
}
|
||||
return histogramPoint(r, exportSelector.ExportKindFor(r.Descriptor(), aggregation.HistogramKind), h)
|
||||
|
||||
case aggregation.SumKind:
|
||||
s, ok := agg.(aggregation.Sum)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg)
|
||||
}
|
||||
sum, err := s.Sum()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return sumPoint(r, sum, r.StartTime(), r.EndTime(), exportSelector.ExportKindFor(r.Descriptor(), aggregation.SumKind), r.Descriptor().InstrumentKind().Monotonic())
|
||||
|
||||
case aggregation.LastValueKind:
|
||||
lv, ok := agg.(aggregation.LastValue)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg)
|
||||
}
|
||||
value, tm, err := lv.LastValue()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gaugePoint(r, value, time.Time{}, tm)
|
||||
|
||||
case aggregation.ExactKind:
|
||||
e, ok := agg.(aggregation.Points)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%w: %T", ErrIncompatibleAgg, agg)
|
||||
}
|
||||
pts, err := e.Points()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return gaugeArray(r, pts)
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: %T", ErrUnimplementedAgg, agg)
|
||||
}
|
||||
}
|
||||
|
||||
func gaugeArray(record export.Record, points []aggregation.Point) (*metricpb.Metric, error) {
|
||||
desc := record.Descriptor()
|
||||
labels := record.Labels()
|
||||
m := &metricpb.Metric{
|
||||
Name: desc.Name(),
|
||||
Description: desc.Description(),
|
||||
Unit: string(desc.Unit()),
|
||||
}
|
||||
|
||||
pbLabels := stringKeyValues(labels.Iter())
|
||||
|
||||
switch nk := desc.NumberKind(); nk {
|
||||
case number.Int64Kind:
|
||||
var pts []*metricpb.IntDataPoint
|
||||
for _, s := range points {
|
||||
pts = append(pts, &metricpb.IntDataPoint{
|
||||
Labels: pbLabels,
|
||||
StartTimeUnixNano: toNanos(record.StartTime()),
|
||||
TimeUnixNano: toNanos(record.EndTime()),
|
||||
Value: s.Number.CoerceToInt64(nk),
|
||||
})
|
||||
}
|
||||
m.Data = &metricpb.Metric_IntGauge{
|
||||
IntGauge: &metricpb.IntGauge{
|
||||
DataPoints: pts,
|
||||
},
|
||||
}
|
||||
|
||||
case number.Float64Kind:
|
||||
var pts []*metricpb.DoubleDataPoint
|
||||
for _, s := range points {
|
||||
pts = append(pts, &metricpb.DoubleDataPoint{
|
||||
Labels: pbLabels,
|
||||
StartTimeUnixNano: toNanos(record.StartTime()),
|
||||
TimeUnixNano: toNanos(record.EndTime()),
|
||||
Value: s.Number.CoerceToFloat64(nk),
|
||||
})
|
||||
}
|
||||
m.Data = &metricpb.Metric_DoubleGauge{
|
||||
DoubleGauge: &metricpb.DoubleGauge{
|
||||
DataPoints: pts,
|
||||
},
|
||||
}
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: %v", ErrUnknownValueType, nk)
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func gaugePoint(record export.Record, num number.Number, start, end time.Time) (*metricpb.Metric, error) {
|
||||
desc := record.Descriptor()
|
||||
labels := record.Labels()
|
||||
|
||||
m := &metricpb.Metric{
|
||||
Name: desc.Name(),
|
||||
Description: desc.Description(),
|
||||
Unit: string(desc.Unit()),
|
||||
}
|
||||
|
||||
switch n := desc.NumberKind(); n {
|
||||
case number.Int64Kind:
|
||||
m.Data = &metricpb.Metric_IntGauge{
|
||||
IntGauge: &metricpb.IntGauge{
|
||||
DataPoints: []*metricpb.IntDataPoint{
|
||||
{
|
||||
Value: num.CoerceToInt64(n),
|
||||
Labels: stringKeyValues(labels.Iter()),
|
||||
StartTimeUnixNano: toNanos(start),
|
||||
TimeUnixNano: toNanos(end),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
case number.Float64Kind:
|
||||
m.Data = &metricpb.Metric_DoubleGauge{
|
||||
DoubleGauge: &metricpb.DoubleGauge{
|
||||
DataPoints: []*metricpb.DoubleDataPoint{
|
||||
{
|
||||
Value: num.CoerceToFloat64(n),
|
||||
Labels: stringKeyValues(labels.Iter()),
|
||||
StartTimeUnixNano: toNanos(start),
|
||||
TimeUnixNano: toNanos(end),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: %v", ErrUnknownValueType, n)
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func exportKindToTemporality(ek export.ExportKind) metricpb.AggregationTemporality {
|
||||
switch ek {
|
||||
case export.DeltaExportKind:
|
||||
return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA
|
||||
case export.CumulativeExportKind:
|
||||
return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE
|
||||
}
|
||||
return metricpb.AggregationTemporality_AGGREGATION_TEMPORALITY_UNSPECIFIED
|
||||
}
|
||||
|
||||
func sumPoint(record export.Record, num number.Number, start, end time.Time, ek export.ExportKind, monotonic bool) (*metricpb.Metric, error) {
|
||||
desc := record.Descriptor()
|
||||
labels := record.Labels()
|
||||
|
||||
m := &metricpb.Metric{
|
||||
Name: desc.Name(),
|
||||
Description: desc.Description(),
|
||||
Unit: string(desc.Unit()),
|
||||
}
|
||||
|
||||
switch n := desc.NumberKind(); n {
|
||||
case number.Int64Kind:
|
||||
m.Data = &metricpb.Metric_IntSum{
|
||||
IntSum: &metricpb.IntSum{
|
||||
IsMonotonic: monotonic,
|
||||
AggregationTemporality: exportKindToTemporality(ek),
|
||||
DataPoints: []*metricpb.IntDataPoint{
|
||||
{
|
||||
Value: num.CoerceToInt64(n),
|
||||
Labels: stringKeyValues(labels.Iter()),
|
||||
StartTimeUnixNano: toNanos(start),
|
||||
TimeUnixNano: toNanos(end),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
case number.Float64Kind:
|
||||
m.Data = &metricpb.Metric_DoubleSum{
|
||||
DoubleSum: &metricpb.DoubleSum{
|
||||
IsMonotonic: monotonic,
|
||||
AggregationTemporality: exportKindToTemporality(ek),
|
||||
DataPoints: []*metricpb.DoubleDataPoint{
|
||||
{
|
||||
Value: num.CoerceToFloat64(n),
|
||||
Labels: stringKeyValues(labels.Iter()),
|
||||
StartTimeUnixNano: toNanos(start),
|
||||
TimeUnixNano: toNanos(end),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: %v", ErrUnknownValueType, n)
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// minMaxSumCountValue returns the values of the MinMaxSumCount Aggregator
|
||||
// as discrete values.
|
||||
func minMaxSumCountValues(a aggregation.MinMaxSumCount) (min, max, sum number.Number, count uint64, err error) {
|
||||
if min, err = a.Min(); err != nil {
|
||||
return
|
||||
}
|
||||
if max, err = a.Max(); err != nil {
|
||||
return
|
||||
}
|
||||
if sum, err = a.Sum(); err != nil {
|
||||
return
|
||||
}
|
||||
if count, err = a.Count(); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// minMaxSumCount transforms a MinMaxSumCount Aggregator into an OTLP Metric.
|
||||
func minMaxSumCount(record export.Record, a aggregation.MinMaxSumCount) (*metricpb.Metric, error) {
|
||||
desc := record.Descriptor()
|
||||
labels := record.Labels()
|
||||
min, max, sum, count, err := minMaxSumCountValues(a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m := &metricpb.Metric{
|
||||
Name: desc.Name(),
|
||||
Description: desc.Description(),
|
||||
Unit: string(desc.Unit()),
|
||||
}
|
||||
|
||||
buckets := []uint64{min.AsRaw(), max.AsRaw()}
|
||||
bounds := []float64{0.0, 100.0}
|
||||
|
||||
switch n := desc.NumberKind(); n {
|
||||
case number.Int64Kind:
|
||||
m.Data = &metricpb.Metric_IntHistogram{
|
||||
IntHistogram: &metricpb.IntHistogram{
|
||||
DataPoints: []*metricpb.IntHistogramDataPoint{
|
||||
{
|
||||
Sum: sum.CoerceToInt64(n),
|
||||
Labels: stringKeyValues(labels.Iter()),
|
||||
StartTimeUnixNano: toNanos(record.StartTime()),
|
||||
TimeUnixNano: toNanos(record.EndTime()),
|
||||
Count: uint64(count),
|
||||
BucketCounts: buckets,
|
||||
ExplicitBounds: bounds,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
case number.Float64Kind:
|
||||
m.Data = &metricpb.Metric_DoubleHistogram{
|
||||
DoubleHistogram: &metricpb.DoubleHistogram{
|
||||
DataPoints: []*metricpb.DoubleHistogramDataPoint{
|
||||
{
|
||||
Sum: sum.CoerceToFloat64(n),
|
||||
Labels: stringKeyValues(labels.Iter()),
|
||||
StartTimeUnixNano: toNanos(record.StartTime()),
|
||||
TimeUnixNano: toNanos(record.EndTime()),
|
||||
Count: uint64(count),
|
||||
BucketCounts: buckets,
|
||||
ExplicitBounds: bounds,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: %v", ErrUnknownValueType, n)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func histogramValues(a aggregation.Histogram) (boundaries []float64, counts []uint64, err error) {
|
||||
var buckets aggregation.Buckets
|
||||
if buckets, err = a.Histogram(); err != nil {
|
||||
return
|
||||
}
|
||||
boundaries, counts = buckets.Boundaries, buckets.Counts
|
||||
if len(counts) != len(boundaries)+1 {
|
||||
err = ErrTransforming
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// histogram transforms a Histogram Aggregator into an OTLP Metric.
|
||||
func histogramPoint(record export.Record, ek export.ExportKind, a aggregation.Histogram) (*metricpb.Metric, error) {
|
||||
desc := record.Descriptor()
|
||||
labels := record.Labels()
|
||||
boundaries, counts, err := histogramValues(a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
count, err := a.Count()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sum, err := a.Sum()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m := &metricpb.Metric{
|
||||
Name: desc.Name(),
|
||||
Description: desc.Description(),
|
||||
Unit: string(desc.Unit()),
|
||||
}
|
||||
switch n := desc.NumberKind(); n {
|
||||
case number.Int64Kind:
|
||||
m.Data = &metricpb.Metric_IntHistogram{
|
||||
IntHistogram: &metricpb.IntHistogram{
|
||||
AggregationTemporality: exportKindToTemporality(ek),
|
||||
DataPoints: []*metricpb.IntHistogramDataPoint{
|
||||
{
|
||||
Sum: sum.CoerceToInt64(n),
|
||||
Labels: stringKeyValues(labels.Iter()),
|
||||
StartTimeUnixNano: toNanos(record.StartTime()),
|
||||
TimeUnixNano: toNanos(record.EndTime()),
|
||||
Count: uint64(count),
|
||||
BucketCounts: counts,
|
||||
ExplicitBounds: boundaries,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
case number.Float64Kind:
|
||||
m.Data = &metricpb.Metric_DoubleHistogram{
|
||||
DoubleHistogram: &metricpb.DoubleHistogram{
|
||||
AggregationTemporality: exportKindToTemporality(ek),
|
||||
DataPoints: []*metricpb.DoubleHistogramDataPoint{
|
||||
{
|
||||
Sum: sum.CoerceToFloat64(n),
|
||||
Labels: stringKeyValues(labels.Iter()),
|
||||
StartTimeUnixNano: toNanos(record.StartTime()),
|
||||
TimeUnixNano: toNanos(record.EndTime()),
|
||||
Count: uint64(count),
|
||||
BucketCounts: counts,
|
||||
ExplicitBounds: boundaries,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("%w: %v", ErrUnknownValueType, n)
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// stringKeyValues transforms a label iterator into an OTLP StringKeyValues.
|
||||
func stringKeyValues(iter attribute.Iterator) []*commonpb.StringKeyValue {
|
||||
l := iter.Len()
|
||||
if l == 0 {
|
||||
return nil
|
||||
}
|
||||
result := make([]*commonpb.StringKeyValue, 0, l)
|
||||
for iter.Next() {
|
||||
kv := iter.Label()
|
||||
result = append(result, &commonpb.StringKeyValue{
|
||||
Key: string(kv.Key),
|
||||
Value: kv.Value.Emit(),
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
29
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/resource.go
generated
vendored
Normal file
29
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/resource.go
generated
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package transform
|
||||
|
||||
import (
|
||||
resourcepb "go.opentelemetry.io/proto/otlp/resource/v1"
|
||||
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
)
|
||||
|
||||
// Resource transforms a Resource into an OTLP Resource.
|
||||
func Resource(r *resource.Resource) *resourcepb.Resource {
|
||||
if r == nil {
|
||||
return nil
|
||||
}
|
||||
return &resourcepb.Resource{Attributes: ResourceAttributes(r)}
|
||||
}
|
218
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/span.go
generated
vendored
Normal file
218
vendor/go.opentelemetry.io/otel/exporters/otlp/internal/transform/span.go
generated
vendored
Normal file
@ -0,0 +1,218 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package transform
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
|
||||
|
||||
"go.opentelemetry.io/otel/sdk/instrumentation"
|
||||
tracesdk "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
const (
|
||||
maxMessageEventsPerSpan = 128
|
||||
)
|
||||
|
||||
// SpanData transforms a slice of SpanSnapshot into a slice of OTLP
|
||||
// ResourceSpans.
|
||||
func SpanData(sdl []*tracesdk.SpanSnapshot) []*tracepb.ResourceSpans {
|
||||
if len(sdl) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
rsm := make(map[attribute.Distinct]*tracepb.ResourceSpans)
|
||||
|
||||
type ilsKey struct {
|
||||
r attribute.Distinct
|
||||
il instrumentation.Library
|
||||
}
|
||||
ilsm := make(map[ilsKey]*tracepb.InstrumentationLibrarySpans)
|
||||
|
||||
var resources int
|
||||
for _, sd := range sdl {
|
||||
if sd == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
rKey := sd.Resource.Equivalent()
|
||||
iKey := ilsKey{
|
||||
r: rKey,
|
||||
il: sd.InstrumentationLibrary,
|
||||
}
|
||||
ils, iOk := ilsm[iKey]
|
||||
if !iOk {
|
||||
// Either the resource or instrumentation library were unknown.
|
||||
ils = &tracepb.InstrumentationLibrarySpans{
|
||||
InstrumentationLibrary: instrumentationLibrary(sd.InstrumentationLibrary),
|
||||
Spans: []*tracepb.Span{},
|
||||
}
|
||||
}
|
||||
ils.Spans = append(ils.Spans, span(sd))
|
||||
ilsm[iKey] = ils
|
||||
|
||||
rs, rOk := rsm[rKey]
|
||||
if !rOk {
|
||||
resources++
|
||||
// The resource was unknown.
|
||||
rs = &tracepb.ResourceSpans{
|
||||
Resource: Resource(sd.Resource),
|
||||
InstrumentationLibrarySpans: []*tracepb.InstrumentationLibrarySpans{ils},
|
||||
}
|
||||
rsm[rKey] = rs
|
||||
continue
|
||||
}
|
||||
|
||||
// The resource has been seen before. Check if the instrumentation
|
||||
// library lookup was unknown because if so we need to add it to the
|
||||
// ResourceSpans. Otherwise, the instrumentation library has already
|
||||
// been seen and the append we did above will be included it in the
|
||||
// InstrumentationLibrarySpans reference.
|
||||
if !iOk {
|
||||
rs.InstrumentationLibrarySpans = append(rs.InstrumentationLibrarySpans, ils)
|
||||
}
|
||||
}
|
||||
|
||||
// Transform the categorized map into a slice
|
||||
rss := make([]*tracepb.ResourceSpans, 0, resources)
|
||||
for _, rs := range rsm {
|
||||
rss = append(rss, rs)
|
||||
}
|
||||
return rss
|
||||
}
|
||||
|
||||
// span transforms a Span into an OTLP span.
|
||||
func span(sd *tracesdk.SpanSnapshot) *tracepb.Span {
|
||||
if sd == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
tid := sd.SpanContext.TraceID()
|
||||
sid := sd.SpanContext.SpanID()
|
||||
|
||||
s := &tracepb.Span{
|
||||
TraceId: tid[:],
|
||||
SpanId: sid[:],
|
||||
TraceState: sd.SpanContext.TraceState().String(),
|
||||
Status: status(sd.StatusCode, sd.StatusMessage),
|
||||
StartTimeUnixNano: uint64(sd.StartTime.UnixNano()),
|
||||
EndTimeUnixNano: uint64(sd.EndTime.UnixNano()),
|
||||
Links: links(sd.Links),
|
||||
Kind: spanKind(sd.SpanKind),
|
||||
Name: sd.Name,
|
||||
Attributes: Attributes(sd.Attributes),
|
||||
Events: spanEvents(sd.MessageEvents),
|
||||
DroppedAttributesCount: uint32(sd.DroppedAttributeCount),
|
||||
DroppedEventsCount: uint32(sd.DroppedMessageEventCount),
|
||||
DroppedLinksCount: uint32(sd.DroppedLinkCount),
|
||||
}
|
||||
|
||||
if psid := sd.Parent.SpanID(); psid.IsValid() {
|
||||
s.ParentSpanId = psid[:]
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// status transform a span code and message into an OTLP span status.
|
||||
func status(status codes.Code, message string) *tracepb.Status {
|
||||
var c tracepb.Status_StatusCode
|
||||
switch status {
|
||||
case codes.Error:
|
||||
c = tracepb.Status_STATUS_CODE_ERROR
|
||||
default:
|
||||
c = tracepb.Status_STATUS_CODE_OK
|
||||
}
|
||||
return &tracepb.Status{
|
||||
Code: c,
|
||||
Message: message,
|
||||
}
|
||||
}
|
||||
|
||||
// links transforms span Links to OTLP span links.
|
||||
func links(links []trace.Link) []*tracepb.Span_Link {
|
||||
if len(links) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
sl := make([]*tracepb.Span_Link, 0, len(links))
|
||||
for _, otLink := range links {
|
||||
// This redefinition is necessary to prevent otLink.*ID[:] copies
|
||||
// being reused -- in short we need a new otLink per iteration.
|
||||
otLink := otLink
|
||||
|
||||
tid := otLink.TraceID()
|
||||
sid := otLink.SpanID()
|
||||
|
||||
sl = append(sl, &tracepb.Span_Link{
|
||||
TraceId: tid[:],
|
||||
SpanId: sid[:],
|
||||
Attributes: Attributes(otLink.Attributes),
|
||||
})
|
||||
}
|
||||
return sl
|
||||
}
|
||||
|
||||
// spanEvents transforms span Events to an OTLP span events.
|
||||
func spanEvents(es []trace.Event) []*tracepb.Span_Event {
|
||||
if len(es) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
evCount := len(es)
|
||||
if evCount > maxMessageEventsPerSpan {
|
||||
evCount = maxMessageEventsPerSpan
|
||||
}
|
||||
events := make([]*tracepb.Span_Event, 0, evCount)
|
||||
messageEvents := 0
|
||||
|
||||
// Transform message events
|
||||
for _, e := range es {
|
||||
if messageEvents >= maxMessageEventsPerSpan {
|
||||
break
|
||||
}
|
||||
messageEvents++
|
||||
events = append(events,
|
||||
&tracepb.Span_Event{
|
||||
Name: e.Name,
|
||||
TimeUnixNano: uint64(e.Time.UnixNano()),
|
||||
Attributes: Attributes(e.Attributes),
|
||||
// TODO (rghetia) : Add Drop Counts when supported.
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return events
|
||||
}
|
||||
|
||||
// spanKind transforms a SpanKind to an OTLP span kind.
|
||||
func spanKind(kind trace.SpanKind) tracepb.Span_SpanKind {
|
||||
switch kind {
|
||||
case trace.SpanKindInternal:
|
||||
return tracepb.Span_SPAN_KIND_INTERNAL
|
||||
case trace.SpanKindClient:
|
||||
return tracepb.Span_SPAN_KIND_CLIENT
|
||||
case trace.SpanKindServer:
|
||||
return tracepb.Span_SPAN_KIND_SERVER
|
||||
case trace.SpanKindProducer:
|
||||
return tracepb.Span_SPAN_KIND_PRODUCER
|
||||
case trace.SpanKindConsumer:
|
||||
return tracepb.Span_SPAN_KIND_CONSUMER
|
||||
default:
|
||||
return tracepb.Span_SPAN_KIND_UNSPECIFIED
|
||||
}
|
||||
}
|
45
vendor/go.opentelemetry.io/otel/exporters/otlp/options.go
generated
vendored
Normal file
45
vendor/go.opentelemetry.io/otel/exporters/otlp/options.go
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlp // import "go.opentelemetry.io/otel/exporters/otlp"
|
||||
|
||||
import (
|
||||
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultCollectorPort is the port the Exporter will attempt connect to
|
||||
// if no collector port is provided.
|
||||
DefaultCollectorPort uint16 = 4317
|
||||
// DefaultCollectorHost is the host address the Exporter will attempt
|
||||
// connect to if no collector address is provided.
|
||||
DefaultCollectorHost string = "localhost"
|
||||
)
|
||||
|
||||
// ExporterOption are setting options passed to an Exporter on creation.
|
||||
type ExporterOption func(*config)
|
||||
|
||||
type config struct {
|
||||
exportKindSelector metricsdk.ExportKindSelector
|
||||
}
|
||||
|
||||
// WithMetricExportKindSelector defines the ExportKindSelector used
|
||||
// for selecting AggregationTemporality (i.e., Cumulative vs. Delta
|
||||
// aggregation). If not specified otherwise, exporter will use a
|
||||
// cumulative export kind selector.
|
||||
func WithMetricExportKindSelector(selector metricsdk.ExportKindSelector) ExporterOption {
|
||||
return func(cfg *config) {
|
||||
cfg.exportKindSelector = selector
|
||||
}
|
||||
}
|
38
vendor/go.opentelemetry.io/otel/exporters/otlp/optiontypes.go
generated
vendored
Normal file
38
vendor/go.opentelemetry.io/otel/exporters/otlp/optiontypes.go
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlp // import "go.opentelemetry.io/otel/exporters/otlp"
|
||||
|
||||
// Compression describes the compression used for payloads sent to the
|
||||
// collector.
|
||||
type Compression int
|
||||
|
||||
const (
|
||||
// NoCompression tells the driver to send payloads without
|
||||
// compression.
|
||||
NoCompression Compression = iota
|
||||
// GzipCompression tells the driver to send payloads after
|
||||
// compressing them with gzip.
|
||||
GzipCompression
|
||||
)
|
||||
|
||||
// Marshaler describes the kind of message format sent to the collector
|
||||
type Marshaler int
|
||||
|
||||
const (
|
||||
// MarshalProto tells the driver to send using the protobuf binary format.
|
||||
MarshalProto Marshaler = iota
|
||||
// MarshalJSON tells the driver to send using json format.
|
||||
MarshalJSON
|
||||
)
|
179
vendor/go.opentelemetry.io/otel/exporters/otlp/otlp.go
generated
vendored
Normal file
179
vendor/go.opentelemetry.io/otel/exporters/otlp/otlp.go
generated
vendored
Normal file
@ -0,0 +1,179 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlp // import "go.opentelemetry.io/otel/exporters/otlp"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregation"
|
||||
"go.opentelemetry.io/otel/sdk/metric/selector/simple"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
|
||||
"go.opentelemetry.io/otel/sdk/metric/controller/basic"
|
||||
processor "go.opentelemetry.io/otel/sdk/metric/processor/basic"
|
||||
tracesdk "go.opentelemetry.io/otel/sdk/trace"
|
||||
)
|
||||
|
||||
// Exporter is an OpenTelemetry exporter. It exports both traces and metrics
|
||||
// from OpenTelemetry instrumented to code using OpenTelemetry protocol
|
||||
// buffers to a configurable receiver.
|
||||
type Exporter struct {
|
||||
cfg config
|
||||
driver ProtocolDriver
|
||||
|
||||
mu sync.RWMutex
|
||||
started bool
|
||||
|
||||
startOnce sync.Once
|
||||
stopOnce sync.Once
|
||||
}
|
||||
|
||||
var _ tracesdk.SpanExporter = (*Exporter)(nil)
|
||||
var _ metricsdk.Exporter = (*Exporter)(nil)
|
||||
|
||||
// NewExporter constructs a new Exporter and starts it.
|
||||
func NewExporter(ctx context.Context, driver ProtocolDriver, opts ...ExporterOption) (*Exporter, error) {
|
||||
exp := NewUnstartedExporter(driver, opts...)
|
||||
if err := exp.Start(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return exp, nil
|
||||
}
|
||||
|
||||
// NewUnstartedExporter constructs a new Exporter and does not start it.
|
||||
func NewUnstartedExporter(driver ProtocolDriver, opts ...ExporterOption) *Exporter {
|
||||
cfg := config{
|
||||
// Note: the default ExportKindSelector is specified
|
||||
// as Cumulative:
|
||||
// https://github.com/open-telemetry/opentelemetry-specification/issues/731
|
||||
exportKindSelector: metricsdk.CumulativeExportKindSelector(),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(&cfg)
|
||||
}
|
||||
return &Exporter{
|
||||
cfg: cfg,
|
||||
driver: driver,
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
errAlreadyStarted = errors.New("already started")
|
||||
)
|
||||
|
||||
// Start establishes connections to the OpenTelemetry collector. Starting an
|
||||
// already started exporter returns an error.
|
||||
func (e *Exporter) Start(ctx context.Context) error {
|
||||
var err = errAlreadyStarted
|
||||
e.startOnce.Do(func() {
|
||||
e.mu.Lock()
|
||||
e.started = true
|
||||
e.mu.Unlock()
|
||||
err = e.driver.Start(ctx)
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Shutdown closes all connections and releases resources currently being used
|
||||
// by the exporter. If the exporter is not started this does nothing. A shut
|
||||
// down exporter can't be started again. Shutting down an already shut down
|
||||
// exporter does nothing.
|
||||
func (e *Exporter) Shutdown(ctx context.Context) error {
|
||||
e.mu.RLock()
|
||||
started := e.started
|
||||
e.mu.RUnlock()
|
||||
|
||||
if !started {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
e.stopOnce.Do(func() {
|
||||
err = e.driver.Stop(ctx)
|
||||
e.mu.Lock()
|
||||
e.started = false
|
||||
e.mu.Unlock()
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Export transforms and batches metric Records into OTLP Metrics and
|
||||
// transmits them to the configured collector.
|
||||
func (e *Exporter) Export(parent context.Context, cps metricsdk.CheckpointSet) error {
|
||||
return e.driver.ExportMetrics(parent, cps, e.cfg.exportKindSelector)
|
||||
}
|
||||
|
||||
// ExportKindFor reports back to the OpenTelemetry SDK sending this Exporter
|
||||
// metric telemetry that it needs to be provided in a configured format.
|
||||
func (e *Exporter) ExportKindFor(desc *metric.Descriptor, kind aggregation.Kind) metricsdk.ExportKind {
|
||||
return e.cfg.exportKindSelector.ExportKindFor(desc, kind)
|
||||
}
|
||||
|
||||
// ExportSpans transforms and batches trace SpanSnapshots into OTLP Trace and
|
||||
// transmits them to the configured collector.
|
||||
func (e *Exporter) ExportSpans(ctx context.Context, ss []*tracesdk.SpanSnapshot) error {
|
||||
return e.driver.ExportTraces(ctx, ss)
|
||||
}
|
||||
|
||||
// NewExportPipeline sets up a complete export pipeline
|
||||
// with the recommended TracerProvider setup.
|
||||
func NewExportPipeline(ctx context.Context, driver ProtocolDriver, exporterOpts ...ExporterOption) (*Exporter,
|
||||
*sdktrace.TracerProvider, *basic.Controller, error) {
|
||||
|
||||
exp, err := NewExporter(ctx, driver, exporterOpts...)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
tracerProvider := sdktrace.NewTracerProvider(
|
||||
sdktrace.WithBatcher(exp),
|
||||
)
|
||||
|
||||
cntr := basic.New(
|
||||
processor.New(
|
||||
simple.NewWithInexpensiveDistribution(),
|
||||
exp,
|
||||
),
|
||||
)
|
||||
|
||||
return exp, tracerProvider, cntr, nil
|
||||
}
|
||||
|
||||
// InstallNewPipeline instantiates a NewExportPipeline with the
|
||||
// recommended configuration and registers it globally.
|
||||
func InstallNewPipeline(ctx context.Context, driver ProtocolDriver, exporterOpts ...ExporterOption) (*Exporter,
|
||||
*sdktrace.TracerProvider, *basic.Controller, error) {
|
||||
|
||||
exp, tp, cntr, err := NewExportPipeline(ctx, driver, exporterOpts...)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
otel.SetTracerProvider(tp)
|
||||
err = cntr.Start(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
return exp, tp, cntr, err
|
||||
}
|
278
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/connection.go
generated
vendored
Normal file
278
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/connection.go
generated
vendored
Normal file
@ -0,0 +1,278 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlpgrpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"google.golang.org/grpc/encoding/gzip"
|
||||
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
type connection struct {
|
||||
// Ensure pointer is 64-bit aligned for atomic operations on both 32 and 64 bit machines.
|
||||
lastConnectErrPtr unsafe.Pointer
|
||||
|
||||
// mu protects the connection as it is accessed by the
|
||||
// exporter goroutines and background connection goroutine
|
||||
mu sync.Mutex
|
||||
cc *grpc.ClientConn
|
||||
|
||||
// these fields are read-only after constructor is finished
|
||||
cfg otlpconfig.Config
|
||||
sCfg otlpconfig.SignalConfig
|
||||
metadata metadata.MD
|
||||
newConnectionHandler func(cc *grpc.ClientConn)
|
||||
|
||||
// these channels are created once
|
||||
disconnectedCh chan bool
|
||||
backgroundConnectionDoneCh chan struct{}
|
||||
stopCh chan struct{}
|
||||
|
||||
// this is for tests, so they can replace the closing
|
||||
// routine without a worry of modifying some global variable
|
||||
// or changing it back to original after the test is done
|
||||
closeBackgroundConnectionDoneCh func(ch chan struct{})
|
||||
}
|
||||
|
||||
func newConnection(cfg otlpconfig.Config, sCfg otlpconfig.SignalConfig, handler func(cc *grpc.ClientConn)) *connection {
|
||||
c := new(connection)
|
||||
c.newConnectionHandler = handler
|
||||
c.cfg = cfg
|
||||
c.sCfg = sCfg
|
||||
if len(c.sCfg.Headers) > 0 {
|
||||
c.metadata = metadata.New(c.sCfg.Headers)
|
||||
}
|
||||
c.closeBackgroundConnectionDoneCh = func(ch chan struct{}) {
|
||||
close(ch)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *connection) startConnection(ctx context.Context) {
|
||||
c.stopCh = make(chan struct{})
|
||||
c.disconnectedCh = make(chan bool, 1)
|
||||
c.backgroundConnectionDoneCh = make(chan struct{})
|
||||
|
||||
if err := c.connect(ctx); err == nil {
|
||||
c.setStateConnected()
|
||||
} else {
|
||||
c.setStateDisconnected(err)
|
||||
}
|
||||
go c.indefiniteBackgroundConnection()
|
||||
}
|
||||
|
||||
func (c *connection) lastConnectError() error {
|
||||
errPtr := (*error)(atomic.LoadPointer(&c.lastConnectErrPtr))
|
||||
if errPtr == nil {
|
||||
return nil
|
||||
}
|
||||
return *errPtr
|
||||
}
|
||||
|
||||
func (c *connection) saveLastConnectError(err error) {
|
||||
var errPtr *error
|
||||
if err != nil {
|
||||
errPtr = &err
|
||||
}
|
||||
atomic.StorePointer(&c.lastConnectErrPtr, unsafe.Pointer(errPtr))
|
||||
}
|
||||
|
||||
func (c *connection) setStateDisconnected(err error) {
|
||||
c.saveLastConnectError(err)
|
||||
select {
|
||||
case c.disconnectedCh <- true:
|
||||
default:
|
||||
}
|
||||
c.newConnectionHandler(nil)
|
||||
}
|
||||
|
||||
func (c *connection) setStateConnected() {
|
||||
c.saveLastConnectError(nil)
|
||||
}
|
||||
|
||||
func (c *connection) connected() bool {
|
||||
return c.lastConnectError() == nil
|
||||
}
|
||||
|
||||
const defaultConnReattemptPeriod = 10 * time.Second
|
||||
|
||||
func (c *connection) indefiniteBackgroundConnection() {
|
||||
defer func() {
|
||||
c.closeBackgroundConnectionDoneCh(c.backgroundConnectionDoneCh)
|
||||
}()
|
||||
|
||||
connReattemptPeriod := c.cfg.ReconnectionPeriod
|
||||
if connReattemptPeriod <= 0 {
|
||||
connReattemptPeriod = defaultConnReattemptPeriod
|
||||
}
|
||||
|
||||
// No strong seeding required, nano time can
|
||||
// already help with pseudo uniqueness.
|
||||
rng := rand.New(rand.NewSource(time.Now().UnixNano() + rand.Int63n(1024)))
|
||||
|
||||
// maxJitterNanos: 70% of the connectionReattemptPeriod
|
||||
maxJitterNanos := int64(0.7 * float64(connReattemptPeriod))
|
||||
|
||||
for {
|
||||
// Otherwise these will be the normal scenarios to enable
|
||||
// reconnection if we trip out.
|
||||
// 1. If we've stopped, return entirely
|
||||
// 2. Otherwise block until we are disconnected, and
|
||||
// then retry connecting
|
||||
select {
|
||||
case <-c.stopCh:
|
||||
return
|
||||
|
||||
case <-c.disconnectedCh:
|
||||
// Quickly check if we haven't stopped at the
|
||||
// same time.
|
||||
select {
|
||||
case <-c.stopCh:
|
||||
return
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
// Normal scenario that we'll wait for
|
||||
}
|
||||
|
||||
if err := c.connect(context.Background()); err == nil {
|
||||
c.setStateConnected()
|
||||
} else {
|
||||
// this code is unreachable in most cases
|
||||
// c.connect does not establish connection
|
||||
c.setStateDisconnected(err)
|
||||
}
|
||||
|
||||
// Apply some jitter to avoid lockstep retrials of other
|
||||
// collector-exporters. Lockstep retrials could result in an
|
||||
// innocent DDOS, by clogging the machine's resources and network.
|
||||
jitter := time.Duration(rng.Int63n(maxJitterNanos))
|
||||
select {
|
||||
case <-c.stopCh:
|
||||
return
|
||||
case <-time.After(connReattemptPeriod + jitter):
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *connection) connect(ctx context.Context) error {
|
||||
cc, err := c.dialToCollector(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.setConnection(cc)
|
||||
c.newConnectionHandler(cc)
|
||||
return nil
|
||||
}
|
||||
|
||||
// setConnection sets cc as the client connection and returns true if
|
||||
// the connection state changed.
|
||||
func (c *connection) setConnection(cc *grpc.ClientConn) bool {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
// If previous clientConn is same as the current then just return.
|
||||
// This doesn't happen right now as this func is only called with new ClientConn.
|
||||
// It is more about future-proofing.
|
||||
if c.cc == cc {
|
||||
return false
|
||||
}
|
||||
|
||||
// If the previous clientConn was non-nil, close it
|
||||
if c.cc != nil {
|
||||
_ = c.cc.Close()
|
||||
}
|
||||
c.cc = cc
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *connection) dialToCollector(ctx context.Context) (*grpc.ClientConn, error) {
|
||||
dialOpts := []grpc.DialOption{}
|
||||
if c.cfg.ServiceConfig != "" {
|
||||
dialOpts = append(dialOpts, grpc.WithDefaultServiceConfig(c.cfg.ServiceConfig))
|
||||
}
|
||||
if c.sCfg.GRPCCredentials != nil {
|
||||
dialOpts = append(dialOpts, grpc.WithTransportCredentials(c.sCfg.GRPCCredentials))
|
||||
} else if c.sCfg.Insecure {
|
||||
dialOpts = append(dialOpts, grpc.WithInsecure())
|
||||
}
|
||||
if c.sCfg.Compression == otlp.GzipCompression {
|
||||
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name)))
|
||||
}
|
||||
if len(c.cfg.DialOptions) != 0 {
|
||||
dialOpts = append(dialOpts, c.cfg.DialOptions...)
|
||||
}
|
||||
|
||||
ctx, cancel := c.contextWithStop(ctx)
|
||||
defer cancel()
|
||||
ctx = c.contextWithMetadata(ctx)
|
||||
return grpc.DialContext(ctx, c.sCfg.Endpoint, dialOpts...)
|
||||
}
|
||||
|
||||
func (c *connection) contextWithMetadata(ctx context.Context) context.Context {
|
||||
if c.metadata.Len() > 0 {
|
||||
return metadata.NewOutgoingContext(ctx, c.metadata)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
func (c *connection) shutdown(ctx context.Context) error {
|
||||
close(c.stopCh)
|
||||
// Ensure that the backgroundConnector returns
|
||||
select {
|
||||
case <-c.backgroundConnectionDoneCh:
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
c.mu.Lock()
|
||||
cc := c.cc
|
||||
c.cc = nil
|
||||
c.mu.Unlock()
|
||||
|
||||
if cc != nil {
|
||||
return cc.Close()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *connection) contextWithStop(ctx context.Context) (context.Context, context.CancelFunc) {
|
||||
// Unify the parent context Done signal with the connection's
|
||||
// stop channel.
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
go func(ctx context.Context, cancel context.CancelFunc) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
// Nothing to do, either cancelled or deadline
|
||||
// happened.
|
||||
case <-c.stopCh:
|
||||
cancel()
|
||||
}
|
||||
}(ctx, cancel)
|
||||
return ctx, cancel
|
||||
}
|
25
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/doc.go
generated
vendored
Normal file
25
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/doc.go
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/*
|
||||
Package otlpgrpc provides an implementation of otlp.ProtocolDriver
|
||||
that connects to the collector and sends traces and metrics using
|
||||
gRPC.
|
||||
|
||||
This package is currently in a pre-GA phase. Backwards incompatible
|
||||
changes may be introduced in subsequent minor version releases as we
|
||||
work to track the evolving OpenTelemetry specification and user
|
||||
feedback.
|
||||
*/
|
||||
package otlpgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
|
195
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/driver.go
generated
vendored
Normal file
195
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/driver.go
generated
vendored
Normal file
@ -0,0 +1,195 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlpgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpgrpc"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/internal/transform"
|
||||
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
tracesdk "go.opentelemetry.io/otel/sdk/trace"
|
||||
colmetricpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
|
||||
coltracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
|
||||
metricpb "go.opentelemetry.io/proto/otlp/metrics/v1"
|
||||
tracepb "go.opentelemetry.io/proto/otlp/trace/v1"
|
||||
)
|
||||
|
||||
type driver struct {
|
||||
metricsDriver metricsDriver
|
||||
tracesDriver tracesDriver
|
||||
}
|
||||
|
||||
type metricsDriver struct {
|
||||
connection *connection
|
||||
|
||||
lock sync.Mutex
|
||||
metricsClient colmetricpb.MetricsServiceClient
|
||||
}
|
||||
|
||||
type tracesDriver struct {
|
||||
connection *connection
|
||||
|
||||
lock sync.Mutex
|
||||
tracesClient coltracepb.TraceServiceClient
|
||||
}
|
||||
|
||||
var (
|
||||
errNoClient = errors.New("no client")
|
||||
)
|
||||
|
||||
// NewDriver creates a new gRPC protocol driver.
|
||||
func NewDriver(opts ...Option) otlp.ProtocolDriver {
|
||||
cfg := otlpconfig.NewDefaultConfig()
|
||||
otlpconfig.ApplyGRPCEnvConfigs(&cfg)
|
||||
for _, opt := range opts {
|
||||
opt.ApplyGRPCOption(&cfg)
|
||||
}
|
||||
|
||||
d := &driver{}
|
||||
|
||||
d.tracesDriver = tracesDriver{
|
||||
connection: newConnection(cfg, cfg.Traces, d.tracesDriver.handleNewConnection),
|
||||
}
|
||||
|
||||
d.metricsDriver = metricsDriver{
|
||||
connection: newConnection(cfg, cfg.Metrics, d.metricsDriver.handleNewConnection),
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func (md *metricsDriver) handleNewConnection(cc *grpc.ClientConn) {
|
||||
md.lock.Lock()
|
||||
defer md.lock.Unlock()
|
||||
if cc != nil {
|
||||
md.metricsClient = colmetricpb.NewMetricsServiceClient(cc)
|
||||
} else {
|
||||
md.metricsClient = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (td *tracesDriver) handleNewConnection(cc *grpc.ClientConn) {
|
||||
td.lock.Lock()
|
||||
defer td.lock.Unlock()
|
||||
if cc != nil {
|
||||
td.tracesClient = coltracepb.NewTraceServiceClient(cc)
|
||||
} else {
|
||||
td.tracesClient = nil
|
||||
}
|
||||
}
|
||||
|
||||
// Start implements otlp.ProtocolDriver. It establishes a connection
|
||||
// to the collector.
|
||||
func (d *driver) Start(ctx context.Context) error {
|
||||
d.tracesDriver.connection.startConnection(ctx)
|
||||
d.metricsDriver.connection.startConnection(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop implements otlp.ProtocolDriver. It shuts down the connection
|
||||
// to the collector.
|
||||
func (d *driver) Stop(ctx context.Context) error {
|
||||
if err := d.tracesDriver.connection.shutdown(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return d.metricsDriver.connection.shutdown(ctx)
|
||||
}
|
||||
|
||||
// ExportMetrics implements otlp.ProtocolDriver. It transforms metrics
|
||||
// to protobuf binary format and sends the result to the collector.
|
||||
func (d *driver) ExportMetrics(ctx context.Context, cps metricsdk.CheckpointSet, selector metricsdk.ExportKindSelector) error {
|
||||
if !d.metricsDriver.connection.connected() {
|
||||
return fmt.Errorf("metrics exporter is disconnected from the server %s: %w", d.metricsDriver.connection.sCfg.Endpoint, d.metricsDriver.connection.lastConnectError())
|
||||
}
|
||||
ctx, cancel := d.metricsDriver.connection.contextWithStop(ctx)
|
||||
defer cancel()
|
||||
ctx, tCancel := context.WithTimeout(ctx, d.metricsDriver.connection.sCfg.Timeout)
|
||||
defer tCancel()
|
||||
|
||||
rms, err := transform.CheckpointSet(ctx, selector, cps, 1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(rms) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return d.metricsDriver.uploadMetrics(ctx, rms)
|
||||
}
|
||||
|
||||
func (md *metricsDriver) uploadMetrics(ctx context.Context, protoMetrics []*metricpb.ResourceMetrics) error {
|
||||
ctx = md.connection.contextWithMetadata(ctx)
|
||||
err := func() error {
|
||||
md.lock.Lock()
|
||||
defer md.lock.Unlock()
|
||||
if md.metricsClient == nil {
|
||||
return errNoClient
|
||||
}
|
||||
_, err := md.metricsClient.Export(ctx, &colmetricpb.ExportMetricsServiceRequest{
|
||||
ResourceMetrics: protoMetrics,
|
||||
})
|
||||
return err
|
||||
}()
|
||||
if err != nil {
|
||||
md.connection.setStateDisconnected(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// ExportTraces implements otlp.ProtocolDriver. It transforms spans to
|
||||
// protobuf binary format and sends the result to the collector.
|
||||
func (d *driver) ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error {
|
||||
if !d.tracesDriver.connection.connected() {
|
||||
return fmt.Errorf("traces exporter is disconnected from the server %s: %w", d.tracesDriver.connection.sCfg.Endpoint, d.tracesDriver.connection.lastConnectError())
|
||||
}
|
||||
ctx, cancel := d.tracesDriver.connection.contextWithStop(ctx)
|
||||
defer cancel()
|
||||
ctx, tCancel := context.WithTimeout(ctx, d.tracesDriver.connection.sCfg.Timeout)
|
||||
defer tCancel()
|
||||
|
||||
protoSpans := transform.SpanData(ss)
|
||||
if len(protoSpans) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return d.tracesDriver.uploadTraces(ctx, protoSpans)
|
||||
}
|
||||
|
||||
func (td *tracesDriver) uploadTraces(ctx context.Context, protoSpans []*tracepb.ResourceSpans) error {
|
||||
ctx = td.connection.contextWithMetadata(ctx)
|
||||
err := func() error {
|
||||
td.lock.Lock()
|
||||
defer td.lock.Unlock()
|
||||
if td.tracesClient == nil {
|
||||
return errNoClient
|
||||
}
|
||||
_, err := td.tracesClient.Export(ctx, &coltracepb.ExportTraceServiceRequest{
|
||||
ResourceSpans: protoSpans,
|
||||
})
|
||||
return err
|
||||
}()
|
||||
if err != nil {
|
||||
td.connection.setStateDisconnected(err)
|
||||
}
|
||||
return err
|
||||
}
|
202
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/options.go
generated
vendored
Normal file
202
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpgrpc/options.go
generated
vendored
Normal file
@ -0,0 +1,202 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlpgrpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/exporters/otlp"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/internal/otlpconfig"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
|
||||
// Option applies an option to the gRPC driver.
|
||||
type Option interface {
|
||||
otlpconfig.GRPCOption
|
||||
}
|
||||
|
||||
// WithInsecure disables client transport security for the exporter's gRPC connection
|
||||
// just like grpc.WithInsecure() https://pkg.go.dev/google.golang.org/grpc#WithInsecure
|
||||
// does. Note, by default, client security is required unless WithInsecure is used.
|
||||
func WithInsecure() Option {
|
||||
return otlpconfig.WithInsecure()
|
||||
}
|
||||
|
||||
// WithTracesInsecure disables client transport security for the traces exporter's gRPC connection
|
||||
// just like grpc.WithInsecure() https://pkg.go.dev/google.golang.org/grpc#WithInsecure
|
||||
// does. Note, by default, client security is required unless WithInsecure is used.
|
||||
func WithTracesInsecure() Option {
|
||||
return otlpconfig.WithInsecureTraces()
|
||||
}
|
||||
|
||||
// WithInsecureMetrics disables client transport security for the metrics exporter's gRPC connection
|
||||
// just like grpc.WithInsecure() https://pkg.go.dev/google.golang.org/grpc#WithInsecure
|
||||
// does. Note, by default, client security is required unless WithInsecure is used.
|
||||
func WithInsecureMetrics() Option {
|
||||
return otlpconfig.WithInsecureMetrics()
|
||||
}
|
||||
|
||||
// WithEndpoint allows one to set the endpoint that the exporter will
|
||||
// connect to the collector on. If unset, it will instead try to use
|
||||
// connect to DefaultCollectorHost:DefaultCollectorPort.
|
||||
func WithEndpoint(endpoint string) Option {
|
||||
return otlpconfig.WithEndpoint(endpoint)
|
||||
}
|
||||
|
||||
// WithTracesEndpoint allows one to set the traces endpoint that the exporter will
|
||||
// connect to the collector on. If unset, it will instead try to use
|
||||
// connect to DefaultCollectorHost:DefaultCollectorPort.
|
||||
func WithTracesEndpoint(endpoint string) Option {
|
||||
return otlpconfig.WithTracesEndpoint(endpoint)
|
||||
}
|
||||
|
||||
// WithMetricsEndpoint allows one to set the metrics endpoint that the exporter will
|
||||
// connect to the collector on. If unset, it will instead try to use
|
||||
// connect to DefaultCollectorHost:DefaultCollectorPort.
|
||||
func WithMetricsEndpoint(endpoint string) Option {
|
||||
return otlpconfig.WithMetricsEndpoint(endpoint)
|
||||
}
|
||||
|
||||
// WithReconnectionPeriod allows one to set the delay between next connection attempt
|
||||
// after failing to connect with the collector.
|
||||
func WithReconnectionPeriod(rp time.Duration) otlpconfig.GRPCOption {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.ReconnectionPeriod = rp
|
||||
})
|
||||
}
|
||||
|
||||
func compressorToCompression(compressor string) otlp.Compression {
|
||||
switch compressor {
|
||||
case "gzip":
|
||||
return otlp.GzipCompression
|
||||
}
|
||||
|
||||
otel.Handle(fmt.Errorf("invalid compression type: '%s', using no compression as default", compressor))
|
||||
return otlp.NoCompression
|
||||
}
|
||||
|
||||
// WithCompressor will set the compressor for the gRPC client to use when sending requests.
|
||||
// It is the responsibility of the caller to ensure that the compressor set has been registered
|
||||
// with google.golang.org/grpc/encoding. This can be done by encoding.RegisterCompressor. Some
|
||||
// compressors auto-register on import, such as gzip, which can be registered by calling
|
||||
// `import _ "google.golang.org/grpc/encoding/gzip"`.
|
||||
func WithCompressor(compressor string) Option {
|
||||
return otlpconfig.WithCompression(compressorToCompression(compressor))
|
||||
}
|
||||
|
||||
// WithTracesCompression will set the compressor for the gRPC client to use when sending traces requests.
|
||||
// It is the responsibility of the caller to ensure that the compressor set has been registered
|
||||
// with google.golang.org/grpc/encoding. This can be done by encoding.RegisterCompressor. Some
|
||||
// compressors auto-register on import, such as gzip, which can be registered by calling
|
||||
// `import _ "google.golang.org/grpc/encoding/gzip"`.
|
||||
func WithTracesCompression(compressor string) Option {
|
||||
return otlpconfig.WithTracesCompression(compressorToCompression(compressor))
|
||||
}
|
||||
|
||||
// WithMetricsCompression will set the compressor for the gRPC client to use when sending metrics requests.
|
||||
// It is the responsibility of the caller to ensure that the compressor set has been registered
|
||||
// with google.golang.org/grpc/encoding. This can be done by encoding.RegisterCompressor. Some
|
||||
// compressors auto-register on import, such as gzip, which can be registered by calling
|
||||
// `import _ "google.golang.org/grpc/encoding/gzip"`.
|
||||
func WithMetricsCompression(compressor string) Option {
|
||||
return otlpconfig.WithMetricsCompression(compressorToCompression(compressor))
|
||||
}
|
||||
|
||||
// WithHeaders will send the provided headers with gRPC requests.
|
||||
func WithHeaders(headers map[string]string) Option {
|
||||
return otlpconfig.WithHeaders(headers)
|
||||
}
|
||||
|
||||
// WithTracesHeaders will send the provided headers with gRPC traces requests.
|
||||
func WithTracesHeaders(headers map[string]string) Option {
|
||||
return otlpconfig.WithTracesHeaders(headers)
|
||||
}
|
||||
|
||||
// WithMetricsHeaders will send the provided headers with gRPC metrics requests.
|
||||
func WithMetricsHeaders(headers map[string]string) Option {
|
||||
return otlpconfig.WithMetricsHeaders(headers)
|
||||
}
|
||||
|
||||
// WithTLSCredentials allows the connection to use TLS credentials
|
||||
// when talking to the server. It takes in grpc.TransportCredentials instead
|
||||
// of say a Certificate file or a tls.Certificate, because the retrieving of
|
||||
// these credentials can be done in many ways e.g. plain file, in code tls.Config
|
||||
// or by certificate rotation, so it is up to the caller to decide what to use.
|
||||
func WithTLSCredentials(creds credentials.TransportCredentials) Option {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.Traces.GRPCCredentials = creds
|
||||
cfg.Metrics.GRPCCredentials = creds
|
||||
})
|
||||
}
|
||||
|
||||
// WithTracesTLSCredentials allows the connection to use TLS credentials
|
||||
// when talking to the traces server. It takes in grpc.TransportCredentials instead
|
||||
// of say a Certificate file or a tls.Certificate, because the retrieving of
|
||||
// these credentials can be done in many ways e.g. plain file, in code tls.Config
|
||||
// or by certificate rotation, so it is up to the caller to decide what to use.
|
||||
func WithTracesTLSCredentials(creds credentials.TransportCredentials) Option {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.Traces.GRPCCredentials = creds
|
||||
})
|
||||
}
|
||||
|
||||
// WithMetricsTLSCredentials allows the connection to use TLS credentials
|
||||
// when talking to the metrics server. It takes in grpc.TransportCredentials instead
|
||||
// of say a Certificate file or a tls.Certificate, because the retrieving of
|
||||
// these credentials can be done in many ways e.g. plain file, in code tls.Config
|
||||
// or by certificate rotation, so it is up to the caller to decide what to use.
|
||||
func WithMetricsTLSCredentials(creds credentials.TransportCredentials) Option {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.Metrics.GRPCCredentials = creds
|
||||
})
|
||||
}
|
||||
|
||||
// WithServiceConfig defines the default gRPC service config used.
|
||||
func WithServiceConfig(serviceConfig string) Option {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.ServiceConfig = serviceConfig
|
||||
})
|
||||
}
|
||||
|
||||
// WithDialOption opens support to any grpc.DialOption to be used. If it conflicts
|
||||
// with some other configuration the GRPC specified via the collector the ones here will
|
||||
// take preference since they are set last.
|
||||
func WithDialOption(opts ...grpc.DialOption) Option {
|
||||
return otlpconfig.NewGRPCOption(func(cfg *otlpconfig.Config) {
|
||||
cfg.DialOptions = opts
|
||||
})
|
||||
}
|
||||
|
||||
// WithTimeout tells the driver the max waiting time for the backend to process
|
||||
// each spans or metrics batch. If unset, the default will be 10 seconds.
|
||||
func WithTimeout(duration time.Duration) Option {
|
||||
return otlpconfig.WithTimeout(duration)
|
||||
}
|
||||
|
||||
// WithTracesTimeout tells the driver the max waiting time for the backend to process
|
||||
// each spans batch. If unset, the default will be 10 seconds.
|
||||
func WithTracesTimeout(duration time.Duration) Option {
|
||||
return otlpconfig.WithTracesTimeout(duration)
|
||||
}
|
||||
|
||||
// WithMetricsTimeout tells the driver the max waiting time for the backend to process
|
||||
// each metrics batch. If unset, the default will be 10 seconds.
|
||||
func WithMetricsTimeout(duration time.Duration) Option {
|
||||
return otlpconfig.WithMetricsTimeout(duration)
|
||||
}
|
145
vendor/go.opentelemetry.io/otel/exporters/otlp/protocoldriver.go
generated
vendored
Normal file
145
vendor/go.opentelemetry.io/otel/exporters/otlp/protocoldriver.go
generated
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otlp // import "go.opentelemetry.io/otel/exporters/otlp"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
metricsdk "go.opentelemetry.io/otel/sdk/export/metric"
|
||||
tracesdk "go.opentelemetry.io/otel/sdk/trace"
|
||||
)
|
||||
|
||||
// ProtocolDriver is an interface used by OTLP exporter. It's
|
||||
// responsible for connecting to and disconnecting from the collector,
|
||||
// and for transforming traces and metrics into wire format and
|
||||
// transmitting them to the collector.
|
||||
type ProtocolDriver interface {
|
||||
// Start should establish connection(s) to endpoint(s). It is
|
||||
// called just once by the exporter, so the implementation
|
||||
// does not need to worry about idempotence and locking.
|
||||
Start(ctx context.Context) error
|
||||
// Stop should close the connections. The function is called
|
||||
// only once by the exporter, so the implementation does not
|
||||
// need to worry about idempotence, but it may be called
|
||||
// concurrently with ExportMetrics or ExportTraces, so proper
|
||||
// locking is required. The function serves as a
|
||||
// synchronization point - after the function returns, the
|
||||
// process of closing connections is assumed to be finished.
|
||||
Stop(ctx context.Context) error
|
||||
// ExportMetrics should transform the passed metrics to the
|
||||
// wire format and send it to the collector. May be called
|
||||
// concurrently with ExportTraces, so the manager needs to
|
||||
// take this into account by doing proper locking.
|
||||
ExportMetrics(ctx context.Context, cps metricsdk.CheckpointSet, selector metricsdk.ExportKindSelector) error
|
||||
// ExportTraces should transform the passed traces to the wire
|
||||
// format and send it to the collector. May be called
|
||||
// concurrently with ExportMetrics, so the manager needs to
|
||||
// take this into account by doing proper locking.
|
||||
ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error
|
||||
}
|
||||
|
||||
// SplitConfig is used to configure a split driver.
|
||||
type SplitConfig struct {
|
||||
// ForMetrics driver will be used for sending metrics to the
|
||||
// collector.
|
||||
ForMetrics ProtocolDriver
|
||||
// ForTraces driver will be used for sending spans to the
|
||||
// collector.
|
||||
ForTraces ProtocolDriver
|
||||
}
|
||||
|
||||
type splitDriver struct {
|
||||
metric ProtocolDriver
|
||||
trace ProtocolDriver
|
||||
}
|
||||
|
||||
var _ ProtocolDriver = (*splitDriver)(nil)
|
||||
|
||||
// NewSplitDriver creates a protocol driver which contains two other
|
||||
// protocol drivers and will forward traces to one of them and metrics
|
||||
// to another.
|
||||
func NewSplitDriver(cfg SplitConfig) ProtocolDriver {
|
||||
return &splitDriver{
|
||||
metric: cfg.ForMetrics,
|
||||
trace: cfg.ForTraces,
|
||||
}
|
||||
}
|
||||
|
||||
// Start implements ProtocolDriver. It starts both drivers at the same
|
||||
// time.
|
||||
func (d *splitDriver) Start(ctx context.Context) error {
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(2)
|
||||
var (
|
||||
metricErr error
|
||||
traceErr error
|
||||
)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
metricErr = d.metric.Start(ctx)
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
traceErr = d.trace.Start(ctx)
|
||||
}()
|
||||
wg.Wait()
|
||||
if metricErr != nil {
|
||||
return metricErr
|
||||
}
|
||||
if traceErr != nil {
|
||||
return traceErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop implements ProtocolDriver. It stops both drivers at the same
|
||||
// time.
|
||||
func (d *splitDriver) Stop(ctx context.Context) error {
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(2)
|
||||
var (
|
||||
metricErr error
|
||||
traceErr error
|
||||
)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
metricErr = d.metric.Stop(ctx)
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
traceErr = d.trace.Stop(ctx)
|
||||
}()
|
||||
wg.Wait()
|
||||
if metricErr != nil {
|
||||
return metricErr
|
||||
}
|
||||
if traceErr != nil {
|
||||
return traceErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExportMetrics implements ProtocolDriver. It forwards the call to
|
||||
// the driver used for sending metrics.
|
||||
func (d *splitDriver) ExportMetrics(ctx context.Context, cps metricsdk.CheckpointSet, selector metricsdk.ExportKindSelector) error {
|
||||
return d.metric.ExportMetrics(ctx, cps, selector)
|
||||
}
|
||||
|
||||
// ExportTraces implements ProtocolDriver. It forwards the call to the
|
||||
// driver used for sending spans.
|
||||
func (d *splitDriver) ExportTraces(ctx context.Context, ss []*tracesdk.SpanSnapshot) error {
|
||||
return d.trace.ExportTraces(ctx, ss)
|
||||
}
|
41
vendor/go.opentelemetry.io/otel/get_main_pkgs.sh
generated
vendored
Normal file
41
vendor/go.opentelemetry.io/otel/get_main_pkgs.sh
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright The OpenTelemetry Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
top_dir='.'
|
||||
if [[ $# -gt 0 ]]; then
|
||||
top_dir="${1}"
|
||||
fi
|
||||
|
||||
p=$(pwd)
|
||||
mod_dirs=()
|
||||
|
||||
# Note `mapfile` does not exist in older bash versions:
|
||||
# https://stackoverflow.com/questions/41475261/need-alternative-to-readarray-mapfile-for-script-on-older-version-of-bash
|
||||
|
||||
while IFS= read -r line; do
|
||||
mod_dirs+=("$line")
|
||||
done < <(find "${top_dir}" -type f -name 'go.mod' -exec dirname {} \; | sort)
|
||||
|
||||
for mod_dir in "${mod_dirs[@]}"; do
|
||||
cd "${mod_dir}"
|
||||
|
||||
while IFS= read -r line; do
|
||||
echo ".${line#${p}}"
|
||||
done < <(go list --find -f '{{.Name}}|{{.Dir}}' ./... | grep '^main|' | cut -f 2- -d '|')
|
||||
cd "${p}"
|
||||
done
|
55
vendor/go.opentelemetry.io/otel/go.mod
generated
vendored
Normal file
55
vendor/go.opentelemetry.io/otel/go.mod
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
module go.opentelemetry.io/otel
|
||||
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.5.5
|
||||
github.com/stretchr/testify v1.7.0
|
||||
go.opentelemetry.io/otel/metric v0.20.0
|
||||
go.opentelemetry.io/otel/oteltest v0.20.0
|
||||
go.opentelemetry.io/otel/trace v0.20.0
|
||||
)
|
||||
|
||||
replace go.opentelemetry.io/otel => ./
|
||||
|
||||
replace go.opentelemetry.io/otel/bridge/opencensus => ./bridge/opencensus
|
||||
|
||||
replace go.opentelemetry.io/otel/bridge/opentracing => ./bridge/opentracing
|
||||
|
||||
replace go.opentelemetry.io/otel/example/jaeger => ./example/jaeger
|
||||
|
||||
replace go.opentelemetry.io/otel/example/namedtracer => ./example/namedtracer
|
||||
|
||||
replace go.opentelemetry.io/otel/example/opencensus => ./example/opencensus
|
||||
|
||||
replace go.opentelemetry.io/otel/example/otel-collector => ./example/otel-collector
|
||||
|
||||
replace go.opentelemetry.io/otel/example/prom-collector => ./example/prom-collector
|
||||
|
||||
replace go.opentelemetry.io/otel/example/prometheus => ./example/prometheus
|
||||
|
||||
replace go.opentelemetry.io/otel/example/zipkin => ./example/zipkin
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/metric/prometheus => ./exporters/metric/prometheus
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/otlp => ./exporters/otlp
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/stdout => ./exporters/stdout
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/trace/jaeger => ./exporters/trace/jaeger
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/trace/zipkin => ./exporters/trace/zipkin
|
||||
|
||||
replace go.opentelemetry.io/otel/internal/tools => ./internal/tools
|
||||
|
||||
replace go.opentelemetry.io/otel/sdk => ./sdk
|
||||
|
||||
replace go.opentelemetry.io/otel/metric => ./metric
|
||||
|
||||
replace go.opentelemetry.io/otel/oteltest => ./oteltest
|
||||
|
||||
replace go.opentelemetry.io/otel/sdk/export/metric => ./sdk/export/metric
|
||||
|
||||
replace go.opentelemetry.io/otel/sdk/metric => ./sdk/metric
|
||||
|
||||
replace go.opentelemetry.io/otel/trace => ./trace
|
15
vendor/go.opentelemetry.io/otel/go.sum
generated
vendored
Normal file
15
vendor/go.opentelemetry.io/otel/go.sum
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
89
vendor/go.opentelemetry.io/otel/handler.go
generated
vendored
Normal file
89
vendor/go.opentelemetry.io/otel/handler.go
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otel // import "go.opentelemetry.io/otel"
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
var (
|
||||
// globalErrorHandler provides an ErrorHandler that can be used
|
||||
// throughout an OpenTelemetry instrumented project. When a user
|
||||
// specified ErrorHandler is registered (`SetErrorHandler`) all calls to
|
||||
// `Handle` and will be delegated to the registered ErrorHandler.
|
||||
globalErrorHandler = &loggingErrorHandler{
|
||||
l: log.New(os.Stderr, "", log.LstdFlags),
|
||||
}
|
||||
|
||||
// delegateErrorHandlerOnce ensures that a user provided ErrorHandler is
|
||||
// only ever registered once.
|
||||
delegateErrorHandlerOnce sync.Once
|
||||
|
||||
// Comiple time check that loggingErrorHandler implements ErrorHandler.
|
||||
_ ErrorHandler = (*loggingErrorHandler)(nil)
|
||||
)
|
||||
|
||||
// loggingErrorHandler logs all errors to STDERR.
|
||||
type loggingErrorHandler struct {
|
||||
delegate atomic.Value
|
||||
|
||||
l *log.Logger
|
||||
}
|
||||
|
||||
// setDelegate sets the ErrorHandler delegate if one is not already set.
|
||||
func (h *loggingErrorHandler) setDelegate(d ErrorHandler) {
|
||||
if h.delegate.Load() != nil {
|
||||
// Delegate already registered
|
||||
return
|
||||
}
|
||||
h.delegate.Store(d)
|
||||
}
|
||||
|
||||
// Handle implements ErrorHandler.
|
||||
func (h *loggingErrorHandler) Handle(err error) {
|
||||
if d := h.delegate.Load(); d != nil {
|
||||
d.(ErrorHandler).Handle(err)
|
||||
return
|
||||
}
|
||||
h.l.Print(err)
|
||||
}
|
||||
|
||||
// GetErrorHandler returns the global ErrorHandler instance. If no ErrorHandler
|
||||
// instance has been set (`SetErrorHandler`), the default ErrorHandler which
|
||||
// logs errors to STDERR is returned.
|
||||
func GetErrorHandler() ErrorHandler {
|
||||
return globalErrorHandler
|
||||
}
|
||||
|
||||
// SetErrorHandler sets the global ErrorHandler to be h.
|
||||
func SetErrorHandler(h ErrorHandler) {
|
||||
delegateErrorHandlerOnce.Do(func() {
|
||||
current := GetErrorHandler()
|
||||
if current == h {
|
||||
return
|
||||
}
|
||||
if internalHandler, ok := current.(*loggingErrorHandler); ok {
|
||||
internalHandler.setDelegate(h)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Handle is a convience function for ErrorHandler().Handle(err)
|
||||
func Handle(err error) {
|
||||
GetErrorHandler().Handle(err)
|
||||
}
|
338
vendor/go.opentelemetry.io/otel/internal/baggage/baggage.go
generated
vendored
Normal file
338
vendor/go.opentelemetry.io/otel/internal/baggage/baggage.go
generated
vendored
Normal file
@ -0,0 +1,338 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package baggage provides types and functions to manage W3C Baggage.
|
||||
package baggage
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
)
|
||||
|
||||
type rawMap map[attribute.Key]attribute.Value
|
||||
type keySet map[attribute.Key]struct{}
|
||||
|
||||
// Map is an immutable storage for correlations.
|
||||
type Map struct {
|
||||
m rawMap
|
||||
}
|
||||
|
||||
// MapUpdate contains information about correlation changes to be
|
||||
// made.
|
||||
type MapUpdate struct {
|
||||
// DropSingleK contains a single key to be dropped from
|
||||
// correlations. Use this to avoid an overhead of a slice
|
||||
// allocation if there is only one key to drop.
|
||||
DropSingleK attribute.Key
|
||||
// DropMultiK contains all the keys to be dropped from
|
||||
// correlations.
|
||||
DropMultiK []attribute.Key
|
||||
|
||||
// SingleKV contains a single key-value pair to be added to
|
||||
// correlations. Use this to avoid an overhead of a slice
|
||||
// allocation if there is only one key-value pair to add.
|
||||
SingleKV attribute.KeyValue
|
||||
// MultiKV contains all the key-value pairs to be added to
|
||||
// correlations.
|
||||
MultiKV []attribute.KeyValue
|
||||
}
|
||||
|
||||
func newMap(raw rawMap) Map {
|
||||
return Map{
|
||||
m: raw,
|
||||
}
|
||||
}
|
||||
|
||||
// NewEmptyMap creates an empty correlations map.
|
||||
func NewEmptyMap() Map {
|
||||
return newMap(nil)
|
||||
}
|
||||
|
||||
// NewMap creates a map with the contents of the update applied. In
|
||||
// this function, having an update with DropSingleK or DropMultiK
|
||||
// makes no sense - those fields are effectively ignored.
|
||||
func NewMap(update MapUpdate) Map {
|
||||
return NewEmptyMap().Apply(update)
|
||||
}
|
||||
|
||||
// Apply creates a copy of the map with the contents of the update
|
||||
// applied. Apply will first drop the keys from DropSingleK and
|
||||
// DropMultiK, then add key-value pairs from SingleKV and MultiKV.
|
||||
func (m Map) Apply(update MapUpdate) Map {
|
||||
delSet, addSet := getModificationSets(update)
|
||||
mapSize := getNewMapSize(m.m, delSet, addSet)
|
||||
|
||||
r := make(rawMap, mapSize)
|
||||
for k, v := range m.m {
|
||||
// do not copy items we want to drop
|
||||
if _, ok := delSet[k]; ok {
|
||||
continue
|
||||
}
|
||||
// do not copy items we would overwrite
|
||||
if _, ok := addSet[k]; ok {
|
||||
continue
|
||||
}
|
||||
r[k] = v
|
||||
}
|
||||
if update.SingleKV.Key.Defined() {
|
||||
r[update.SingleKV.Key] = update.SingleKV.Value
|
||||
}
|
||||
for _, kv := range update.MultiKV {
|
||||
r[kv.Key] = kv.Value
|
||||
}
|
||||
if len(r) == 0 {
|
||||
r = nil
|
||||
}
|
||||
return newMap(r)
|
||||
}
|
||||
|
||||
func getModificationSets(update MapUpdate) (delSet, addSet keySet) {
|
||||
deletionsCount := len(update.DropMultiK)
|
||||
if update.DropSingleK.Defined() {
|
||||
deletionsCount++
|
||||
}
|
||||
if deletionsCount > 0 {
|
||||
delSet = make(map[attribute.Key]struct{}, deletionsCount)
|
||||
for _, k := range update.DropMultiK {
|
||||
delSet[k] = struct{}{}
|
||||
}
|
||||
if update.DropSingleK.Defined() {
|
||||
delSet[update.DropSingleK] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
additionsCount := len(update.MultiKV)
|
||||
if update.SingleKV.Key.Defined() {
|
||||
additionsCount++
|
||||
}
|
||||
if additionsCount > 0 {
|
||||
addSet = make(map[attribute.Key]struct{}, additionsCount)
|
||||
for _, k := range update.MultiKV {
|
||||
addSet[k.Key] = struct{}{}
|
||||
}
|
||||
if update.SingleKV.Key.Defined() {
|
||||
addSet[update.SingleKV.Key] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func getNewMapSize(m rawMap, delSet, addSet keySet) int {
|
||||
mapSizeDiff := 0
|
||||
for k := range addSet {
|
||||
if _, ok := m[k]; !ok {
|
||||
mapSizeDiff++
|
||||
}
|
||||
}
|
||||
for k := range delSet {
|
||||
if _, ok := m[k]; ok {
|
||||
if _, inAddSet := addSet[k]; !inAddSet {
|
||||
mapSizeDiff--
|
||||
}
|
||||
}
|
||||
}
|
||||
return len(m) + mapSizeDiff
|
||||
}
|
||||
|
||||
// Value gets a value from correlations map and returns a boolean
|
||||
// value indicating whether the key exist in the map.
|
||||
func (m Map) Value(k attribute.Key) (attribute.Value, bool) {
|
||||
value, ok := m.m[k]
|
||||
return value, ok
|
||||
}
|
||||
|
||||
// HasValue returns a boolean value indicating whether the key exist
|
||||
// in the map.
|
||||
func (m Map) HasValue(k attribute.Key) bool {
|
||||
_, has := m.Value(k)
|
||||
return has
|
||||
}
|
||||
|
||||
// Len returns a length of the map.
|
||||
func (m Map) Len() int {
|
||||
return len(m.m)
|
||||
}
|
||||
|
||||
// Foreach calls a passed callback once on each key-value pair until
|
||||
// all the key-value pairs of the map were iterated or the callback
|
||||
// returns false, whichever happens first.
|
||||
func (m Map) Foreach(f func(attribute.KeyValue) bool) {
|
||||
for k, v := range m.m {
|
||||
if !f(attribute.KeyValue{
|
||||
Key: k,
|
||||
Value: v,
|
||||
}) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type correlationsType struct{}
|
||||
|
||||
// SetHookFunc describes a type of a callback that is called when
|
||||
// storing baggage in the context.
|
||||
type SetHookFunc func(context.Context) context.Context
|
||||
|
||||
// GetHookFunc describes a type of a callback that is called when
|
||||
// getting baggage from the context.
|
||||
type GetHookFunc func(context.Context, Map) Map
|
||||
|
||||
// value under this key is either of type Map or correlationsData
|
||||
var correlationsKey = &correlationsType{}
|
||||
|
||||
type correlationsData struct {
|
||||
m Map
|
||||
setHook SetHookFunc
|
||||
getHook GetHookFunc
|
||||
}
|
||||
|
||||
func (d correlationsData) isHookless() bool {
|
||||
return d.setHook == nil && d.getHook == nil
|
||||
}
|
||||
|
||||
type hookKind int
|
||||
|
||||
const (
|
||||
hookKindSet hookKind = iota
|
||||
hookKindGet
|
||||
)
|
||||
|
||||
func (d *correlationsData) overrideHook(kind hookKind, setHook SetHookFunc, getHook GetHookFunc) {
|
||||
switch kind {
|
||||
case hookKindSet:
|
||||
d.setHook = setHook
|
||||
case hookKindGet:
|
||||
d.getHook = getHook
|
||||
}
|
||||
}
|
||||
|
||||
// ContextWithSetHook installs a hook function that will be invoked
|
||||
// every time ContextWithMap is called. To avoid unnecessary callback
|
||||
// invocations (recursive or not), the callback can temporarily clear
|
||||
// the hooks from the context with the ContextWithNoHooks function.
|
||||
//
|
||||
// Note that NewContext also calls ContextWithMap, so the hook will be
|
||||
// invoked.
|
||||
//
|
||||
// Passing nil SetHookFunc creates a context with no set hook to call.
|
||||
//
|
||||
// This function should not be used by applications or libraries. It
|
||||
// is mostly for interoperation with other observability APIs.
|
||||
func ContextWithSetHook(ctx context.Context, hook SetHookFunc) context.Context {
|
||||
return contextWithHook(ctx, hookKindSet, hook, nil)
|
||||
}
|
||||
|
||||
// ContextWithGetHook installs a hook function that will be invoked
|
||||
// every time MapFromContext is called. To avoid unnecessary callback
|
||||
// invocations (recursive or not), the callback can temporarily clear
|
||||
// the hooks from the context with the ContextWithNoHooks function.
|
||||
//
|
||||
// Note that NewContext also calls MapFromContext, so the hook will be
|
||||
// invoked.
|
||||
//
|
||||
// Passing nil GetHookFunc creates a context with no get hook to call.
|
||||
//
|
||||
// This function should not be used by applications or libraries. It
|
||||
// is mostly for interoperation with other observability APIs.
|
||||
func ContextWithGetHook(ctx context.Context, hook GetHookFunc) context.Context {
|
||||
return contextWithHook(ctx, hookKindGet, nil, hook)
|
||||
}
|
||||
|
||||
func contextWithHook(ctx context.Context, kind hookKind, setHook SetHookFunc, getHook GetHookFunc) context.Context {
|
||||
switch v := ctx.Value(correlationsKey).(type) {
|
||||
case correlationsData:
|
||||
v.overrideHook(kind, setHook, getHook)
|
||||
if v.isHookless() {
|
||||
return context.WithValue(ctx, correlationsKey, v.m)
|
||||
}
|
||||
return context.WithValue(ctx, correlationsKey, v)
|
||||
case Map:
|
||||
return contextWithOneHookAndMap(ctx, kind, setHook, getHook, v)
|
||||
default:
|
||||
m := NewEmptyMap()
|
||||
return contextWithOneHookAndMap(ctx, kind, setHook, getHook, m)
|
||||
}
|
||||
}
|
||||
|
||||
func contextWithOneHookAndMap(ctx context.Context, kind hookKind, setHook SetHookFunc, getHook GetHookFunc, m Map) context.Context {
|
||||
d := correlationsData{m: m}
|
||||
d.overrideHook(kind, setHook, getHook)
|
||||
if d.isHookless() {
|
||||
return ctx
|
||||
}
|
||||
return context.WithValue(ctx, correlationsKey, d)
|
||||
}
|
||||
|
||||
// ContextWithNoHooks creates a context with all the hooks
|
||||
// disabled. Also returns old set and get hooks. This function can be
|
||||
// used to temporarily clear the context from hooks and then reinstate
|
||||
// them by calling ContextWithSetHook and ContextWithGetHook functions
|
||||
// passing the hooks returned by this function.
|
||||
//
|
||||
// This function should not be used by applications or libraries. It
|
||||
// is mostly for interoperation with other observability APIs.
|
||||
func ContextWithNoHooks(ctx context.Context) (context.Context, SetHookFunc, GetHookFunc) {
|
||||
switch v := ctx.Value(correlationsKey).(type) {
|
||||
case correlationsData:
|
||||
return context.WithValue(ctx, correlationsKey, v.m), v.setHook, v.getHook
|
||||
default:
|
||||
return ctx, nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ContextWithMap returns a context with the Map entered into it.
|
||||
func ContextWithMap(ctx context.Context, m Map) context.Context {
|
||||
switch v := ctx.Value(correlationsKey).(type) {
|
||||
case correlationsData:
|
||||
v.m = m
|
||||
ctx = context.WithValue(ctx, correlationsKey, v)
|
||||
if v.setHook != nil {
|
||||
ctx = v.setHook(ctx)
|
||||
}
|
||||
return ctx
|
||||
default:
|
||||
return context.WithValue(ctx, correlationsKey, m)
|
||||
}
|
||||
}
|
||||
|
||||
// ContextWithNoCorrelationData returns a context stripped of correlation
|
||||
// data.
|
||||
func ContextWithNoCorrelationData(ctx context.Context) context.Context {
|
||||
return context.WithValue(ctx, correlationsKey, nil)
|
||||
}
|
||||
|
||||
// NewContext returns a context with the map from passed context
|
||||
// updated with the passed key-value pairs.
|
||||
func NewContext(ctx context.Context, keyvalues ...attribute.KeyValue) context.Context {
|
||||
return ContextWithMap(ctx, MapFromContext(ctx).Apply(MapUpdate{
|
||||
MultiKV: keyvalues,
|
||||
}))
|
||||
}
|
||||
|
||||
// MapFromContext gets the current Map from a Context.
|
||||
func MapFromContext(ctx context.Context) Map {
|
||||
switch v := ctx.Value(correlationsKey).(type) {
|
||||
case correlationsData:
|
||||
if v.getHook != nil {
|
||||
return v.getHook(ctx, v.m)
|
||||
}
|
||||
return v.m
|
||||
case Map:
|
||||
return v
|
||||
default:
|
||||
return NewEmptyMap()
|
||||
}
|
||||
}
|
348
vendor/go.opentelemetry.io/otel/internal/global/meter.go
generated
vendored
Normal file
348
vendor/go.opentelemetry.io/otel/internal/global/meter.go
generated
vendored
Normal file
@ -0,0 +1,348 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package global
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"unsafe"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/metric/registry"
|
||||
)
|
||||
|
||||
// This file contains the forwarding implementation of MeterProvider used as
|
||||
// the default global instance. Metric events using instruments provided by
|
||||
// this implementation are no-ops until the first Meter implementation is set
|
||||
// as the global provider.
|
||||
//
|
||||
// The implementation here uses Mutexes to maintain a list of active Meters in
|
||||
// the MeterProvider and Instruments in each Meter, under the assumption that
|
||||
// these interfaces are not performance-critical.
|
||||
//
|
||||
// We have the invariant that setDelegate() will be called before a new
|
||||
// MeterProvider implementation is registered as the global provider. Mutexes
|
||||
// in the MeterProvider and Meters ensure that each instrument has a delegate
|
||||
// before the global provider is set.
|
||||
//
|
||||
// Bound instrument operations are implemented by delegating to the
|
||||
// instrument after it is registered, with a sync.Once initializer to
|
||||
// protect against races with Release().
|
||||
//
|
||||
// Metric uniqueness checking is implemented by calling the exported
|
||||
// methods of the api/metric/registry package.
|
||||
|
||||
type meterKey struct {
|
||||
Name, Version string
|
||||
}
|
||||
|
||||
type meterProvider struct {
|
||||
delegate metric.MeterProvider
|
||||
|
||||
// lock protects `delegate` and `meters`.
|
||||
lock sync.Mutex
|
||||
|
||||
// meters maintains a unique entry for every named Meter
|
||||
// that has been registered through the global instance.
|
||||
meters map[meterKey]*meterEntry
|
||||
}
|
||||
|
||||
type meterImpl struct {
|
||||
delegate unsafe.Pointer // (*metric.MeterImpl)
|
||||
|
||||
lock sync.Mutex
|
||||
syncInsts []*syncImpl
|
||||
asyncInsts []*asyncImpl
|
||||
}
|
||||
|
||||
type meterEntry struct {
|
||||
unique metric.MeterImpl
|
||||
impl meterImpl
|
||||
}
|
||||
|
||||
type instrument struct {
|
||||
descriptor metric.Descriptor
|
||||
}
|
||||
|
||||
type syncImpl struct {
|
||||
delegate unsafe.Pointer // (*metric.SyncImpl)
|
||||
|
||||
instrument
|
||||
}
|
||||
|
||||
type asyncImpl struct {
|
||||
delegate unsafe.Pointer // (*metric.AsyncImpl)
|
||||
|
||||
instrument
|
||||
|
||||
runner metric.AsyncRunner
|
||||
}
|
||||
|
||||
// SyncImpler is implemented by all of the sync metric
|
||||
// instruments.
|
||||
type SyncImpler interface {
|
||||
SyncImpl() metric.SyncImpl
|
||||
}
|
||||
|
||||
// AsyncImpler is implemented by all of the async
|
||||
// metric instruments.
|
||||
type AsyncImpler interface {
|
||||
AsyncImpl() metric.AsyncImpl
|
||||
}
|
||||
|
||||
type syncHandle struct {
|
||||
delegate unsafe.Pointer // (*metric.BoundInstrumentImpl)
|
||||
|
||||
inst *syncImpl
|
||||
labels []attribute.KeyValue
|
||||
|
||||
initialize sync.Once
|
||||
}
|
||||
|
||||
var _ metric.MeterProvider = &meterProvider{}
|
||||
var _ metric.MeterImpl = &meterImpl{}
|
||||
var _ metric.InstrumentImpl = &syncImpl{}
|
||||
var _ metric.BoundSyncImpl = &syncHandle{}
|
||||
var _ metric.AsyncImpl = &asyncImpl{}
|
||||
|
||||
func (inst *instrument) Descriptor() metric.Descriptor {
|
||||
return inst.descriptor
|
||||
}
|
||||
|
||||
// MeterProvider interface and delegation
|
||||
|
||||
func newMeterProvider() *meterProvider {
|
||||
return &meterProvider{
|
||||
meters: map[meterKey]*meterEntry{},
|
||||
}
|
||||
}
|
||||
|
||||
func (p *meterProvider) setDelegate(provider metric.MeterProvider) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
p.delegate = provider
|
||||
for key, entry := range p.meters {
|
||||
entry.impl.setDelegate(key.Name, key.Version, provider)
|
||||
}
|
||||
p.meters = nil
|
||||
}
|
||||
|
||||
func (p *meterProvider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
if p.delegate != nil {
|
||||
return p.delegate.Meter(instrumentationName, opts...)
|
||||
}
|
||||
|
||||
key := meterKey{
|
||||
Name: instrumentationName,
|
||||
Version: metric.NewMeterConfig(opts...).InstrumentationVersion,
|
||||
}
|
||||
entry, ok := p.meters[key]
|
||||
if !ok {
|
||||
entry = &meterEntry{}
|
||||
entry.unique = registry.NewUniqueInstrumentMeterImpl(&entry.impl)
|
||||
p.meters[key] = entry
|
||||
|
||||
}
|
||||
return metric.WrapMeterImpl(entry.unique, key.Name, metric.WithInstrumentationVersion(key.Version))
|
||||
}
|
||||
|
||||
// Meter interface and delegation
|
||||
|
||||
func (m *meterImpl) setDelegate(name, version string, provider metric.MeterProvider) {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
|
||||
d := new(metric.MeterImpl)
|
||||
*d = provider.Meter(name, metric.WithInstrumentationVersion(version)).MeterImpl()
|
||||
m.delegate = unsafe.Pointer(d)
|
||||
|
||||
for _, inst := range m.syncInsts {
|
||||
inst.setDelegate(*d)
|
||||
}
|
||||
m.syncInsts = nil
|
||||
for _, obs := range m.asyncInsts {
|
||||
obs.setDelegate(*d)
|
||||
}
|
||||
m.asyncInsts = nil
|
||||
}
|
||||
|
||||
func (m *meterImpl) NewSyncInstrument(desc metric.Descriptor) (metric.SyncImpl, error) {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
|
||||
if meterPtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); meterPtr != nil {
|
||||
return (*meterPtr).NewSyncInstrument(desc)
|
||||
}
|
||||
|
||||
inst := &syncImpl{
|
||||
instrument: instrument{
|
||||
descriptor: desc,
|
||||
},
|
||||
}
|
||||
m.syncInsts = append(m.syncInsts, inst)
|
||||
return inst, nil
|
||||
}
|
||||
|
||||
// Synchronous delegation
|
||||
|
||||
func (inst *syncImpl) setDelegate(d metric.MeterImpl) {
|
||||
implPtr := new(metric.SyncImpl)
|
||||
|
||||
var err error
|
||||
*implPtr, err = d.NewSyncInstrument(inst.descriptor)
|
||||
|
||||
if err != nil {
|
||||
// TODO: There is no standard way to deliver this error to the user.
|
||||
// See https://github.com/open-telemetry/opentelemetry-go/issues/514
|
||||
// Note that the default SDK will not generate any errors yet, this is
|
||||
// only for added safety.
|
||||
panic(err)
|
||||
}
|
||||
|
||||
atomic.StorePointer(&inst.delegate, unsafe.Pointer(implPtr))
|
||||
}
|
||||
|
||||
func (inst *syncImpl) Implementation() interface{} {
|
||||
if implPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil {
|
||||
return (*implPtr).Implementation()
|
||||
}
|
||||
return inst
|
||||
}
|
||||
|
||||
func (inst *syncImpl) Bind(labels []attribute.KeyValue) metric.BoundSyncImpl {
|
||||
if implPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); implPtr != nil {
|
||||
return (*implPtr).Bind(labels)
|
||||
}
|
||||
return &syncHandle{
|
||||
inst: inst,
|
||||
labels: labels,
|
||||
}
|
||||
}
|
||||
|
||||
func (bound *syncHandle) Unbind() {
|
||||
bound.initialize.Do(func() {})
|
||||
|
||||
implPtr := (*metric.BoundSyncImpl)(atomic.LoadPointer(&bound.delegate))
|
||||
|
||||
if implPtr == nil {
|
||||
return
|
||||
}
|
||||
|
||||
(*implPtr).Unbind()
|
||||
}
|
||||
|
||||
// Async delegation
|
||||
|
||||
func (m *meterImpl) NewAsyncInstrument(
|
||||
desc metric.Descriptor,
|
||||
runner metric.AsyncRunner,
|
||||
) (metric.AsyncImpl, error) {
|
||||
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
|
||||
if meterPtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); meterPtr != nil {
|
||||
return (*meterPtr).NewAsyncInstrument(desc, runner)
|
||||
}
|
||||
|
||||
inst := &asyncImpl{
|
||||
instrument: instrument{
|
||||
descriptor: desc,
|
||||
},
|
||||
runner: runner,
|
||||
}
|
||||
m.asyncInsts = append(m.asyncInsts, inst)
|
||||
return inst, nil
|
||||
}
|
||||
|
||||
func (obs *asyncImpl) Implementation() interface{} {
|
||||
if implPtr := (*metric.AsyncImpl)(atomic.LoadPointer(&obs.delegate)); implPtr != nil {
|
||||
return (*implPtr).Implementation()
|
||||
}
|
||||
return obs
|
||||
}
|
||||
|
||||
func (obs *asyncImpl) setDelegate(d metric.MeterImpl) {
|
||||
implPtr := new(metric.AsyncImpl)
|
||||
|
||||
var err error
|
||||
*implPtr, err = d.NewAsyncInstrument(obs.descriptor, obs.runner)
|
||||
|
||||
if err != nil {
|
||||
// TODO: There is no standard way to deliver this error to the user.
|
||||
// See https://github.com/open-telemetry/opentelemetry-go/issues/514
|
||||
// Note that the default SDK will not generate any errors yet, this is
|
||||
// only for added safety.
|
||||
panic(err)
|
||||
}
|
||||
|
||||
atomic.StorePointer(&obs.delegate, unsafe.Pointer(implPtr))
|
||||
}
|
||||
|
||||
// Metric updates
|
||||
|
||||
func (m *meterImpl) RecordBatch(ctx context.Context, labels []attribute.KeyValue, measurements ...metric.Measurement) {
|
||||
if delegatePtr := (*metric.MeterImpl)(atomic.LoadPointer(&m.delegate)); delegatePtr != nil {
|
||||
(*delegatePtr).RecordBatch(ctx, labels, measurements...)
|
||||
}
|
||||
}
|
||||
|
||||
func (inst *syncImpl) RecordOne(ctx context.Context, number number.Number, labels []attribute.KeyValue) {
|
||||
if instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); instPtr != nil {
|
||||
(*instPtr).RecordOne(ctx, number, labels)
|
||||
}
|
||||
}
|
||||
|
||||
// Bound instrument initialization
|
||||
|
||||
func (bound *syncHandle) RecordOne(ctx context.Context, number number.Number) {
|
||||
instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&bound.inst.delegate))
|
||||
if instPtr == nil {
|
||||
return
|
||||
}
|
||||
var implPtr *metric.BoundSyncImpl
|
||||
bound.initialize.Do(func() {
|
||||
implPtr = new(metric.BoundSyncImpl)
|
||||
*implPtr = (*instPtr).Bind(bound.labels)
|
||||
atomic.StorePointer(&bound.delegate, unsafe.Pointer(implPtr))
|
||||
})
|
||||
if implPtr == nil {
|
||||
implPtr = (*metric.BoundSyncImpl)(atomic.LoadPointer(&bound.delegate))
|
||||
}
|
||||
// This may still be nil if instrument was created and bound
|
||||
// without a delegate, then the instrument was set to have a
|
||||
// delegate and unbound.
|
||||
if implPtr == nil {
|
||||
return
|
||||
}
|
||||
(*implPtr).RecordOne(ctx, number)
|
||||
}
|
||||
|
||||
func AtomicFieldOffsets() map[string]uintptr {
|
||||
return map[string]uintptr{
|
||||
"meterProvider.delegate": unsafe.Offsetof(meterProvider{}.delegate),
|
||||
"meterImpl.delegate": unsafe.Offsetof(meterImpl{}.delegate),
|
||||
"syncImpl.delegate": unsafe.Offsetof(syncImpl{}.delegate),
|
||||
"asyncImpl.delegate": unsafe.Offsetof(asyncImpl{}.delegate),
|
||||
"syncHandle.delegate": unsafe.Offsetof(syncHandle{}.delegate),
|
||||
}
|
||||
}
|
82
vendor/go.opentelemetry.io/otel/internal/global/propagator.go
generated
vendored
Normal file
82
vendor/go.opentelemetry.io/otel/internal/global/propagator.go
generated
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package global
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
)
|
||||
|
||||
// textMapPropagator is a default TextMapPropagator that delegates calls to a
|
||||
// registered delegate if one is set, otherwise it defaults to delegating the
|
||||
// calls to a the default no-op propagation.TextMapPropagator.
|
||||
type textMapPropagator struct {
|
||||
mtx sync.Mutex
|
||||
once sync.Once
|
||||
delegate propagation.TextMapPropagator
|
||||
noop propagation.TextMapPropagator
|
||||
}
|
||||
|
||||
// Compile-time guarantee that textMapPropagator implements the
|
||||
// propagation.TextMapPropagator interface.
|
||||
var _ propagation.TextMapPropagator = (*textMapPropagator)(nil)
|
||||
|
||||
func newTextMapPropagator() *textMapPropagator {
|
||||
return &textMapPropagator{
|
||||
noop: propagation.NewCompositeTextMapPropagator(),
|
||||
}
|
||||
}
|
||||
|
||||
// SetDelegate sets a delegate propagation.TextMapPropagator that all calls are
|
||||
// forwarded to. Delegation can only be performed once, all subsequent calls
|
||||
// perform no delegation.
|
||||
func (p *textMapPropagator) SetDelegate(delegate propagation.TextMapPropagator) {
|
||||
if delegate == nil {
|
||||
return
|
||||
}
|
||||
|
||||
p.mtx.Lock()
|
||||
p.once.Do(func() { p.delegate = delegate })
|
||||
p.mtx.Unlock()
|
||||
}
|
||||
|
||||
// effectiveDelegate returns the current delegate of p if one is set,
|
||||
// otherwise the default noop TextMapPropagator is returned. This method
|
||||
// can be called concurrently.
|
||||
func (p *textMapPropagator) effectiveDelegate() propagation.TextMapPropagator {
|
||||
p.mtx.Lock()
|
||||
defer p.mtx.Unlock()
|
||||
if p.delegate != nil {
|
||||
return p.delegate
|
||||
}
|
||||
return p.noop
|
||||
}
|
||||
|
||||
// Inject set cross-cutting concerns from the Context into the carrier.
|
||||
func (p *textMapPropagator) Inject(ctx context.Context, carrier propagation.TextMapCarrier) {
|
||||
p.effectiveDelegate().Inject(ctx, carrier)
|
||||
}
|
||||
|
||||
// Extract reads cross-cutting concerns from the carrier into a Context.
|
||||
func (p *textMapPropagator) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context {
|
||||
return p.effectiveDelegate().Extract(ctx, carrier)
|
||||
}
|
||||
|
||||
// Fields returns the keys whose values are set with Inject.
|
||||
func (p *textMapPropagator) Fields() []string {
|
||||
return p.effectiveDelegate().Fields()
|
||||
}
|
143
vendor/go.opentelemetry.io/otel/internal/global/state.go
generated
vendored
Normal file
143
vendor/go.opentelemetry.io/otel/internal/global/state.go
generated
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package global
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
type (
|
||||
tracerProviderHolder struct {
|
||||
tp trace.TracerProvider
|
||||
}
|
||||
|
||||
meterProviderHolder struct {
|
||||
mp metric.MeterProvider
|
||||
}
|
||||
|
||||
propagatorsHolder struct {
|
||||
tm propagation.TextMapPropagator
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
globalTracer = defaultTracerValue()
|
||||
globalMeter = defaultMeterValue()
|
||||
globalPropagators = defaultPropagatorsValue()
|
||||
|
||||
delegateMeterOnce sync.Once
|
||||
delegateTraceOnce sync.Once
|
||||
delegateTextMapPropagatorOnce sync.Once
|
||||
)
|
||||
|
||||
// TracerProvider is the internal implementation for global.TracerProvider.
|
||||
func TracerProvider() trace.TracerProvider {
|
||||
return globalTracer.Load().(tracerProviderHolder).tp
|
||||
}
|
||||
|
||||
// SetTracerProvider is the internal implementation for global.SetTracerProvider.
|
||||
func SetTracerProvider(tp trace.TracerProvider) {
|
||||
delegateTraceOnce.Do(func() {
|
||||
current := TracerProvider()
|
||||
if current == tp {
|
||||
// Setting the provider to the prior default is nonsense, panic.
|
||||
// Panic is acceptable because we are likely still early in the
|
||||
// process lifetime.
|
||||
panic("invalid TracerProvider, the global instance cannot be reinstalled")
|
||||
} else if def, ok := current.(*tracerProvider); ok {
|
||||
def.setDelegate(tp)
|
||||
}
|
||||
|
||||
})
|
||||
globalTracer.Store(tracerProviderHolder{tp: tp})
|
||||
}
|
||||
|
||||
// MeterProvider is the internal implementation for global.MeterProvider.
|
||||
func MeterProvider() metric.MeterProvider {
|
||||
return globalMeter.Load().(meterProviderHolder).mp
|
||||
}
|
||||
|
||||
// SetMeterProvider is the internal implementation for global.SetMeterProvider.
|
||||
func SetMeterProvider(mp metric.MeterProvider) {
|
||||
delegateMeterOnce.Do(func() {
|
||||
current := MeterProvider()
|
||||
|
||||
if current == mp {
|
||||
// Setting the provider to the prior default is nonsense, panic.
|
||||
// Panic is acceptable because we are likely still early in the
|
||||
// process lifetime.
|
||||
panic("invalid MeterProvider, the global instance cannot be reinstalled")
|
||||
} else if def, ok := current.(*meterProvider); ok {
|
||||
def.setDelegate(mp)
|
||||
}
|
||||
})
|
||||
globalMeter.Store(meterProviderHolder{mp: mp})
|
||||
}
|
||||
|
||||
// TextMapPropagator is the internal implementation for global.TextMapPropagator.
|
||||
func TextMapPropagator() propagation.TextMapPropagator {
|
||||
return globalPropagators.Load().(propagatorsHolder).tm
|
||||
}
|
||||
|
||||
// SetTextMapPropagator is the internal implementation for global.SetTextMapPropagator.
|
||||
func SetTextMapPropagator(p propagation.TextMapPropagator) {
|
||||
// For the textMapPropagator already returned by TextMapPropagator
|
||||
// delegate to p.
|
||||
delegateTextMapPropagatorOnce.Do(func() {
|
||||
if current := TextMapPropagator(); current == p {
|
||||
// Setting the provider to the prior default is nonsense, panic.
|
||||
// Panic is acceptable because we are likely still early in the
|
||||
// process lifetime.
|
||||
panic("invalid TextMapPropagator, the global instance cannot be reinstalled")
|
||||
} else if def, ok := current.(*textMapPropagator); ok {
|
||||
def.SetDelegate(p)
|
||||
}
|
||||
})
|
||||
// Return p when subsequent calls to TextMapPropagator are made.
|
||||
globalPropagators.Store(propagatorsHolder{tm: p})
|
||||
}
|
||||
|
||||
func defaultTracerValue() *atomic.Value {
|
||||
v := &atomic.Value{}
|
||||
v.Store(tracerProviderHolder{tp: &tracerProvider{}})
|
||||
return v
|
||||
}
|
||||
|
||||
func defaultMeterValue() *atomic.Value {
|
||||
v := &atomic.Value{}
|
||||
v.Store(meterProviderHolder{mp: newMeterProvider()})
|
||||
return v
|
||||
}
|
||||
|
||||
func defaultPropagatorsValue() *atomic.Value {
|
||||
v := &atomic.Value{}
|
||||
v.Store(propagatorsHolder{tm: newTextMapPropagator()})
|
||||
return v
|
||||
}
|
||||
|
||||
// ResetForTest restores the initial global state, for testing purposes.
|
||||
func ResetForTest() {
|
||||
globalTracer = defaultTracerValue()
|
||||
globalMeter = defaultMeterValue()
|
||||
globalPropagators = defaultPropagatorsValue()
|
||||
delegateMeterOnce = sync.Once{}
|
||||
delegateTraceOnce = sync.Once{}
|
||||
delegateTextMapPropagatorOnce = sync.Once{}
|
||||
}
|
147
vendor/go.opentelemetry.io/otel/internal/global/trace.go
generated
vendored
Normal file
147
vendor/go.opentelemetry.io/otel/internal/global/trace.go
generated
vendored
Normal file
@ -0,0 +1,147 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package global
|
||||
|
||||
/*
|
||||
This file contains the forwarding implementation of the TracerProvider used as
|
||||
the default global instance. Prior to initialization of an SDK, Tracers
|
||||
returned by the global TracerProvider will provide no-op functionality. This
|
||||
means that all Span created prior to initialization are no-op Spans.
|
||||
|
||||
Once an SDK has been initialized, all provided no-op Tracers are swapped for
|
||||
Tracers provided by the SDK defined TracerProvider. However, any Span started
|
||||
prior to this initialization does not change its behavior. Meaning, the Span
|
||||
remains a no-op Span.
|
||||
|
||||
The implementation to track and swap Tracers locks all new Tracer creation
|
||||
until the swap is complete. This assumes that this operation is not
|
||||
performance-critical. If that assumption is incorrect, be sure to configure an
|
||||
SDK prior to any Tracer creation.
|
||||
*/
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"go.opentelemetry.io/otel/internal/trace/noop"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// tracerProvider is a placeholder for a configured SDK TracerProvider.
|
||||
//
|
||||
// All TracerProvider functionality is forwarded to a delegate once
|
||||
// configured.
|
||||
type tracerProvider struct {
|
||||
mtx sync.Mutex
|
||||
tracers map[il]*tracer
|
||||
delegate trace.TracerProvider
|
||||
}
|
||||
|
||||
// Compile-time guarantee that tracerProvider implements the TracerProvider
|
||||
// interface.
|
||||
var _ trace.TracerProvider = &tracerProvider{}
|
||||
|
||||
// setDelegate configures p to delegate all TracerProvider functionality to
|
||||
// provider.
|
||||
//
|
||||
// All Tracers provided prior to this function call are switched out to be
|
||||
// Tracers provided by provider.
|
||||
//
|
||||
// It is guaranteed by the caller that this happens only once.
|
||||
func (p *tracerProvider) setDelegate(provider trace.TracerProvider) {
|
||||
p.mtx.Lock()
|
||||
defer p.mtx.Unlock()
|
||||
|
||||
p.delegate = provider
|
||||
|
||||
if len(p.tracers) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, t := range p.tracers {
|
||||
t.setDelegate(provider)
|
||||
}
|
||||
|
||||
p.tracers = nil
|
||||
}
|
||||
|
||||
// Tracer implements TracerProvider.
|
||||
func (p *tracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
|
||||
p.mtx.Lock()
|
||||
defer p.mtx.Unlock()
|
||||
|
||||
if p.delegate != nil {
|
||||
return p.delegate.Tracer(name, opts...)
|
||||
}
|
||||
|
||||
// At this moment it is guaranteed that no sdk is installed, save the tracer in the tracers map.
|
||||
|
||||
key := il{
|
||||
name: name,
|
||||
version: trace.NewTracerConfig(opts...).InstrumentationVersion,
|
||||
}
|
||||
|
||||
if p.tracers == nil {
|
||||
p.tracers = make(map[il]*tracer)
|
||||
}
|
||||
|
||||
if val, ok := p.tracers[key]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
t := &tracer{name: name, opts: opts}
|
||||
p.tracers[key] = t
|
||||
return t
|
||||
}
|
||||
|
||||
type il struct {
|
||||
name string
|
||||
version string
|
||||
}
|
||||
|
||||
// tracer is a placeholder for a trace.Tracer.
|
||||
//
|
||||
// All Tracer functionality is forwarded to a delegate once configured.
|
||||
// Otherwise, all functionality is forwarded to a NoopTracer.
|
||||
type tracer struct {
|
||||
name string
|
||||
opts []trace.TracerOption
|
||||
|
||||
delegate atomic.Value
|
||||
}
|
||||
|
||||
// Compile-time guarantee that tracer implements the trace.Tracer interface.
|
||||
var _ trace.Tracer = &tracer{}
|
||||
|
||||
// setDelegate configures t to delegate all Tracer functionality to Tracers
|
||||
// created by provider.
|
||||
//
|
||||
// All subsequent calls to the Tracer methods will be passed to the delegate.
|
||||
//
|
||||
// It is guaranteed by the caller that this happens only once.
|
||||
func (t *tracer) setDelegate(provider trace.TracerProvider) {
|
||||
t.delegate.Store(provider.Tracer(t.name, t.opts...))
|
||||
}
|
||||
|
||||
// Start implements trace.Tracer by forwarding the call to t.delegate if
|
||||
// set, otherwise it forwards the call to a NoopTracer.
|
||||
func (t *tracer) Start(ctx context.Context, name string, opts ...trace.SpanOption) (context.Context, trace.Span) {
|
||||
delegate := t.delegate.Load()
|
||||
if delegate != nil {
|
||||
return delegate.(trace.Tracer).Start(ctx, name, opts...)
|
||||
}
|
||||
return noop.Tracer.Start(ctx, name, opts...)
|
||||
}
|
148
vendor/go.opentelemetry.io/otel/internal/metric/async.go
generated
vendored
Normal file
148
vendor/go.opentelemetry.io/otel/internal/metric/async.go
generated
vendored
Normal file
@ -0,0 +1,148 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package metric
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
var ErrInvalidAsyncRunner = errors.New("unknown async runner type")
|
||||
|
||||
// AsyncCollector is an interface used between the MeterImpl and the
|
||||
// AsyncInstrumentState helper below. This interface is implemented by
|
||||
// the SDK to provide support for running observer callbacks.
|
||||
type AsyncCollector interface {
|
||||
// CollectAsync passes a batch of observations to the MeterImpl.
|
||||
CollectAsync(labels []attribute.KeyValue, observation ...metric.Observation)
|
||||
}
|
||||
|
||||
// AsyncInstrumentState manages an ordered set of asynchronous
|
||||
// instruments and the distinct runners, taking into account batch
|
||||
// observer callbacks.
|
||||
type AsyncInstrumentState struct {
|
||||
lock sync.Mutex
|
||||
|
||||
// errorOnce will use the otel.Handler to report an error
|
||||
// once in case of an invalid runner attempting to run.
|
||||
errorOnce sync.Once
|
||||
|
||||
// runnerMap keeps the set of runners that will run each
|
||||
// collection interval. Singletons are entered with a real
|
||||
// instrument each, batch observers are entered with a nil
|
||||
// instrument, ensuring that when a singleton callback is used
|
||||
// repeatedly, it is executed repeatedly in the interval, while
|
||||
// when a batch callback is used repeatedly, it only executes
|
||||
// once per interval.
|
||||
runnerMap map[asyncRunnerPair]struct{}
|
||||
|
||||
// runners maintains the set of runners in the order they were
|
||||
// registered.
|
||||
runners []asyncRunnerPair
|
||||
|
||||
// instruments maintains the set of instruments in the order
|
||||
// they were registered.
|
||||
instruments []metric.AsyncImpl
|
||||
}
|
||||
|
||||
// asyncRunnerPair is a map entry for Observer callback runners.
|
||||
type asyncRunnerPair struct {
|
||||
// runner is used as a map key here. The API ensures
|
||||
// that all callbacks are pointers for this reason.
|
||||
runner metric.AsyncRunner
|
||||
|
||||
// inst refers to a non-nil instrument when `runner` is a
|
||||
// AsyncSingleRunner.
|
||||
inst metric.AsyncImpl
|
||||
}
|
||||
|
||||
// NewAsyncInstrumentState returns a new *AsyncInstrumentState, for
|
||||
// use by MeterImpl to manage running the set of observer callbacks in
|
||||
// the correct order.
|
||||
func NewAsyncInstrumentState() *AsyncInstrumentState {
|
||||
return &AsyncInstrumentState{
|
||||
runnerMap: map[asyncRunnerPair]struct{}{},
|
||||
}
|
||||
}
|
||||
|
||||
// Instruments returns the asynchronous instruments managed by this
|
||||
// object, the set that should be checkpointed after observers are
|
||||
// run.
|
||||
func (a *AsyncInstrumentState) Instruments() []metric.AsyncImpl {
|
||||
a.lock.Lock()
|
||||
defer a.lock.Unlock()
|
||||
return a.instruments
|
||||
}
|
||||
|
||||
// Register adds a new asynchronous instrument to by managed by this
|
||||
// object. This should be called during NewAsyncInstrument() and
|
||||
// assumes that errors (e.g., duplicate registration) have already
|
||||
// been checked.
|
||||
func (a *AsyncInstrumentState) Register(inst metric.AsyncImpl, runner metric.AsyncRunner) {
|
||||
a.lock.Lock()
|
||||
defer a.lock.Unlock()
|
||||
|
||||
a.instruments = append(a.instruments, inst)
|
||||
|
||||
// asyncRunnerPair reflects this callback in the asyncRunners
|
||||
// list. If this is a batch runner, the instrument is nil.
|
||||
// If this is a single-Observer runner, the instrument is
|
||||
// included. This ensures that batch callbacks are called
|
||||
// once and single callbacks are called once per instrument.
|
||||
rp := asyncRunnerPair{
|
||||
runner: runner,
|
||||
}
|
||||
if _, ok := runner.(metric.AsyncSingleRunner); ok {
|
||||
rp.inst = inst
|
||||
}
|
||||
|
||||
if _, ok := a.runnerMap[rp]; !ok {
|
||||
a.runnerMap[rp] = struct{}{}
|
||||
a.runners = append(a.runners, rp)
|
||||
}
|
||||
}
|
||||
|
||||
// Run executes the complete set of observer callbacks.
|
||||
func (a *AsyncInstrumentState) Run(ctx context.Context, collector AsyncCollector) {
|
||||
a.lock.Lock()
|
||||
runners := a.runners
|
||||
a.lock.Unlock()
|
||||
|
||||
for _, rp := range runners {
|
||||
// The runner must be a single or batch runner, no
|
||||
// other implementations are possible because the
|
||||
// interface has un-exported methods.
|
||||
|
||||
if singleRunner, ok := rp.runner.(metric.AsyncSingleRunner); ok {
|
||||
singleRunner.Run(ctx, rp.inst, collector.CollectAsync)
|
||||
continue
|
||||
}
|
||||
|
||||
if multiRunner, ok := rp.runner.(metric.AsyncBatchRunner); ok {
|
||||
multiRunner.Run(ctx, collector.CollectAsync)
|
||||
continue
|
||||
}
|
||||
|
||||
a.errorOnce.Do(func() {
|
||||
otel.Handle(fmt.Errorf("%w: type %T (reported once)", ErrInvalidAsyncRunner, rp))
|
||||
})
|
||||
}
|
||||
}
|
55
vendor/go.opentelemetry.io/otel/internal/rawhelpers.go
generated
vendored
Normal file
55
vendor/go.opentelemetry.io/otel/internal/rawhelpers.go
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package internal
|
||||
|
||||
import (
|
||||
"math"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func BoolToRaw(b bool) uint64 {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func RawToBool(r uint64) bool {
|
||||
return r != 0
|
||||
}
|
||||
|
||||
func Int64ToRaw(i int64) uint64 {
|
||||
return uint64(i)
|
||||
}
|
||||
|
||||
func RawToInt64(r uint64) int64 {
|
||||
return int64(r)
|
||||
}
|
||||
|
||||
func Float64ToRaw(f float64) uint64 {
|
||||
return math.Float64bits(f)
|
||||
}
|
||||
|
||||
func RawToFloat64(r uint64) float64 {
|
||||
return math.Float64frombits(r)
|
||||
}
|
||||
|
||||
func RawPtrToFloat64Ptr(r *uint64) *float64 {
|
||||
return (*float64)(unsafe.Pointer(r))
|
||||
}
|
||||
|
||||
func RawPtrToInt64Ptr(r *uint64) *int64 {
|
||||
return (*int64)(unsafe.Pointer(r))
|
||||
}
|
35
vendor/go.opentelemetry.io/otel/internal/trace/noop/noop.go
generated
vendored
Normal file
35
vendor/go.opentelemetry.io/otel/internal/trace/noop/noop.go
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package noop provides noop tracing implementations for tracer and span.
|
||||
package noop
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
// Tracer is a noop tracer that starts noop spans.
|
||||
Tracer trace.Tracer
|
||||
|
||||
// Span is a noop Span.
|
||||
Span trace.Span
|
||||
)
|
||||
|
||||
func init() {
|
||||
Tracer = trace.NewNoopTracerProvider().Tracer("")
|
||||
_, Span = Tracer.Start(context.Background(), "")
|
||||
}
|
201
vendor/go.opentelemetry.io/otel/metric/LICENSE
generated
vendored
Normal file
201
vendor/go.opentelemetry.io/otel/metric/LICENSE
generated
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
128
vendor/go.opentelemetry.io/otel/metric/config.go
generated
vendored
Normal file
128
vendor/go.opentelemetry.io/otel/metric/config.go
generated
vendored
Normal file
@ -0,0 +1,128 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package metric // import "go.opentelemetry.io/otel/metric"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel/unit"
|
||||
)
|
||||
|
||||
// InstrumentConfig contains options for metric instrument descriptors.
|
||||
type InstrumentConfig struct {
|
||||
// Description describes the instrument in human-readable terms.
|
||||
Description string
|
||||
// Unit describes the measurement unit for a instrument.
|
||||
Unit unit.Unit
|
||||
// InstrumentationName is the name of the library providing
|
||||
// instrumentation.
|
||||
InstrumentationName string
|
||||
// InstrumentationVersion is the version of the library providing
|
||||
// instrumentation.
|
||||
InstrumentationVersion string
|
||||
}
|
||||
|
||||
// InstrumentOption is an interface for applying metric instrument options.
|
||||
type InstrumentOption interface {
|
||||
// ApplyMeter is used to set a InstrumentOption value of a
|
||||
// InstrumentConfig.
|
||||
ApplyInstrument(*InstrumentConfig)
|
||||
}
|
||||
|
||||
// NewInstrumentConfig creates a new InstrumentConfig
|
||||
// and applies all the given options.
|
||||
func NewInstrumentConfig(opts ...InstrumentOption) InstrumentConfig {
|
||||
var config InstrumentConfig
|
||||
for _, o := range opts {
|
||||
o.ApplyInstrument(&config)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
// WithDescription applies provided description.
|
||||
func WithDescription(desc string) InstrumentOption {
|
||||
return descriptionOption(desc)
|
||||
}
|
||||
|
||||
type descriptionOption string
|
||||
|
||||
func (d descriptionOption) ApplyInstrument(config *InstrumentConfig) {
|
||||
config.Description = string(d)
|
||||
}
|
||||
|
||||
// WithUnit applies provided unit.
|
||||
func WithUnit(unit unit.Unit) InstrumentOption {
|
||||
return unitOption(unit)
|
||||
}
|
||||
|
||||
type unitOption unit.Unit
|
||||
|
||||
func (u unitOption) ApplyInstrument(config *InstrumentConfig) {
|
||||
config.Unit = unit.Unit(u)
|
||||
}
|
||||
|
||||
// WithInstrumentationName sets the instrumentation name.
|
||||
func WithInstrumentationName(name string) InstrumentOption {
|
||||
return instrumentationNameOption(name)
|
||||
}
|
||||
|
||||
type instrumentationNameOption string
|
||||
|
||||
func (i instrumentationNameOption) ApplyInstrument(config *InstrumentConfig) {
|
||||
config.InstrumentationName = string(i)
|
||||
}
|
||||
|
||||
// MeterConfig contains options for Meters.
|
||||
type MeterConfig struct {
|
||||
// InstrumentationVersion is the version of the library providing
|
||||
// instrumentation.
|
||||
InstrumentationVersion string
|
||||
}
|
||||
|
||||
// MeterOption is an interface for applying Meter options.
|
||||
type MeterOption interface {
|
||||
// ApplyMeter is used to set a MeterOption value of a MeterConfig.
|
||||
ApplyMeter(*MeterConfig)
|
||||
}
|
||||
|
||||
// NewMeterConfig creates a new MeterConfig and applies
|
||||
// all the given options.
|
||||
func NewMeterConfig(opts ...MeterOption) MeterConfig {
|
||||
var config MeterConfig
|
||||
for _, o := range opts {
|
||||
o.ApplyMeter(&config)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
// InstrumentationOption is an interface for applying instrumentation specific
|
||||
// options.
|
||||
type InstrumentationOption interface {
|
||||
InstrumentOption
|
||||
MeterOption
|
||||
}
|
||||
|
||||
// WithInstrumentationVersion sets the instrumentation version.
|
||||
func WithInstrumentationVersion(version string) InstrumentationOption {
|
||||
return instrumentationVersionOption(version)
|
||||
}
|
||||
|
||||
type instrumentationVersionOption string
|
||||
|
||||
func (i instrumentationVersionOption) ApplyMeter(config *MeterConfig) {
|
||||
config.InstrumentationVersion = string(i)
|
||||
}
|
||||
|
||||
func (i instrumentationVersionOption) ApplyInstrument(config *InstrumentConfig) {
|
||||
config.InstrumentationVersion = string(i)
|
||||
}
|
67
vendor/go.opentelemetry.io/otel/metric/doc.go
generated
vendored
Normal file
67
vendor/go.opentelemetry.io/otel/metric/doc.go
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/*
|
||||
Package metric provides an implementation of the metrics part of the
|
||||
OpenTelemetry API.
|
||||
|
||||
This package is currently in a pre-GA phase. Backwards incompatible changes
|
||||
may be introduced in subsequent minor version releases as we work to track the
|
||||
evolving OpenTelemetry specification and user feedback.
|
||||
|
||||
Measurements can be made about an operation being performed or the state of a
|
||||
system in general. These measurements can be crucial to the reliable operation
|
||||
of code and provide valuable insights about the inner workings of a system.
|
||||
|
||||
Measurements are made using instruments provided by this package. The type of
|
||||
instrument used will depend on the type of measurement being made and of what
|
||||
part of a system is being measured.
|
||||
|
||||
Instruments are categorized as Synchronous or Asynchronous and independently
|
||||
as Adding or Grouping. Synchronous instruments are called by the user with a
|
||||
Context. Asynchronous instruments are called by the SDK during collection.
|
||||
Additive instruments are semantically intended for capturing a sum. Grouping
|
||||
instruments are intended for capturing a distribution.
|
||||
|
||||
Additive instruments may be monotonic, in which case they are non-decreasing
|
||||
and naturally define a rate.
|
||||
|
||||
The synchronous instrument names are:
|
||||
|
||||
Counter: additive, monotonic
|
||||
UpDownCounter: additive
|
||||
ValueRecorder: grouping
|
||||
|
||||
and the asynchronous instruments are:
|
||||
|
||||
SumObserver: additive, monotonic
|
||||
UpDownSumObserver: additive
|
||||
ValueObserver: grouping
|
||||
|
||||
All instruments are provided with support for either float64 or int64 input
|
||||
values.
|
||||
|
||||
An instrument is created using a Meter. Additionally, a Meter is used to
|
||||
record batches of synchronous measurements or asynchronous observations. A
|
||||
Meter is obtained using a MeterProvider. A Meter, like a Tracer, is unique to
|
||||
the instrumentation it instruments and must be named and versioned when
|
||||
created with a MeterProvider with the name and version of the instrumentation
|
||||
library.
|
||||
|
||||
Instrumentation should be designed to accept a MeterProvider from which it can
|
||||
create its own unique Meter. Alternatively, the registered global
|
||||
MeterProvider from the go.opentelemetry.io/otel package can be used as a
|
||||
default.
|
||||
*/
|
||||
package metric // import "go.opentelemetry.io/otel/metric"
|
49
vendor/go.opentelemetry.io/otel/metric/global/metric.go
generated
vendored
Normal file
49
vendor/go.opentelemetry.io/otel/metric/global/metric.go
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package global // import "go.opentelemetry.io/otel/metric/global"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel/internal/global"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
// Meter creates an implementation of the Meter interface from the global
|
||||
// MeterProvider. The instrumentationName must be the name of the library
|
||||
// providing instrumentation. This name may be the same as the instrumented
|
||||
// code only if that code provides built-in instrumentation. If the
|
||||
// instrumentationName is empty, then a implementation defined default name
|
||||
// will be used instead.
|
||||
//
|
||||
// This is short for MeterProvider().Meter(name)
|
||||
func Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
|
||||
return GetMeterProvider().Meter(instrumentationName, opts...)
|
||||
}
|
||||
|
||||
// GetMeterProvider returns the registered global meter provider. If
|
||||
// none is registered then a default meter provider is returned that
|
||||
// forwards the Meter interface to the first registered Meter.
|
||||
//
|
||||
// Use the meter provider to create a named meter. E.g.
|
||||
// meter := global.MeterProvider().Meter("example.com/foo")
|
||||
// or
|
||||
// meter := global.Meter("example.com/foo")
|
||||
func GetMeterProvider() metric.MeterProvider {
|
||||
return global.MeterProvider()
|
||||
}
|
||||
|
||||
// SetMeterProvider registers `mp` as the global meter provider.
|
||||
func SetMeterProvider(mp metric.MeterProvider) {
|
||||
global.SetMeterProvider(mp)
|
||||
}
|
54
vendor/go.opentelemetry.io/otel/metric/go.mod
generated
vendored
Normal file
54
vendor/go.opentelemetry.io/otel/metric/go.mod
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
module go.opentelemetry.io/otel/metric
|
||||
|
||||
go 1.14
|
||||
|
||||
replace go.opentelemetry.io/otel => ../
|
||||
|
||||
replace go.opentelemetry.io/otel/bridge/opencensus => ../bridge/opencensus
|
||||
|
||||
replace go.opentelemetry.io/otel/bridge/opentracing => ../bridge/opentracing
|
||||
|
||||
replace go.opentelemetry.io/otel/example/jaeger => ../example/jaeger
|
||||
|
||||
replace go.opentelemetry.io/otel/example/namedtracer => ../example/namedtracer
|
||||
|
||||
replace go.opentelemetry.io/otel/example/opencensus => ../example/opencensus
|
||||
|
||||
replace go.opentelemetry.io/otel/example/otel-collector => ../example/otel-collector
|
||||
|
||||
replace go.opentelemetry.io/otel/example/prom-collector => ../example/prom-collector
|
||||
|
||||
replace go.opentelemetry.io/otel/example/prometheus => ../example/prometheus
|
||||
|
||||
replace go.opentelemetry.io/otel/example/zipkin => ../example/zipkin
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/metric/prometheus => ../exporters/metric/prometheus
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/otlp => ../exporters/otlp
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/stdout => ../exporters/stdout
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/trace/jaeger => ../exporters/trace/jaeger
|
||||
|
||||
replace go.opentelemetry.io/otel/exporters/trace/zipkin => ../exporters/trace/zipkin
|
||||
|
||||
replace go.opentelemetry.io/otel/internal/tools => ../internal/tools
|
||||
|
||||
replace go.opentelemetry.io/otel/metric => ./
|
||||
|
||||
replace go.opentelemetry.io/otel/oteltest => ../oteltest
|
||||
|
||||
replace go.opentelemetry.io/otel/sdk => ../sdk
|
||||
|
||||
replace go.opentelemetry.io/otel/sdk/export/metric => ../sdk/export/metric
|
||||
|
||||
replace go.opentelemetry.io/otel/sdk/metric => ../sdk/metric
|
||||
|
||||
replace go.opentelemetry.io/otel/trace => ../trace
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.5.5
|
||||
github.com/stretchr/testify v1.7.0
|
||||
go.opentelemetry.io/otel v0.20.0
|
||||
go.opentelemetry.io/otel/oteltest v0.20.0
|
||||
)
|
15
vendor/go.opentelemetry.io/otel/metric/go.sum
generated
vendored
Normal file
15
vendor/go.opentelemetry.io/otel/metric/go.sum
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
28
vendor/go.opentelemetry.io/otel/metric/instrumentkind_string.go
generated
vendored
Normal file
28
vendor/go.opentelemetry.io/otel/metric/instrumentkind_string.go
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
// Code generated by "stringer -type=InstrumentKind"; DO NOT EDIT.
|
||||
|
||||
package metric
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[ValueRecorderInstrumentKind-0]
|
||||
_ = x[ValueObserverInstrumentKind-1]
|
||||
_ = x[CounterInstrumentKind-2]
|
||||
_ = x[UpDownCounterInstrumentKind-3]
|
||||
_ = x[SumObserverInstrumentKind-4]
|
||||
_ = x[UpDownSumObserverInstrumentKind-5]
|
||||
}
|
||||
|
||||
const _InstrumentKind_name = "ValueRecorderInstrumentKindValueObserverInstrumentKindCounterInstrumentKindUpDownCounterInstrumentKindSumObserverInstrumentKindUpDownSumObserverInstrumentKind"
|
||||
|
||||
var _InstrumentKind_index = [...]uint8{0, 27, 54, 75, 102, 127, 158}
|
||||
|
||||
func (i InstrumentKind) String() string {
|
||||
if i < 0 || i >= InstrumentKind(len(_InstrumentKind_index)-1) {
|
||||
return "InstrumentKind(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _InstrumentKind_name[_InstrumentKind_index[i]:_InstrumentKind_index[i+1]]
|
||||
}
|
577
vendor/go.opentelemetry.io/otel/metric/metric.go
generated
vendored
Normal file
577
vendor/go.opentelemetry.io/otel/metric/metric.go
generated
vendored
Normal file
@ -0,0 +1,577 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package metric // import "go.opentelemetry.io/otel/metric"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
"go.opentelemetry.io/otel/unit"
|
||||
)
|
||||
|
||||
// MeterProvider supports named Meter instances.
|
||||
type MeterProvider interface {
|
||||
// Meter creates an implementation of the Meter interface.
|
||||
// The instrumentationName must be the name of the library providing
|
||||
// instrumentation. This name may be the same as the instrumented code
|
||||
// only if that code provides built-in instrumentation. If the
|
||||
// instrumentationName is empty, then a implementation defined default
|
||||
// name will be used instead.
|
||||
Meter(instrumentationName string, opts ...MeterOption) Meter
|
||||
}
|
||||
|
||||
// Meter is the creator of metric instruments.
|
||||
//
|
||||
// An uninitialized Meter is a no-op implementation.
|
||||
type Meter struct {
|
||||
impl MeterImpl
|
||||
name, version string
|
||||
}
|
||||
|
||||
// RecordBatch atomically records a batch of measurements.
|
||||
func (m Meter) RecordBatch(ctx context.Context, ls []attribute.KeyValue, ms ...Measurement) {
|
||||
if m.impl == nil {
|
||||
return
|
||||
}
|
||||
m.impl.RecordBatch(ctx, ls, ms...)
|
||||
}
|
||||
|
||||
// NewBatchObserver creates a new BatchObserver that supports
|
||||
// making batches of observations for multiple instruments.
|
||||
func (m Meter) NewBatchObserver(callback BatchObserverFunc) BatchObserver {
|
||||
return BatchObserver{
|
||||
meter: m,
|
||||
runner: newBatchAsyncRunner(callback),
|
||||
}
|
||||
}
|
||||
|
||||
// NewInt64Counter creates a new integer Counter instrument with the
|
||||
// given name, customized with options. May return an error if the
|
||||
// name is invalid (e.g., empty) or improperly registered (e.g.,
|
||||
// duplicate registration).
|
||||
func (m Meter) NewInt64Counter(name string, options ...InstrumentOption) (Int64Counter, error) {
|
||||
return wrapInt64CounterInstrument(
|
||||
m.newSync(name, CounterInstrumentKind, number.Int64Kind, options))
|
||||
}
|
||||
|
||||
// NewFloat64Counter creates a new floating point Counter with the
|
||||
// given name, customized with options. May return an error if the
|
||||
// name is invalid (e.g., empty) or improperly registered (e.g.,
|
||||
// duplicate registration).
|
||||
func (m Meter) NewFloat64Counter(name string, options ...InstrumentOption) (Float64Counter, error) {
|
||||
return wrapFloat64CounterInstrument(
|
||||
m.newSync(name, CounterInstrumentKind, number.Float64Kind, options))
|
||||
}
|
||||
|
||||
// NewInt64UpDownCounter creates a new integer UpDownCounter instrument with the
|
||||
// given name, customized with options. May return an error if the
|
||||
// name is invalid (e.g., empty) or improperly registered (e.g.,
|
||||
// duplicate registration).
|
||||
func (m Meter) NewInt64UpDownCounter(name string, options ...InstrumentOption) (Int64UpDownCounter, error) {
|
||||
return wrapInt64UpDownCounterInstrument(
|
||||
m.newSync(name, UpDownCounterInstrumentKind, number.Int64Kind, options))
|
||||
}
|
||||
|
||||
// NewFloat64UpDownCounter creates a new floating point UpDownCounter with the
|
||||
// given name, customized with options. May return an error if the
|
||||
// name is invalid (e.g., empty) or improperly registered (e.g.,
|
||||
// duplicate registration).
|
||||
func (m Meter) NewFloat64UpDownCounter(name string, options ...InstrumentOption) (Float64UpDownCounter, error) {
|
||||
return wrapFloat64UpDownCounterInstrument(
|
||||
m.newSync(name, UpDownCounterInstrumentKind, number.Float64Kind, options))
|
||||
}
|
||||
|
||||
// NewInt64ValueRecorder creates a new integer ValueRecorder instrument with the
|
||||
// given name, customized with options. May return an error if the
|
||||
// name is invalid (e.g., empty) or improperly registered (e.g.,
|
||||
// duplicate registration).
|
||||
func (m Meter) NewInt64ValueRecorder(name string, opts ...InstrumentOption) (Int64ValueRecorder, error) {
|
||||
return wrapInt64ValueRecorderInstrument(
|
||||
m.newSync(name, ValueRecorderInstrumentKind, number.Int64Kind, opts))
|
||||
}
|
||||
|
||||
// NewFloat64ValueRecorder creates a new floating point ValueRecorder with the
|
||||
// given name, customized with options. May return an error if the
|
||||
// name is invalid (e.g., empty) or improperly registered (e.g.,
|
||||
// duplicate registration).
|
||||
func (m Meter) NewFloat64ValueRecorder(name string, opts ...InstrumentOption) (Float64ValueRecorder, error) {
|
||||
return wrapFloat64ValueRecorderInstrument(
|
||||
m.newSync(name, ValueRecorderInstrumentKind, number.Float64Kind, opts))
|
||||
}
|
||||
|
||||
// NewInt64ValueObserver creates a new integer ValueObserver instrument
|
||||
// with the given name, running a given callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (m Meter) NewInt64ValueObserver(name string, callback Int64ObserverFunc, opts ...InstrumentOption) (Int64ValueObserver, error) {
|
||||
if callback == nil {
|
||||
return wrapInt64ValueObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapInt64ValueObserverInstrument(
|
||||
m.newAsync(name, ValueObserverInstrumentKind, number.Int64Kind, opts,
|
||||
newInt64AsyncRunner(callback)))
|
||||
}
|
||||
|
||||
// NewFloat64ValueObserver creates a new floating point ValueObserver with
|
||||
// the given name, running a given callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (m Meter) NewFloat64ValueObserver(name string, callback Float64ObserverFunc, opts ...InstrumentOption) (Float64ValueObserver, error) {
|
||||
if callback == nil {
|
||||
return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapFloat64ValueObserverInstrument(
|
||||
m.newAsync(name, ValueObserverInstrumentKind, number.Float64Kind, opts,
|
||||
newFloat64AsyncRunner(callback)))
|
||||
}
|
||||
|
||||
// NewInt64SumObserver creates a new integer SumObserver instrument
|
||||
// with the given name, running a given callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (m Meter) NewInt64SumObserver(name string, callback Int64ObserverFunc, opts ...InstrumentOption) (Int64SumObserver, error) {
|
||||
if callback == nil {
|
||||
return wrapInt64SumObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapInt64SumObserverInstrument(
|
||||
m.newAsync(name, SumObserverInstrumentKind, number.Int64Kind, opts,
|
||||
newInt64AsyncRunner(callback)))
|
||||
}
|
||||
|
||||
// NewFloat64SumObserver creates a new floating point SumObserver with
|
||||
// the given name, running a given callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (m Meter) NewFloat64SumObserver(name string, callback Float64ObserverFunc, opts ...InstrumentOption) (Float64SumObserver, error) {
|
||||
if callback == nil {
|
||||
return wrapFloat64SumObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapFloat64SumObserverInstrument(
|
||||
m.newAsync(name, SumObserverInstrumentKind, number.Float64Kind, opts,
|
||||
newFloat64AsyncRunner(callback)))
|
||||
}
|
||||
|
||||
// NewInt64UpDownSumObserver creates a new integer UpDownSumObserver instrument
|
||||
// with the given name, running a given callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (m Meter) NewInt64UpDownSumObserver(name string, callback Int64ObserverFunc, opts ...InstrumentOption) (Int64UpDownSumObserver, error) {
|
||||
if callback == nil {
|
||||
return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapInt64UpDownSumObserverInstrument(
|
||||
m.newAsync(name, UpDownSumObserverInstrumentKind, number.Int64Kind, opts,
|
||||
newInt64AsyncRunner(callback)))
|
||||
}
|
||||
|
||||
// NewFloat64UpDownSumObserver creates a new floating point UpDownSumObserver with
|
||||
// the given name, running a given callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (m Meter) NewFloat64UpDownSumObserver(name string, callback Float64ObserverFunc, opts ...InstrumentOption) (Float64UpDownSumObserver, error) {
|
||||
if callback == nil {
|
||||
return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapFloat64UpDownSumObserverInstrument(
|
||||
m.newAsync(name, UpDownSumObserverInstrumentKind, number.Float64Kind, opts,
|
||||
newFloat64AsyncRunner(callback)))
|
||||
}
|
||||
|
||||
// NewInt64ValueObserver creates a new integer ValueObserver instrument
|
||||
// with the given name, running in a batch callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (b BatchObserver) NewInt64ValueObserver(name string, opts ...InstrumentOption) (Int64ValueObserver, error) {
|
||||
if b.runner == nil {
|
||||
return wrapInt64ValueObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapInt64ValueObserverInstrument(
|
||||
b.meter.newAsync(name, ValueObserverInstrumentKind, number.Int64Kind, opts, b.runner))
|
||||
}
|
||||
|
||||
// NewFloat64ValueObserver creates a new floating point ValueObserver with
|
||||
// the given name, running in a batch callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (b BatchObserver) NewFloat64ValueObserver(name string, opts ...InstrumentOption) (Float64ValueObserver, error) {
|
||||
if b.runner == nil {
|
||||
return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapFloat64ValueObserverInstrument(
|
||||
b.meter.newAsync(name, ValueObserverInstrumentKind, number.Float64Kind, opts,
|
||||
b.runner))
|
||||
}
|
||||
|
||||
// NewInt64SumObserver creates a new integer SumObserver instrument
|
||||
// with the given name, running in a batch callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (b BatchObserver) NewInt64SumObserver(name string, opts ...InstrumentOption) (Int64SumObserver, error) {
|
||||
if b.runner == nil {
|
||||
return wrapInt64SumObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapInt64SumObserverInstrument(
|
||||
b.meter.newAsync(name, SumObserverInstrumentKind, number.Int64Kind, opts, b.runner))
|
||||
}
|
||||
|
||||
// NewFloat64SumObserver creates a new floating point SumObserver with
|
||||
// the given name, running in a batch callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (b BatchObserver) NewFloat64SumObserver(name string, opts ...InstrumentOption) (Float64SumObserver, error) {
|
||||
if b.runner == nil {
|
||||
return wrapFloat64SumObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapFloat64SumObserverInstrument(
|
||||
b.meter.newAsync(name, SumObserverInstrumentKind, number.Float64Kind, opts,
|
||||
b.runner))
|
||||
}
|
||||
|
||||
// NewInt64UpDownSumObserver creates a new integer UpDownSumObserver instrument
|
||||
// with the given name, running in a batch callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (b BatchObserver) NewInt64UpDownSumObserver(name string, opts ...InstrumentOption) (Int64UpDownSumObserver, error) {
|
||||
if b.runner == nil {
|
||||
return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapInt64UpDownSumObserverInstrument(
|
||||
b.meter.newAsync(name, UpDownSumObserverInstrumentKind, number.Int64Kind, opts, b.runner))
|
||||
}
|
||||
|
||||
// NewFloat64UpDownSumObserver creates a new floating point UpDownSumObserver with
|
||||
// the given name, running in a batch callback, and customized with
|
||||
// options. May return an error if the name is invalid (e.g., empty)
|
||||
// or improperly registered (e.g., duplicate registration).
|
||||
func (b BatchObserver) NewFloat64UpDownSumObserver(name string, opts ...InstrumentOption) (Float64UpDownSumObserver, error) {
|
||||
if b.runner == nil {
|
||||
return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil)
|
||||
}
|
||||
return wrapFloat64UpDownSumObserverInstrument(
|
||||
b.meter.newAsync(name, UpDownSumObserverInstrumentKind, number.Float64Kind, opts,
|
||||
b.runner))
|
||||
}
|
||||
|
||||
// MeterImpl returns the underlying MeterImpl of this Meter.
|
||||
func (m Meter) MeterImpl() MeterImpl {
|
||||
return m.impl
|
||||
}
|
||||
|
||||
// newAsync constructs one new asynchronous instrument.
|
||||
func (m Meter) newAsync(
|
||||
name string,
|
||||
mkind InstrumentKind,
|
||||
nkind number.Kind,
|
||||
opts []InstrumentOption,
|
||||
runner AsyncRunner,
|
||||
) (
|
||||
AsyncImpl,
|
||||
error,
|
||||
) {
|
||||
if m.impl == nil {
|
||||
return NoopAsync{}, nil
|
||||
}
|
||||
desc := NewDescriptor(name, mkind, nkind, opts...)
|
||||
desc.config.InstrumentationName = m.name
|
||||
desc.config.InstrumentationVersion = m.version
|
||||
return m.impl.NewAsyncInstrument(desc, runner)
|
||||
}
|
||||
|
||||
// newSync constructs one new synchronous instrument.
|
||||
func (m Meter) newSync(
|
||||
name string,
|
||||
metricKind InstrumentKind,
|
||||
numberKind number.Kind,
|
||||
opts []InstrumentOption,
|
||||
) (
|
||||
SyncImpl,
|
||||
error,
|
||||
) {
|
||||
if m.impl == nil {
|
||||
return NoopSync{}, nil
|
||||
}
|
||||
desc := NewDescriptor(name, metricKind, numberKind, opts...)
|
||||
desc.config.InstrumentationName = m.name
|
||||
desc.config.InstrumentationVersion = m.version
|
||||
return m.impl.NewSyncInstrument(desc)
|
||||
}
|
||||
|
||||
// MeterMust is a wrapper for Meter interfaces that panics when any
|
||||
// instrument constructor encounters an error.
|
||||
type MeterMust struct {
|
||||
meter Meter
|
||||
}
|
||||
|
||||
// BatchObserverMust is a wrapper for BatchObserver that panics when
|
||||
// any instrument constructor encounters an error.
|
||||
type BatchObserverMust struct {
|
||||
batch BatchObserver
|
||||
}
|
||||
|
||||
// Must constructs a MeterMust implementation from a Meter, allowing
|
||||
// the application to panic when any instrument constructor yields an
|
||||
// error.
|
||||
func Must(meter Meter) MeterMust {
|
||||
return MeterMust{meter: meter}
|
||||
}
|
||||
|
||||
// NewInt64Counter calls `Meter.NewInt64Counter` and returns the
|
||||
// instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewInt64Counter(name string, cos ...InstrumentOption) Int64Counter {
|
||||
if inst, err := mm.meter.NewInt64Counter(name, cos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewFloat64Counter calls `Meter.NewFloat64Counter` and returns the
|
||||
// instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewFloat64Counter(name string, cos ...InstrumentOption) Float64Counter {
|
||||
if inst, err := mm.meter.NewFloat64Counter(name, cos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewInt64UpDownCounter calls `Meter.NewInt64UpDownCounter` and returns the
|
||||
// instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewInt64UpDownCounter(name string, cos ...InstrumentOption) Int64UpDownCounter {
|
||||
if inst, err := mm.meter.NewInt64UpDownCounter(name, cos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewFloat64UpDownCounter calls `Meter.NewFloat64UpDownCounter` and returns the
|
||||
// instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewFloat64UpDownCounter(name string, cos ...InstrumentOption) Float64UpDownCounter {
|
||||
if inst, err := mm.meter.NewFloat64UpDownCounter(name, cos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewInt64ValueRecorder calls `Meter.NewInt64ValueRecorder` and returns the
|
||||
// instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewInt64ValueRecorder(name string, mos ...InstrumentOption) Int64ValueRecorder {
|
||||
if inst, err := mm.meter.NewInt64ValueRecorder(name, mos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewFloat64ValueRecorder calls `Meter.NewFloat64ValueRecorder` and returns the
|
||||
// instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewFloat64ValueRecorder(name string, mos ...InstrumentOption) Float64ValueRecorder {
|
||||
if inst, err := mm.meter.NewFloat64ValueRecorder(name, mos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewInt64ValueObserver calls `Meter.NewInt64ValueObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewInt64ValueObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64ValueObserver {
|
||||
if inst, err := mm.meter.NewInt64ValueObserver(name, callback, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewFloat64ValueObserver calls `Meter.NewFloat64ValueObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewFloat64ValueObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64ValueObserver {
|
||||
if inst, err := mm.meter.NewFloat64ValueObserver(name, callback, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewInt64SumObserver calls `Meter.NewInt64SumObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewInt64SumObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64SumObserver {
|
||||
if inst, err := mm.meter.NewInt64SumObserver(name, callback, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewFloat64SumObserver calls `Meter.NewFloat64SumObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewFloat64SumObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64SumObserver {
|
||||
if inst, err := mm.meter.NewFloat64SumObserver(name, callback, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewInt64UpDownSumObserver calls `Meter.NewInt64UpDownSumObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewInt64UpDownSumObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64UpDownSumObserver {
|
||||
if inst, err := mm.meter.NewInt64UpDownSumObserver(name, callback, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewFloat64UpDownSumObserver calls `Meter.NewFloat64UpDownSumObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (mm MeterMust) NewFloat64UpDownSumObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64UpDownSumObserver {
|
||||
if inst, err := mm.meter.NewFloat64UpDownSumObserver(name, callback, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewBatchObserver returns a wrapper around BatchObserver that panics
|
||||
// when any instrument constructor returns an error.
|
||||
func (mm MeterMust) NewBatchObserver(callback BatchObserverFunc) BatchObserverMust {
|
||||
return BatchObserverMust{
|
||||
batch: mm.meter.NewBatchObserver(callback),
|
||||
}
|
||||
}
|
||||
|
||||
// NewInt64ValueObserver calls `BatchObserver.NewInt64ValueObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (bm BatchObserverMust) NewInt64ValueObserver(name string, oos ...InstrumentOption) Int64ValueObserver {
|
||||
if inst, err := bm.batch.NewInt64ValueObserver(name, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewFloat64ValueObserver calls `BatchObserver.NewFloat64ValueObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (bm BatchObserverMust) NewFloat64ValueObserver(name string, oos ...InstrumentOption) Float64ValueObserver {
|
||||
if inst, err := bm.batch.NewFloat64ValueObserver(name, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewInt64SumObserver calls `BatchObserver.NewInt64SumObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (bm BatchObserverMust) NewInt64SumObserver(name string, oos ...InstrumentOption) Int64SumObserver {
|
||||
if inst, err := bm.batch.NewInt64SumObserver(name, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewFloat64SumObserver calls `BatchObserver.NewFloat64SumObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (bm BatchObserverMust) NewFloat64SumObserver(name string, oos ...InstrumentOption) Float64SumObserver {
|
||||
if inst, err := bm.batch.NewFloat64SumObserver(name, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewInt64UpDownSumObserver calls `BatchObserver.NewInt64UpDownSumObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (bm BatchObserverMust) NewInt64UpDownSumObserver(name string, oos ...InstrumentOption) Int64UpDownSumObserver {
|
||||
if inst, err := bm.batch.NewInt64UpDownSumObserver(name, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// NewFloat64UpDownSumObserver calls `BatchObserver.NewFloat64UpDownSumObserver` and
|
||||
// returns the instrument, panicking if it encounters an error.
|
||||
func (bm BatchObserverMust) NewFloat64UpDownSumObserver(name string, oos ...InstrumentOption) Float64UpDownSumObserver {
|
||||
if inst, err := bm.batch.NewFloat64UpDownSumObserver(name, oos...); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
return inst
|
||||
}
|
||||
}
|
||||
|
||||
// Descriptor contains all the settings that describe an instrument,
|
||||
// including its name, metric kind, number kind, and the configurable
|
||||
// options.
|
||||
type Descriptor struct {
|
||||
name string
|
||||
instrumentKind InstrumentKind
|
||||
numberKind number.Kind
|
||||
config InstrumentConfig
|
||||
}
|
||||
|
||||
// NewDescriptor returns a Descriptor with the given contents.
|
||||
func NewDescriptor(name string, ikind InstrumentKind, nkind number.Kind, opts ...InstrumentOption) Descriptor {
|
||||
return Descriptor{
|
||||
name: name,
|
||||
instrumentKind: ikind,
|
||||
numberKind: nkind,
|
||||
config: NewInstrumentConfig(opts...),
|
||||
}
|
||||
}
|
||||
|
||||
// Name returns the metric instrument's name.
|
||||
func (d Descriptor) Name() string {
|
||||
return d.name
|
||||
}
|
||||
|
||||
// InstrumentKind returns the specific kind of instrument.
|
||||
func (d Descriptor) InstrumentKind() InstrumentKind {
|
||||
return d.instrumentKind
|
||||
}
|
||||
|
||||
// Description provides a human-readable description of the metric
|
||||
// instrument.
|
||||
func (d Descriptor) Description() string {
|
||||
return d.config.Description
|
||||
}
|
||||
|
||||
// Unit describes the units of the metric instrument. Unitless
|
||||
// metrics return the empty string.
|
||||
func (d Descriptor) Unit() unit.Unit {
|
||||
return d.config.Unit
|
||||
}
|
||||
|
||||
// NumberKind returns whether this instrument is declared over int64,
|
||||
// float64, or uint64 values.
|
||||
func (d Descriptor) NumberKind() number.Kind {
|
||||
return d.numberKind
|
||||
}
|
||||
|
||||
// InstrumentationName returns the name of the library that provided
|
||||
// instrumentation for this instrument.
|
||||
func (d Descriptor) InstrumentationName() string {
|
||||
return d.config.InstrumentationName
|
||||
}
|
||||
|
||||
// InstrumentationVersion returns the version of the library that provided
|
||||
// instrumentation for this instrument.
|
||||
func (d Descriptor) InstrumentationVersion() string {
|
||||
return d.config.InstrumentationVersion
|
||||
}
|
777
vendor/go.opentelemetry.io/otel/metric/metric_instrument.go
generated
vendored
Normal file
777
vendor/go.opentelemetry.io/otel/metric/metric_instrument.go
generated
vendored
Normal file
@ -0,0 +1,777 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:generate stringer -type=InstrumentKind
|
||||
|
||||
package metric // import "go.opentelemetry.io/otel/metric"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
)
|
||||
|
||||
// ErrSDKReturnedNilImpl is returned when a new `MeterImpl` returns nil.
|
||||
var ErrSDKReturnedNilImpl = errors.New("SDK returned a nil implementation")
|
||||
|
||||
// InstrumentKind describes the kind of instrument.
|
||||
type InstrumentKind int8
|
||||
|
||||
const (
|
||||
// ValueRecorderInstrumentKind indicates a ValueRecorder instrument.
|
||||
ValueRecorderInstrumentKind InstrumentKind = iota
|
||||
// ValueObserverInstrumentKind indicates an ValueObserver instrument.
|
||||
ValueObserverInstrumentKind
|
||||
|
||||
// CounterInstrumentKind indicates a Counter instrument.
|
||||
CounterInstrumentKind
|
||||
// UpDownCounterInstrumentKind indicates a UpDownCounter instrument.
|
||||
UpDownCounterInstrumentKind
|
||||
|
||||
// SumObserverInstrumentKind indicates a SumObserver instrument.
|
||||
SumObserverInstrumentKind
|
||||
// UpDownSumObserverInstrumentKind indicates a UpDownSumObserver
|
||||
// instrument.
|
||||
UpDownSumObserverInstrumentKind
|
||||
)
|
||||
|
||||
// Synchronous returns whether this is a synchronous kind of instrument.
|
||||
func (k InstrumentKind) Synchronous() bool {
|
||||
switch k {
|
||||
case CounterInstrumentKind, UpDownCounterInstrumentKind, ValueRecorderInstrumentKind:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Asynchronous returns whether this is an asynchronous kind of instrument.
|
||||
func (k InstrumentKind) Asynchronous() bool {
|
||||
return !k.Synchronous()
|
||||
}
|
||||
|
||||
// Adding returns whether this kind of instrument adds its inputs (as opposed to Grouping).
|
||||
func (k InstrumentKind) Adding() bool {
|
||||
switch k {
|
||||
case CounterInstrumentKind, UpDownCounterInstrumentKind, SumObserverInstrumentKind, UpDownSumObserverInstrumentKind:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Grouping returns whether this kind of instrument groups its inputs (as opposed to Adding).
|
||||
func (k InstrumentKind) Grouping() bool {
|
||||
return !k.Adding()
|
||||
}
|
||||
|
||||
// Monotonic returns whether this kind of instrument exposes a non-decreasing sum.
|
||||
func (k InstrumentKind) Monotonic() bool {
|
||||
switch k {
|
||||
case CounterInstrumentKind, SumObserverInstrumentKind:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// PrecomputedSum returns whether this kind of instrument receives precomputed sums.
|
||||
func (k InstrumentKind) PrecomputedSum() bool {
|
||||
return k.Adding() && k.Asynchronous()
|
||||
}
|
||||
|
||||
// Observation is used for reporting an asynchronous batch of metric
|
||||
// values. Instances of this type should be created by asynchronous
|
||||
// instruments (e.g., Int64ValueObserver.Observation()).
|
||||
type Observation struct {
|
||||
// number needs to be aligned for 64-bit atomic operations.
|
||||
number number.Number
|
||||
instrument AsyncImpl
|
||||
}
|
||||
|
||||
// Int64ObserverFunc is a type of callback that integral
|
||||
// observers run.
|
||||
type Int64ObserverFunc func(context.Context, Int64ObserverResult)
|
||||
|
||||
// Float64ObserverFunc is a type of callback that floating point
|
||||
// observers run.
|
||||
type Float64ObserverFunc func(context.Context, Float64ObserverResult)
|
||||
|
||||
// BatchObserverFunc is a callback argument for use with any
|
||||
// Observer instrument that will be reported as a batch of
|
||||
// observations.
|
||||
type BatchObserverFunc func(context.Context, BatchObserverResult)
|
||||
|
||||
// Int64ObserverResult is passed to an observer callback to capture
|
||||
// observations for one asynchronous integer metric instrument.
|
||||
type Int64ObserverResult struct {
|
||||
instrument AsyncImpl
|
||||
function func([]attribute.KeyValue, ...Observation)
|
||||
}
|
||||
|
||||
// Float64ObserverResult is passed to an observer callback to capture
|
||||
// observations for one asynchronous floating point metric instrument.
|
||||
type Float64ObserverResult struct {
|
||||
instrument AsyncImpl
|
||||
function func([]attribute.KeyValue, ...Observation)
|
||||
}
|
||||
|
||||
// BatchObserverResult is passed to a batch observer callback to
|
||||
// capture observations for multiple asynchronous instruments.
|
||||
type BatchObserverResult struct {
|
||||
function func([]attribute.KeyValue, ...Observation)
|
||||
}
|
||||
|
||||
// Observe captures a single integer value from the associated
|
||||
// instrument callback, with the given labels.
|
||||
func (ir Int64ObserverResult) Observe(value int64, labels ...attribute.KeyValue) {
|
||||
ir.function(labels, Observation{
|
||||
instrument: ir.instrument,
|
||||
number: number.NewInt64Number(value),
|
||||
})
|
||||
}
|
||||
|
||||
// Observe captures a single floating point value from the associated
|
||||
// instrument callback, with the given labels.
|
||||
func (fr Float64ObserverResult) Observe(value float64, labels ...attribute.KeyValue) {
|
||||
fr.function(labels, Observation{
|
||||
instrument: fr.instrument,
|
||||
number: number.NewFloat64Number(value),
|
||||
})
|
||||
}
|
||||
|
||||
// Observe captures a multiple observations from the associated batch
|
||||
// instrument callback, with the given labels.
|
||||
func (br BatchObserverResult) Observe(labels []attribute.KeyValue, obs ...Observation) {
|
||||
br.function(labels, obs...)
|
||||
}
|
||||
|
||||
// AsyncRunner is expected to convert into an AsyncSingleRunner or an
|
||||
// AsyncBatchRunner. SDKs will encounter an error if the AsyncRunner
|
||||
// does not satisfy one of these interfaces.
|
||||
type AsyncRunner interface {
|
||||
// AnyRunner() is a non-exported method with no functional use
|
||||
// other than to make this a non-empty interface.
|
||||
AnyRunner()
|
||||
}
|
||||
|
||||
// AsyncSingleRunner is an interface implemented by single-observer
|
||||
// callbacks.
|
||||
type AsyncSingleRunner interface {
|
||||
// Run accepts a single instrument and function for capturing
|
||||
// observations of that instrument. Each call to the function
|
||||
// receives one captured observation. (The function accepts
|
||||
// multiple observations so the same implementation can be
|
||||
// used for batch runners.)
|
||||
Run(ctx context.Context, single AsyncImpl, capture func([]attribute.KeyValue, ...Observation))
|
||||
|
||||
AsyncRunner
|
||||
}
|
||||
|
||||
// AsyncBatchRunner is an interface implemented by batch-observer
|
||||
// callbacks.
|
||||
type AsyncBatchRunner interface {
|
||||
// Run accepts a function for capturing observations of
|
||||
// multiple instruments.
|
||||
Run(ctx context.Context, capture func([]attribute.KeyValue, ...Observation))
|
||||
|
||||
AsyncRunner
|
||||
}
|
||||
|
||||
var _ AsyncSingleRunner = (*Int64ObserverFunc)(nil)
|
||||
var _ AsyncSingleRunner = (*Float64ObserverFunc)(nil)
|
||||
var _ AsyncBatchRunner = (*BatchObserverFunc)(nil)
|
||||
|
||||
// newInt64AsyncRunner returns a single-observer callback for integer Observer instruments.
|
||||
func newInt64AsyncRunner(c Int64ObserverFunc) AsyncSingleRunner {
|
||||
return &c
|
||||
}
|
||||
|
||||
// newFloat64AsyncRunner returns a single-observer callback for floating point Observer instruments.
|
||||
func newFloat64AsyncRunner(c Float64ObserverFunc) AsyncSingleRunner {
|
||||
return &c
|
||||
}
|
||||
|
||||
// newBatchAsyncRunner returns a batch-observer callback use with multiple Observer instruments.
|
||||
func newBatchAsyncRunner(c BatchObserverFunc) AsyncBatchRunner {
|
||||
return &c
|
||||
}
|
||||
|
||||
// AnyRunner implements AsyncRunner.
|
||||
func (*Int64ObserverFunc) AnyRunner() {}
|
||||
|
||||
// AnyRunner implements AsyncRunner.
|
||||
func (*Float64ObserverFunc) AnyRunner() {}
|
||||
|
||||
// AnyRunner implements AsyncRunner.
|
||||
func (*BatchObserverFunc) AnyRunner() {}
|
||||
|
||||
// Run implements AsyncSingleRunner.
|
||||
func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]attribute.KeyValue, ...Observation)) {
|
||||
(*i)(ctx, Int64ObserverResult{
|
||||
instrument: impl,
|
||||
function: function,
|
||||
})
|
||||
}
|
||||
|
||||
// Run implements AsyncSingleRunner.
|
||||
func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]attribute.KeyValue, ...Observation)) {
|
||||
(*f)(ctx, Float64ObserverResult{
|
||||
instrument: impl,
|
||||
function: function,
|
||||
})
|
||||
}
|
||||
|
||||
// Run implements AsyncBatchRunner.
|
||||
func (b *BatchObserverFunc) Run(ctx context.Context, function func([]attribute.KeyValue, ...Observation)) {
|
||||
(*b)(ctx, BatchObserverResult{
|
||||
function: function,
|
||||
})
|
||||
}
|
||||
|
||||
// wrapInt64ValueObserverInstrument converts an AsyncImpl into Int64ValueObserver.
|
||||
func wrapInt64ValueObserverInstrument(asyncInst AsyncImpl, err error) (Int64ValueObserver, error) {
|
||||
common, err := checkNewAsync(asyncInst, err)
|
||||
return Int64ValueObserver{asyncInstrument: common}, err
|
||||
}
|
||||
|
||||
// wrapFloat64ValueObserverInstrument converts an AsyncImpl into Float64ValueObserver.
|
||||
func wrapFloat64ValueObserverInstrument(asyncInst AsyncImpl, err error) (Float64ValueObserver, error) {
|
||||
common, err := checkNewAsync(asyncInst, err)
|
||||
return Float64ValueObserver{asyncInstrument: common}, err
|
||||
}
|
||||
|
||||
// wrapInt64SumObserverInstrument converts an AsyncImpl into Int64SumObserver.
|
||||
func wrapInt64SumObserverInstrument(asyncInst AsyncImpl, err error) (Int64SumObserver, error) {
|
||||
common, err := checkNewAsync(asyncInst, err)
|
||||
return Int64SumObserver{asyncInstrument: common}, err
|
||||
}
|
||||
|
||||
// wrapFloat64SumObserverInstrument converts an AsyncImpl into Float64SumObserver.
|
||||
func wrapFloat64SumObserverInstrument(asyncInst AsyncImpl, err error) (Float64SumObserver, error) {
|
||||
common, err := checkNewAsync(asyncInst, err)
|
||||
return Float64SumObserver{asyncInstrument: common}, err
|
||||
}
|
||||
|
||||
// wrapInt64UpDownSumObserverInstrument converts an AsyncImpl into Int64UpDownSumObserver.
|
||||
func wrapInt64UpDownSumObserverInstrument(asyncInst AsyncImpl, err error) (Int64UpDownSumObserver, error) {
|
||||
common, err := checkNewAsync(asyncInst, err)
|
||||
return Int64UpDownSumObserver{asyncInstrument: common}, err
|
||||
}
|
||||
|
||||
// wrapFloat64UpDownSumObserverInstrument converts an AsyncImpl into Float64UpDownSumObserver.
|
||||
func wrapFloat64UpDownSumObserverInstrument(asyncInst AsyncImpl, err error) (Float64UpDownSumObserver, error) {
|
||||
common, err := checkNewAsync(asyncInst, err)
|
||||
return Float64UpDownSumObserver{asyncInstrument: common}, err
|
||||
}
|
||||
|
||||
// BatchObserver represents an Observer callback that can report
|
||||
// observations for multiple instruments.
|
||||
type BatchObserver struct {
|
||||
meter Meter
|
||||
runner AsyncBatchRunner
|
||||
}
|
||||
|
||||
// Int64ValueObserver is a metric that captures a set of int64 values at a
|
||||
// point in time.
|
||||
type Int64ValueObserver struct {
|
||||
asyncInstrument
|
||||
}
|
||||
|
||||
// Float64ValueObserver is a metric that captures a set of float64 values
|
||||
// at a point in time.
|
||||
type Float64ValueObserver struct {
|
||||
asyncInstrument
|
||||
}
|
||||
|
||||
// Int64SumObserver is a metric that captures a precomputed sum of
|
||||
// int64 values at a point in time.
|
||||
type Int64SumObserver struct {
|
||||
asyncInstrument
|
||||
}
|
||||
|
||||
// Float64SumObserver is a metric that captures a precomputed sum of
|
||||
// float64 values at a point in time.
|
||||
type Float64SumObserver struct {
|
||||
asyncInstrument
|
||||
}
|
||||
|
||||
// Int64UpDownSumObserver is a metric that captures a precomputed sum of
|
||||
// int64 values at a point in time.
|
||||
type Int64UpDownSumObserver struct {
|
||||
asyncInstrument
|
||||
}
|
||||
|
||||
// Float64UpDownSumObserver is a metric that captures a precomputed sum of
|
||||
// float64 values at a point in time.
|
||||
type Float64UpDownSumObserver struct {
|
||||
asyncInstrument
|
||||
}
|
||||
|
||||
// Observation returns an Observation, a BatchObserverFunc
|
||||
// argument, for an asynchronous integer instrument.
|
||||
// This returns an implementation-level object for use by the SDK,
|
||||
// users should not refer to this.
|
||||
func (i Int64ValueObserver) Observation(v int64) Observation {
|
||||
return Observation{
|
||||
number: number.NewInt64Number(v),
|
||||
instrument: i.instrument,
|
||||
}
|
||||
}
|
||||
|
||||
// Observation returns an Observation, a BatchObserverFunc
|
||||
// argument, for an asynchronous integer instrument.
|
||||
// This returns an implementation-level object for use by the SDK,
|
||||
// users should not refer to this.
|
||||
func (f Float64ValueObserver) Observation(v float64) Observation {
|
||||
return Observation{
|
||||
number: number.NewFloat64Number(v),
|
||||
instrument: f.instrument,
|
||||
}
|
||||
}
|
||||
|
||||
// Observation returns an Observation, a BatchObserverFunc
|
||||
// argument, for an asynchronous integer instrument.
|
||||
// This returns an implementation-level object for use by the SDK,
|
||||
// users should not refer to this.
|
||||
func (i Int64SumObserver) Observation(v int64) Observation {
|
||||
return Observation{
|
||||
number: number.NewInt64Number(v),
|
||||
instrument: i.instrument,
|
||||
}
|
||||
}
|
||||
|
||||
// Observation returns an Observation, a BatchObserverFunc
|
||||
// argument, for an asynchronous integer instrument.
|
||||
// This returns an implementation-level object for use by the SDK,
|
||||
// users should not refer to this.
|
||||
func (f Float64SumObserver) Observation(v float64) Observation {
|
||||
return Observation{
|
||||
number: number.NewFloat64Number(v),
|
||||
instrument: f.instrument,
|
||||
}
|
||||
}
|
||||
|
||||
// Observation returns an Observation, a BatchObserverFunc
|
||||
// argument, for an asynchronous integer instrument.
|
||||
// This returns an implementation-level object for use by the SDK,
|
||||
// users should not refer to this.
|
||||
func (i Int64UpDownSumObserver) Observation(v int64) Observation {
|
||||
return Observation{
|
||||
number: number.NewInt64Number(v),
|
||||
instrument: i.instrument,
|
||||
}
|
||||
}
|
||||
|
||||
// Observation returns an Observation, a BatchObserverFunc
|
||||
// argument, for an asynchronous integer instrument.
|
||||
// This returns an implementation-level object for use by the SDK,
|
||||
// users should not refer to this.
|
||||
func (f Float64UpDownSumObserver) Observation(v float64) Observation {
|
||||
return Observation{
|
||||
number: number.NewFloat64Number(v),
|
||||
instrument: f.instrument,
|
||||
}
|
||||
}
|
||||
|
||||
// Measurement is used for reporting a synchronous batch of metric
|
||||
// values. Instances of this type should be created by synchronous
|
||||
// instruments (e.g., Int64Counter.Measurement()).
|
||||
type Measurement struct {
|
||||
// number needs to be aligned for 64-bit atomic operations.
|
||||
number number.Number
|
||||
instrument SyncImpl
|
||||
}
|
||||
|
||||
// syncInstrument contains a SyncImpl.
|
||||
type syncInstrument struct {
|
||||
instrument SyncImpl
|
||||
}
|
||||
|
||||
// syncBoundInstrument contains a BoundSyncImpl.
|
||||
type syncBoundInstrument struct {
|
||||
boundInstrument BoundSyncImpl
|
||||
}
|
||||
|
||||
// asyncInstrument contains a AsyncImpl.
|
||||
type asyncInstrument struct {
|
||||
instrument AsyncImpl
|
||||
}
|
||||
|
||||
// SyncImpl returns the instrument that created this measurement.
|
||||
// This returns an implementation-level object for use by the SDK,
|
||||
// users should not refer to this.
|
||||
func (m Measurement) SyncImpl() SyncImpl {
|
||||
return m.instrument
|
||||
}
|
||||
|
||||
// Number returns a number recorded in this measurement.
|
||||
func (m Measurement) Number() number.Number {
|
||||
return m.number
|
||||
}
|
||||
|
||||
// AsyncImpl returns the instrument that created this observation.
|
||||
// This returns an implementation-level object for use by the SDK,
|
||||
// users should not refer to this.
|
||||
func (m Observation) AsyncImpl() AsyncImpl {
|
||||
return m.instrument
|
||||
}
|
||||
|
||||
// Number returns a number recorded in this observation.
|
||||
func (m Observation) Number() number.Number {
|
||||
return m.number
|
||||
}
|
||||
|
||||
// AsyncImpl implements AsyncImpl.
|
||||
func (a asyncInstrument) AsyncImpl() AsyncImpl {
|
||||
return a.instrument
|
||||
}
|
||||
|
||||
// SyncImpl returns the implementation object for synchronous instruments.
|
||||
func (s syncInstrument) SyncImpl() SyncImpl {
|
||||
return s.instrument
|
||||
}
|
||||
|
||||
func (s syncInstrument) bind(labels []attribute.KeyValue) syncBoundInstrument {
|
||||
return newSyncBoundInstrument(s.instrument.Bind(labels))
|
||||
}
|
||||
|
||||
func (s syncInstrument) float64Measurement(value float64) Measurement {
|
||||
return newMeasurement(s.instrument, number.NewFloat64Number(value))
|
||||
}
|
||||
|
||||
func (s syncInstrument) int64Measurement(value int64) Measurement {
|
||||
return newMeasurement(s.instrument, number.NewInt64Number(value))
|
||||
}
|
||||
|
||||
func (s syncInstrument) directRecord(ctx context.Context, number number.Number, labels []attribute.KeyValue) {
|
||||
s.instrument.RecordOne(ctx, number, labels)
|
||||
}
|
||||
|
||||
func (h syncBoundInstrument) directRecord(ctx context.Context, number number.Number) {
|
||||
h.boundInstrument.RecordOne(ctx, number)
|
||||
}
|
||||
|
||||
// Unbind calls SyncImpl.Unbind.
|
||||
func (h syncBoundInstrument) Unbind() {
|
||||
h.boundInstrument.Unbind()
|
||||
}
|
||||
|
||||
// checkNewAsync receives an AsyncImpl and potential
|
||||
// error, and returns the same types, checking for and ensuring that
|
||||
// the returned interface is not nil.
|
||||
func checkNewAsync(instrument AsyncImpl, err error) (asyncInstrument, error) {
|
||||
if instrument == nil {
|
||||
if err == nil {
|
||||
err = ErrSDKReturnedNilImpl
|
||||
}
|
||||
instrument = NoopAsync{}
|
||||
}
|
||||
return asyncInstrument{
|
||||
instrument: instrument,
|
||||
}, err
|
||||
}
|
||||
|
||||
// checkNewSync receives an SyncImpl and potential
|
||||
// error, and returns the same types, checking for and ensuring that
|
||||
// the returned interface is not nil.
|
||||
func checkNewSync(instrument SyncImpl, err error) (syncInstrument, error) {
|
||||
if instrument == nil {
|
||||
if err == nil {
|
||||
err = ErrSDKReturnedNilImpl
|
||||
}
|
||||
// Note: an alternate behavior would be to synthesize a new name
|
||||
// or group all duplicately-named instruments of a certain type
|
||||
// together and use a tag for the original name, e.g.,
|
||||
// name = 'invalid.counter.int64'
|
||||
// label = 'original-name=duplicate-counter-name'
|
||||
instrument = NoopSync{}
|
||||
}
|
||||
return syncInstrument{
|
||||
instrument: instrument,
|
||||
}, err
|
||||
}
|
||||
|
||||
func newSyncBoundInstrument(boundInstrument BoundSyncImpl) syncBoundInstrument {
|
||||
return syncBoundInstrument{
|
||||
boundInstrument: boundInstrument,
|
||||
}
|
||||
}
|
||||
|
||||
func newMeasurement(instrument SyncImpl, number number.Number) Measurement {
|
||||
return Measurement{
|
||||
instrument: instrument,
|
||||
number: number,
|
||||
}
|
||||
}
|
||||
|
||||
// wrapInt64CounterInstrument converts a SyncImpl into Int64Counter.
|
||||
func wrapInt64CounterInstrument(syncInst SyncImpl, err error) (Int64Counter, error) {
|
||||
common, err := checkNewSync(syncInst, err)
|
||||
return Int64Counter{syncInstrument: common}, err
|
||||
}
|
||||
|
||||
// wrapFloat64CounterInstrument converts a SyncImpl into Float64Counter.
|
||||
func wrapFloat64CounterInstrument(syncInst SyncImpl, err error) (Float64Counter, error) {
|
||||
common, err := checkNewSync(syncInst, err)
|
||||
return Float64Counter{syncInstrument: common}, err
|
||||
}
|
||||
|
||||
// wrapInt64UpDownCounterInstrument converts a SyncImpl into Int64UpDownCounter.
|
||||
func wrapInt64UpDownCounterInstrument(syncInst SyncImpl, err error) (Int64UpDownCounter, error) {
|
||||
common, err := checkNewSync(syncInst, err)
|
||||
return Int64UpDownCounter{syncInstrument: common}, err
|
||||
}
|
||||
|
||||
// wrapFloat64UpDownCounterInstrument converts a SyncImpl into Float64UpDownCounter.
|
||||
func wrapFloat64UpDownCounterInstrument(syncInst SyncImpl, err error) (Float64UpDownCounter, error) {
|
||||
common, err := checkNewSync(syncInst, err)
|
||||
return Float64UpDownCounter{syncInstrument: common}, err
|
||||
}
|
||||
|
||||
// wrapInt64ValueRecorderInstrument converts a SyncImpl into Int64ValueRecorder.
|
||||
func wrapInt64ValueRecorderInstrument(syncInst SyncImpl, err error) (Int64ValueRecorder, error) {
|
||||
common, err := checkNewSync(syncInst, err)
|
||||
return Int64ValueRecorder{syncInstrument: common}, err
|
||||
}
|
||||
|
||||
// wrapFloat64ValueRecorderInstrument converts a SyncImpl into Float64ValueRecorder.
|
||||
func wrapFloat64ValueRecorderInstrument(syncInst SyncImpl, err error) (Float64ValueRecorder, error) {
|
||||
common, err := checkNewSync(syncInst, err)
|
||||
return Float64ValueRecorder{syncInstrument: common}, err
|
||||
}
|
||||
|
||||
// Float64Counter is a metric that accumulates float64 values.
|
||||
type Float64Counter struct {
|
||||
syncInstrument
|
||||
}
|
||||
|
||||
// Int64Counter is a metric that accumulates int64 values.
|
||||
type Int64Counter struct {
|
||||
syncInstrument
|
||||
}
|
||||
|
||||
// BoundFloat64Counter is a bound instrument for Float64Counter.
|
||||
//
|
||||
// It inherits the Unbind function from syncBoundInstrument.
|
||||
type BoundFloat64Counter struct {
|
||||
syncBoundInstrument
|
||||
}
|
||||
|
||||
// BoundInt64Counter is a boundInstrument for Int64Counter.
|
||||
//
|
||||
// It inherits the Unbind function from syncBoundInstrument.
|
||||
type BoundInt64Counter struct {
|
||||
syncBoundInstrument
|
||||
}
|
||||
|
||||
// Bind creates a bound instrument for this counter. The labels are
|
||||
// associated with values recorded via subsequent calls to Record.
|
||||
func (c Float64Counter) Bind(labels ...attribute.KeyValue) (h BoundFloat64Counter) {
|
||||
h.syncBoundInstrument = c.bind(labels)
|
||||
return
|
||||
}
|
||||
|
||||
// Bind creates a bound instrument for this counter. The labels are
|
||||
// associated with values recorded via subsequent calls to Record.
|
||||
func (c Int64Counter) Bind(labels ...attribute.KeyValue) (h BoundInt64Counter) {
|
||||
h.syncBoundInstrument = c.bind(labels)
|
||||
return
|
||||
}
|
||||
|
||||
// Measurement creates a Measurement object to use with batch
|
||||
// recording.
|
||||
func (c Float64Counter) Measurement(value float64) Measurement {
|
||||
return c.float64Measurement(value)
|
||||
}
|
||||
|
||||
// Measurement creates a Measurement object to use with batch
|
||||
// recording.
|
||||
func (c Int64Counter) Measurement(value int64) Measurement {
|
||||
return c.int64Measurement(value)
|
||||
}
|
||||
|
||||
// Add adds the value to the counter's sum. The labels should contain
|
||||
// the keys and values to be associated with this value.
|
||||
func (c Float64Counter) Add(ctx context.Context, value float64, labels ...attribute.KeyValue) {
|
||||
c.directRecord(ctx, number.NewFloat64Number(value), labels)
|
||||
}
|
||||
|
||||
// Add adds the value to the counter's sum. The labels should contain
|
||||
// the keys and values to be associated with this value.
|
||||
func (c Int64Counter) Add(ctx context.Context, value int64, labels ...attribute.KeyValue) {
|
||||
c.directRecord(ctx, number.NewInt64Number(value), labels)
|
||||
}
|
||||
|
||||
// Add adds the value to the counter's sum using the labels
|
||||
// previously bound to this counter via Bind()
|
||||
func (b BoundFloat64Counter) Add(ctx context.Context, value float64) {
|
||||
b.directRecord(ctx, number.NewFloat64Number(value))
|
||||
}
|
||||
|
||||
// Add adds the value to the counter's sum using the labels
|
||||
// previously bound to this counter via Bind()
|
||||
func (b BoundInt64Counter) Add(ctx context.Context, value int64) {
|
||||
b.directRecord(ctx, number.NewInt64Number(value))
|
||||
}
|
||||
|
||||
// Float64UpDownCounter is a metric instrument that sums floating
|
||||
// point values.
|
||||
type Float64UpDownCounter struct {
|
||||
syncInstrument
|
||||
}
|
||||
|
||||
// Int64UpDownCounter is a metric instrument that sums integer values.
|
||||
type Int64UpDownCounter struct {
|
||||
syncInstrument
|
||||
}
|
||||
|
||||
// BoundFloat64UpDownCounter is a bound instrument for Float64UpDownCounter.
|
||||
//
|
||||
// It inherits the Unbind function from syncBoundInstrument.
|
||||
type BoundFloat64UpDownCounter struct {
|
||||
syncBoundInstrument
|
||||
}
|
||||
|
||||
// BoundInt64UpDownCounter is a boundInstrument for Int64UpDownCounter.
|
||||
//
|
||||
// It inherits the Unbind function from syncBoundInstrument.
|
||||
type BoundInt64UpDownCounter struct {
|
||||
syncBoundInstrument
|
||||
}
|
||||
|
||||
// Bind creates a bound instrument for this counter. The labels are
|
||||
// associated with values recorded via subsequent calls to Record.
|
||||
func (c Float64UpDownCounter) Bind(labels ...attribute.KeyValue) (h BoundFloat64UpDownCounter) {
|
||||
h.syncBoundInstrument = c.bind(labels)
|
||||
return
|
||||
}
|
||||
|
||||
// Bind creates a bound instrument for this counter. The labels are
|
||||
// associated with values recorded via subsequent calls to Record.
|
||||
func (c Int64UpDownCounter) Bind(labels ...attribute.KeyValue) (h BoundInt64UpDownCounter) {
|
||||
h.syncBoundInstrument = c.bind(labels)
|
||||
return
|
||||
}
|
||||
|
||||
// Measurement creates a Measurement object to use with batch
|
||||
// recording.
|
||||
func (c Float64UpDownCounter) Measurement(value float64) Measurement {
|
||||
return c.float64Measurement(value)
|
||||
}
|
||||
|
||||
// Measurement creates a Measurement object to use with batch
|
||||
// recording.
|
||||
func (c Int64UpDownCounter) Measurement(value int64) Measurement {
|
||||
return c.int64Measurement(value)
|
||||
}
|
||||
|
||||
// Add adds the value to the counter's sum. The labels should contain
|
||||
// the keys and values to be associated with this value.
|
||||
func (c Float64UpDownCounter) Add(ctx context.Context, value float64, labels ...attribute.KeyValue) {
|
||||
c.directRecord(ctx, number.NewFloat64Number(value), labels)
|
||||
}
|
||||
|
||||
// Add adds the value to the counter's sum. The labels should contain
|
||||
// the keys and values to be associated with this value.
|
||||
func (c Int64UpDownCounter) Add(ctx context.Context, value int64, labels ...attribute.KeyValue) {
|
||||
c.directRecord(ctx, number.NewInt64Number(value), labels)
|
||||
}
|
||||
|
||||
// Add adds the value to the counter's sum using the labels
|
||||
// previously bound to this counter via Bind()
|
||||
func (b BoundFloat64UpDownCounter) Add(ctx context.Context, value float64) {
|
||||
b.directRecord(ctx, number.NewFloat64Number(value))
|
||||
}
|
||||
|
||||
// Add adds the value to the counter's sum using the labels
|
||||
// previously bound to this counter via Bind()
|
||||
func (b BoundInt64UpDownCounter) Add(ctx context.Context, value int64) {
|
||||
b.directRecord(ctx, number.NewInt64Number(value))
|
||||
}
|
||||
|
||||
// Float64ValueRecorder is a metric that records float64 values.
|
||||
type Float64ValueRecorder struct {
|
||||
syncInstrument
|
||||
}
|
||||
|
||||
// Int64ValueRecorder is a metric that records int64 values.
|
||||
type Int64ValueRecorder struct {
|
||||
syncInstrument
|
||||
}
|
||||
|
||||
// BoundFloat64ValueRecorder is a bound instrument for Float64ValueRecorder.
|
||||
//
|
||||
// It inherits the Unbind function from syncBoundInstrument.
|
||||
type BoundFloat64ValueRecorder struct {
|
||||
syncBoundInstrument
|
||||
}
|
||||
|
||||
// BoundInt64ValueRecorder is a bound instrument for Int64ValueRecorder.
|
||||
//
|
||||
// It inherits the Unbind function from syncBoundInstrument.
|
||||
type BoundInt64ValueRecorder struct {
|
||||
syncBoundInstrument
|
||||
}
|
||||
|
||||
// Bind creates a bound instrument for this ValueRecorder. The labels are
|
||||
// associated with values recorded via subsequent calls to Record.
|
||||
func (c Float64ValueRecorder) Bind(labels ...attribute.KeyValue) (h BoundFloat64ValueRecorder) {
|
||||
h.syncBoundInstrument = c.bind(labels)
|
||||
return
|
||||
}
|
||||
|
||||
// Bind creates a bound instrument for this ValueRecorder. The labels are
|
||||
// associated with values recorded via subsequent calls to Record.
|
||||
func (c Int64ValueRecorder) Bind(labels ...attribute.KeyValue) (h BoundInt64ValueRecorder) {
|
||||
h.syncBoundInstrument = c.bind(labels)
|
||||
return
|
||||
}
|
||||
|
||||
// Measurement creates a Measurement object to use with batch
|
||||
// recording.
|
||||
func (c Float64ValueRecorder) Measurement(value float64) Measurement {
|
||||
return c.float64Measurement(value)
|
||||
}
|
||||
|
||||
// Measurement creates a Measurement object to use with batch
|
||||
// recording.
|
||||
func (c Int64ValueRecorder) Measurement(value int64) Measurement {
|
||||
return c.int64Measurement(value)
|
||||
}
|
||||
|
||||
// Record adds a new value to the list of ValueRecorder's records. The
|
||||
// labels should contain the keys and values to be associated with
|
||||
// this value.
|
||||
func (c Float64ValueRecorder) Record(ctx context.Context, value float64, labels ...attribute.KeyValue) {
|
||||
c.directRecord(ctx, number.NewFloat64Number(value), labels)
|
||||
}
|
||||
|
||||
// Record adds a new value to the ValueRecorder's distribution. The
|
||||
// labels should contain the keys and values to be associated with
|
||||
// this value.
|
||||
func (c Int64ValueRecorder) Record(ctx context.Context, value int64, labels ...attribute.KeyValue) {
|
||||
c.directRecord(ctx, number.NewInt64Number(value), labels)
|
||||
}
|
||||
|
||||
// Record adds a new value to the ValueRecorder's distribution using the labels
|
||||
// previously bound to the ValueRecorder via Bind().
|
||||
func (b BoundFloat64ValueRecorder) Record(ctx context.Context, value float64) {
|
||||
b.directRecord(ctx, number.NewFloat64Number(value))
|
||||
}
|
||||
|
||||
// Record adds a new value to the ValueRecorder's distribution using the labels
|
||||
// previously bound to the ValueRecorder via Bind().
|
||||
func (b BoundInt64ValueRecorder) Record(ctx context.Context, value int64) {
|
||||
b.directRecord(ctx, number.NewInt64Number(value))
|
||||
}
|
59
vendor/go.opentelemetry.io/otel/metric/metric_noop.go
generated
vendored
Normal file
59
vendor/go.opentelemetry.io/otel/metric/metric_noop.go
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package metric // import "go.opentelemetry.io/otel/metric"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
)
|
||||
|
||||
type NoopMeterProvider struct{}
|
||||
|
||||
type noopInstrument struct{}
|
||||
type noopBoundInstrument struct{}
|
||||
type NoopSync struct{ noopInstrument }
|
||||
type NoopAsync struct{ noopInstrument }
|
||||
|
||||
var _ MeterProvider = NoopMeterProvider{}
|
||||
var _ SyncImpl = NoopSync{}
|
||||
var _ BoundSyncImpl = noopBoundInstrument{}
|
||||
var _ AsyncImpl = NoopAsync{}
|
||||
|
||||
func (NoopMeterProvider) Meter(_ string, _ ...MeterOption) Meter {
|
||||
return Meter{}
|
||||
}
|
||||
|
||||
func (noopInstrument) Implementation() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (noopInstrument) Descriptor() Descriptor {
|
||||
return Descriptor{}
|
||||
}
|
||||
|
||||
func (noopBoundInstrument) RecordOne(context.Context, number.Number) {
|
||||
}
|
||||
|
||||
func (noopBoundInstrument) Unbind() {
|
||||
}
|
||||
|
||||
func (NoopSync) Bind([]attribute.KeyValue) BoundSyncImpl {
|
||||
return noopBoundInstrument{}
|
||||
}
|
||||
|
||||
func (NoopSync) RecordOne(context.Context, number.Number, []attribute.KeyValue) {
|
||||
}
|
95
vendor/go.opentelemetry.io/otel/metric/metric_sdkapi.go
generated
vendored
Normal file
95
vendor/go.opentelemetry.io/otel/metric/metric_sdkapi.go
generated
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package metric // import "go.opentelemetry.io/otel/metric"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric/number"
|
||||
)
|
||||
|
||||
// MeterImpl is the interface an SDK must implement to supply a Meter
|
||||
// implementation.
|
||||
type MeterImpl interface {
|
||||
// RecordBatch atomically records a batch of measurements.
|
||||
RecordBatch(ctx context.Context, labels []attribute.KeyValue, measurement ...Measurement)
|
||||
|
||||
// NewSyncInstrument returns a newly constructed
|
||||
// synchronous instrument implementation or an error, should
|
||||
// one occur.
|
||||
NewSyncInstrument(descriptor Descriptor) (SyncImpl, error)
|
||||
|
||||
// NewAsyncInstrument returns a newly constructed
|
||||
// asynchronous instrument implementation or an error, should
|
||||
// one occur.
|
||||
NewAsyncInstrument(
|
||||
descriptor Descriptor,
|
||||
runner AsyncRunner,
|
||||
) (AsyncImpl, error)
|
||||
}
|
||||
|
||||
// InstrumentImpl is a common interface for synchronous and
|
||||
// asynchronous instruments.
|
||||
type InstrumentImpl interface {
|
||||
// Implementation returns the underlying implementation of the
|
||||
// instrument, which allows the implementation to gain access
|
||||
// to its own representation especially from a `Measurement`.
|
||||
Implementation() interface{}
|
||||
|
||||
// Descriptor returns a copy of the instrument's Descriptor.
|
||||
Descriptor() Descriptor
|
||||
}
|
||||
|
||||
// SyncImpl is the implementation-level interface to a generic
|
||||
// synchronous instrument (e.g., ValueRecorder and Counter instruments).
|
||||
type SyncImpl interface {
|
||||
InstrumentImpl
|
||||
|
||||
// Bind creates an implementation-level bound instrument,
|
||||
// binding a label set with this instrument implementation.
|
||||
Bind(labels []attribute.KeyValue) BoundSyncImpl
|
||||
|
||||
// RecordOne captures a single synchronous metric event.
|
||||
RecordOne(ctx context.Context, number number.Number, labels []attribute.KeyValue)
|
||||
}
|
||||
|
||||
// BoundSyncImpl is the implementation-level interface to a
|
||||
// generic bound synchronous instrument
|
||||
type BoundSyncImpl interface {
|
||||
|
||||
// RecordOne captures a single synchronous metric event.
|
||||
RecordOne(ctx context.Context, number number.Number)
|
||||
|
||||
// Unbind frees the resources associated with this bound instrument. It
|
||||
// does not affect the metric this bound instrument was created through.
|
||||
Unbind()
|
||||
}
|
||||
|
||||
// AsyncImpl is an implementation-level interface to an
|
||||
// asynchronous instrument (e.g., Observer instruments).
|
||||
type AsyncImpl interface {
|
||||
InstrumentImpl
|
||||
}
|
||||
|
||||
// WrapMeterImpl constructs a `Meter` implementation from a
|
||||
// `MeterImpl` implementation.
|
||||
func WrapMeterImpl(impl MeterImpl, instrumentationName string, opts ...MeterOption) Meter {
|
||||
return Meter{
|
||||
impl: impl,
|
||||
name: instrumentationName,
|
||||
version: NewMeterConfig(opts...).InstrumentationVersion,
|
||||
}
|
||||
}
|
23
vendor/go.opentelemetry.io/otel/metric/number/doc.go
generated
vendored
Normal file
23
vendor/go.opentelemetry.io/otel/metric/number/doc.go
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/*
|
||||
Package number provides a number abstraction for instruments that
|
||||
either support int64 or float64 input values.
|
||||
|
||||
This package is currently in a pre-GA phase. Backwards incompatible changes
|
||||
may be introduced in subsequent minor version releases as we work to track the
|
||||
evolving OpenTelemetry specification and user feedback.
|
||||
*/
|
||||
package number // import "go.opentelemetry.io/otel/metric/number"
|
24
vendor/go.opentelemetry.io/otel/metric/number/kind_string.go
generated
vendored
Normal file
24
vendor/go.opentelemetry.io/otel/metric/number/kind_string.go
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
// Code generated by "stringer -type=Kind"; DO NOT EDIT.
|
||||
|
||||
package number
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[Int64Kind-0]
|
||||
_ = x[Float64Kind-1]
|
||||
}
|
||||
|
||||
const _Kind_name = "Int64KindFloat64Kind"
|
||||
|
||||
var _Kind_index = [...]uint8{0, 9, 20}
|
||||
|
||||
func (i Kind) String() string {
|
||||
if i < 0 || i >= Kind(len(_Kind_index)-1) {
|
||||
return "Kind(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Kind_name[_Kind_index[i]:_Kind_index[i+1]]
|
||||
}
|
538
vendor/go.opentelemetry.io/otel/metric/number/number.go
generated
vendored
Normal file
538
vendor/go.opentelemetry.io/otel/metric/number/number.go
generated
vendored
Normal file
@ -0,0 +1,538 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package number // import "go.opentelemetry.io/otel/metric/number"
|
||||
|
||||
//go:generate stringer -type=Kind
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"sync/atomic"
|
||||
|
||||
"go.opentelemetry.io/otel/internal"
|
||||
)
|
||||
|
||||
// Kind describes the data type of the Number.
|
||||
type Kind int8
|
||||
|
||||
const (
|
||||
// Int64Kind means that the Number stores int64.
|
||||
Int64Kind Kind = iota
|
||||
// Float64Kind means that the Number stores float64.
|
||||
Float64Kind
|
||||
)
|
||||
|
||||
// Zero returns a zero value for a given Kind
|
||||
func (k Kind) Zero() Number {
|
||||
switch k {
|
||||
case Int64Kind:
|
||||
return NewInt64Number(0)
|
||||
case Float64Kind:
|
||||
return NewFloat64Number(0.)
|
||||
default:
|
||||
return Number(0)
|
||||
}
|
||||
}
|
||||
|
||||
// Minimum returns the minimum representable value
|
||||
// for a given Kind
|
||||
func (k Kind) Minimum() Number {
|
||||
switch k {
|
||||
case Int64Kind:
|
||||
return NewInt64Number(math.MinInt64)
|
||||
case Float64Kind:
|
||||
return NewFloat64Number(-1. * math.MaxFloat64)
|
||||
default:
|
||||
return Number(0)
|
||||
}
|
||||
}
|
||||
|
||||
// Maximum returns the maximum representable value
|
||||
// for a given Kind
|
||||
func (k Kind) Maximum() Number {
|
||||
switch k {
|
||||
case Int64Kind:
|
||||
return NewInt64Number(math.MaxInt64)
|
||||
case Float64Kind:
|
||||
return NewFloat64Number(math.MaxFloat64)
|
||||
default:
|
||||
return Number(0)
|
||||
}
|
||||
}
|
||||
|
||||
// Number represents either an integral or a floating point value. It
|
||||
// needs to be accompanied with a source of Kind that describes
|
||||
// the actual type of the value stored within Number.
|
||||
type Number uint64
|
||||
|
||||
// - constructors
|
||||
|
||||
// NewNumberFromRaw creates a new Number from a raw value.
|
||||
func NewNumberFromRaw(r uint64) Number {
|
||||
return Number(r)
|
||||
}
|
||||
|
||||
// NewInt64Number creates an integral Number.
|
||||
func NewInt64Number(i int64) Number {
|
||||
return NewNumberFromRaw(internal.Int64ToRaw(i))
|
||||
}
|
||||
|
||||
// NewFloat64Number creates a floating point Number.
|
||||
func NewFloat64Number(f float64) Number {
|
||||
return NewNumberFromRaw(internal.Float64ToRaw(f))
|
||||
}
|
||||
|
||||
// NewNumberSignChange returns a number with the same magnitude and
|
||||
// the opposite sign. `kind` must describe the kind of number in `nn`.
|
||||
func NewNumberSignChange(kind Kind, nn Number) Number {
|
||||
switch kind {
|
||||
case Int64Kind:
|
||||
return NewInt64Number(-nn.AsInt64())
|
||||
case Float64Kind:
|
||||
return NewFloat64Number(-nn.AsFloat64())
|
||||
}
|
||||
return nn
|
||||
}
|
||||
|
||||
// - as x
|
||||
|
||||
// AsNumber gets the Number.
|
||||
func (n *Number) AsNumber() Number {
|
||||
return *n
|
||||
}
|
||||
|
||||
// AsRaw gets the uninterpreted raw value. Might be useful for some
|
||||
// atomic operations.
|
||||
func (n *Number) AsRaw() uint64 {
|
||||
return uint64(*n)
|
||||
}
|
||||
|
||||
// AsInt64 assumes that the value contains an int64 and returns it as
|
||||
// such.
|
||||
func (n *Number) AsInt64() int64 {
|
||||
return internal.RawToInt64(n.AsRaw())
|
||||
}
|
||||
|
||||
// AsFloat64 assumes that the measurement value contains a float64 and
|
||||
// returns it as such.
|
||||
func (n *Number) AsFloat64() float64 {
|
||||
return internal.RawToFloat64(n.AsRaw())
|
||||
}
|
||||
|
||||
// - as x atomic
|
||||
|
||||
// AsNumberAtomic gets the Number atomically.
|
||||
func (n *Number) AsNumberAtomic() Number {
|
||||
return NewNumberFromRaw(n.AsRawAtomic())
|
||||
}
|
||||
|
||||
// AsRawAtomic gets the uninterpreted raw value atomically. Might be
|
||||
// useful for some atomic operations.
|
||||
func (n *Number) AsRawAtomic() uint64 {
|
||||
return atomic.LoadUint64(n.AsRawPtr())
|
||||
}
|
||||
|
||||
// AsInt64Atomic assumes that the number contains an int64 and returns
|
||||
// it as such atomically.
|
||||
func (n *Number) AsInt64Atomic() int64 {
|
||||
return atomic.LoadInt64(n.AsInt64Ptr())
|
||||
}
|
||||
|
||||
// AsFloat64Atomic assumes that the measurement value contains a
|
||||
// float64 and returns it as such atomically.
|
||||
func (n *Number) AsFloat64Atomic() float64 {
|
||||
return internal.RawToFloat64(n.AsRawAtomic())
|
||||
}
|
||||
|
||||
// - as x ptr
|
||||
|
||||
// AsRawPtr gets the pointer to the raw, uninterpreted raw
|
||||
// value. Might be useful for some atomic operations.
|
||||
func (n *Number) AsRawPtr() *uint64 {
|
||||
return (*uint64)(n)
|
||||
}
|
||||
|
||||
// AsInt64Ptr assumes that the number contains an int64 and returns a
|
||||
// pointer to it.
|
||||
func (n *Number) AsInt64Ptr() *int64 {
|
||||
return internal.RawPtrToInt64Ptr(n.AsRawPtr())
|
||||
}
|
||||
|
||||
// AsFloat64Ptr assumes that the number contains a float64 and returns a
|
||||
// pointer to it.
|
||||
func (n *Number) AsFloat64Ptr() *float64 {
|
||||
return internal.RawPtrToFloat64Ptr(n.AsRawPtr())
|
||||
}
|
||||
|
||||
// - coerce
|
||||
|
||||
// CoerceToInt64 casts the number to int64. May result in
|
||||
// data/precision loss.
|
||||
func (n *Number) CoerceToInt64(kind Kind) int64 {
|
||||
switch kind {
|
||||
case Int64Kind:
|
||||
return n.AsInt64()
|
||||
case Float64Kind:
|
||||
return int64(n.AsFloat64())
|
||||
default:
|
||||
// you get what you deserve
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// CoerceToFloat64 casts the number to float64. May result in
|
||||
// data/precision loss.
|
||||
func (n *Number) CoerceToFloat64(kind Kind) float64 {
|
||||
switch kind {
|
||||
case Int64Kind:
|
||||
return float64(n.AsInt64())
|
||||
case Float64Kind:
|
||||
return n.AsFloat64()
|
||||
default:
|
||||
// you get what you deserve
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// - set
|
||||
|
||||
// SetNumber sets the number to the passed number. Both should be of
|
||||
// the same kind.
|
||||
func (n *Number) SetNumber(nn Number) {
|
||||
*n.AsRawPtr() = nn.AsRaw()
|
||||
}
|
||||
|
||||
// SetRaw sets the number to the passed raw value. Both number and the
|
||||
// raw number should represent the same kind.
|
||||
func (n *Number) SetRaw(r uint64) {
|
||||
*n.AsRawPtr() = r
|
||||
}
|
||||
|
||||
// SetInt64 assumes that the number contains an int64 and sets it to
|
||||
// the passed value.
|
||||
func (n *Number) SetInt64(i int64) {
|
||||
*n.AsInt64Ptr() = i
|
||||
}
|
||||
|
||||
// SetFloat64 assumes that the number contains a float64 and sets it
|
||||
// to the passed value.
|
||||
func (n *Number) SetFloat64(f float64) {
|
||||
*n.AsFloat64Ptr() = f
|
||||
}
|
||||
|
||||
// - set atomic
|
||||
|
||||
// SetNumberAtomic sets the number to the passed number
|
||||
// atomically. Both should be of the same kind.
|
||||
func (n *Number) SetNumberAtomic(nn Number) {
|
||||
atomic.StoreUint64(n.AsRawPtr(), nn.AsRaw())
|
||||
}
|
||||
|
||||
// SetRawAtomic sets the number to the passed raw value
|
||||
// atomically. Both number and the raw number should represent the
|
||||
// same kind.
|
||||
func (n *Number) SetRawAtomic(r uint64) {
|
||||
atomic.StoreUint64(n.AsRawPtr(), r)
|
||||
}
|
||||
|
||||
// SetInt64Atomic assumes that the number contains an int64 and sets
|
||||
// it to the passed value atomically.
|
||||
func (n *Number) SetInt64Atomic(i int64) {
|
||||
atomic.StoreInt64(n.AsInt64Ptr(), i)
|
||||
}
|
||||
|
||||
// SetFloat64Atomic assumes that the number contains a float64 and
|
||||
// sets it to the passed value atomically.
|
||||
func (n *Number) SetFloat64Atomic(f float64) {
|
||||
atomic.StoreUint64(n.AsRawPtr(), internal.Float64ToRaw(f))
|
||||
}
|
||||
|
||||
// - swap
|
||||
|
||||
// SwapNumber sets the number to the passed number and returns the old
|
||||
// number. Both this number and the passed number should be of the
|
||||
// same kind.
|
||||
func (n *Number) SwapNumber(nn Number) Number {
|
||||
old := *n
|
||||
n.SetNumber(nn)
|
||||
return old
|
||||
}
|
||||
|
||||
// SwapRaw sets the number to the passed raw value and returns the old
|
||||
// raw value. Both number and the raw number should represent the same
|
||||
// kind.
|
||||
func (n *Number) SwapRaw(r uint64) uint64 {
|
||||
old := n.AsRaw()
|
||||
n.SetRaw(r)
|
||||
return old
|
||||
}
|
||||
|
||||
// SwapInt64 assumes that the number contains an int64, sets it to the
|
||||
// passed value and returns the old int64 value.
|
||||
func (n *Number) SwapInt64(i int64) int64 {
|
||||
old := n.AsInt64()
|
||||
n.SetInt64(i)
|
||||
return old
|
||||
}
|
||||
|
||||
// SwapFloat64 assumes that the number contains an float64, sets it to
|
||||
// the passed value and returns the old float64 value.
|
||||
func (n *Number) SwapFloat64(f float64) float64 {
|
||||
old := n.AsFloat64()
|
||||
n.SetFloat64(f)
|
||||
return old
|
||||
}
|
||||
|
||||
// - swap atomic
|
||||
|
||||
// SwapNumberAtomic sets the number to the passed number and returns
|
||||
// the old number atomically. Both this number and the passed number
|
||||
// should be of the same kind.
|
||||
func (n *Number) SwapNumberAtomic(nn Number) Number {
|
||||
return NewNumberFromRaw(atomic.SwapUint64(n.AsRawPtr(), nn.AsRaw()))
|
||||
}
|
||||
|
||||
// SwapRawAtomic sets the number to the passed raw value and returns
|
||||
// the old raw value atomically. Both number and the raw number should
|
||||
// represent the same kind.
|
||||
func (n *Number) SwapRawAtomic(r uint64) uint64 {
|
||||
return atomic.SwapUint64(n.AsRawPtr(), r)
|
||||
}
|
||||
|
||||
// SwapInt64Atomic assumes that the number contains an int64, sets it
|
||||
// to the passed value and returns the old int64 value atomically.
|
||||
func (n *Number) SwapInt64Atomic(i int64) int64 {
|
||||
return atomic.SwapInt64(n.AsInt64Ptr(), i)
|
||||
}
|
||||
|
||||
// SwapFloat64Atomic assumes that the number contains an float64, sets
|
||||
// it to the passed value and returns the old float64 value
|
||||
// atomically.
|
||||
func (n *Number) SwapFloat64Atomic(f float64) float64 {
|
||||
return internal.RawToFloat64(atomic.SwapUint64(n.AsRawPtr(), internal.Float64ToRaw(f)))
|
||||
}
|
||||
|
||||
// - add
|
||||
|
||||
// AddNumber assumes that this and the passed number are of the passed
|
||||
// kind and adds the passed number to this number.
|
||||
func (n *Number) AddNumber(kind Kind, nn Number) {
|
||||
switch kind {
|
||||
case Int64Kind:
|
||||
n.AddInt64(nn.AsInt64())
|
||||
case Float64Kind:
|
||||
n.AddFloat64(nn.AsFloat64())
|
||||
}
|
||||
}
|
||||
|
||||
// AddRaw assumes that this number and the passed raw value are of the
|
||||
// passed kind and adds the passed raw value to this number.
|
||||
func (n *Number) AddRaw(kind Kind, r uint64) {
|
||||
n.AddNumber(kind, NewNumberFromRaw(r))
|
||||
}
|
||||
|
||||
// AddInt64 assumes that the number contains an int64 and adds the
|
||||
// passed int64 to it.
|
||||
func (n *Number) AddInt64(i int64) {
|
||||
*n.AsInt64Ptr() += i
|
||||
}
|
||||
|
||||
// AddFloat64 assumes that the number contains a float64 and adds the
|
||||
// passed float64 to it.
|
||||
func (n *Number) AddFloat64(f float64) {
|
||||
*n.AsFloat64Ptr() += f
|
||||
}
|
||||
|
||||
// - add atomic
|
||||
|
||||
// AddNumberAtomic assumes that this and the passed number are of the
|
||||
// passed kind and adds the passed number to this number atomically.
|
||||
func (n *Number) AddNumberAtomic(kind Kind, nn Number) {
|
||||
switch kind {
|
||||
case Int64Kind:
|
||||
n.AddInt64Atomic(nn.AsInt64())
|
||||
case Float64Kind:
|
||||
n.AddFloat64Atomic(nn.AsFloat64())
|
||||
}
|
||||
}
|
||||
|
||||
// AddRawAtomic assumes that this number and the passed raw value are
|
||||
// of the passed kind and adds the passed raw value to this number
|
||||
// atomically.
|
||||
func (n *Number) AddRawAtomic(kind Kind, r uint64) {
|
||||
n.AddNumberAtomic(kind, NewNumberFromRaw(r))
|
||||
}
|
||||
|
||||
// AddInt64Atomic assumes that the number contains an int64 and adds
|
||||
// the passed int64 to it atomically.
|
||||
func (n *Number) AddInt64Atomic(i int64) {
|
||||
atomic.AddInt64(n.AsInt64Ptr(), i)
|
||||
}
|
||||
|
||||
// AddFloat64Atomic assumes that the number contains a float64 and
|
||||
// adds the passed float64 to it atomically.
|
||||
func (n *Number) AddFloat64Atomic(f float64) {
|
||||
for {
|
||||
o := n.AsFloat64Atomic()
|
||||
if n.CompareAndSwapFloat64(o, o+f) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// - compare and swap (atomic only)
|
||||
|
||||
// CompareAndSwapNumber does the atomic CAS operation on this
|
||||
// number. This number and passed old and new numbers should be of the
|
||||
// same kind.
|
||||
func (n *Number) CompareAndSwapNumber(on, nn Number) bool {
|
||||
return atomic.CompareAndSwapUint64(n.AsRawPtr(), on.AsRaw(), nn.AsRaw())
|
||||
}
|
||||
|
||||
// CompareAndSwapRaw does the atomic CAS operation on this
|
||||
// number. This number and passed old and new raw values should be of
|
||||
// the same kind.
|
||||
func (n *Number) CompareAndSwapRaw(or, nr uint64) bool {
|
||||
return atomic.CompareAndSwapUint64(n.AsRawPtr(), or, nr)
|
||||
}
|
||||
|
||||
// CompareAndSwapInt64 assumes that this number contains an int64 and
|
||||
// does the atomic CAS operation on it.
|
||||
func (n *Number) CompareAndSwapInt64(oi, ni int64) bool {
|
||||
return atomic.CompareAndSwapInt64(n.AsInt64Ptr(), oi, ni)
|
||||
}
|
||||
|
||||
// CompareAndSwapFloat64 assumes that this number contains a float64 and
|
||||
// does the atomic CAS operation on it.
|
||||
func (n *Number) CompareAndSwapFloat64(of, nf float64) bool {
|
||||
return atomic.CompareAndSwapUint64(n.AsRawPtr(), internal.Float64ToRaw(of), internal.Float64ToRaw(nf))
|
||||
}
|
||||
|
||||
// - compare
|
||||
|
||||
// CompareNumber compares two Numbers given their kind. Both numbers
|
||||
// should have the same kind. This returns:
|
||||
// 0 if the numbers are equal
|
||||
// -1 if the subject `n` is less than the argument `nn`
|
||||
// +1 if the subject `n` is greater than the argument `nn`
|
||||
func (n *Number) CompareNumber(kind Kind, nn Number) int {
|
||||
switch kind {
|
||||
case Int64Kind:
|
||||
return n.CompareInt64(nn.AsInt64())
|
||||
case Float64Kind:
|
||||
return n.CompareFloat64(nn.AsFloat64())
|
||||
default:
|
||||
// you get what you deserve
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// CompareRaw compares two numbers, where one is input as a raw
|
||||
// uint64, interpreting both values as a `kind` of number.
|
||||
func (n *Number) CompareRaw(kind Kind, r uint64) int {
|
||||
return n.CompareNumber(kind, NewNumberFromRaw(r))
|
||||
}
|
||||
|
||||
// CompareInt64 assumes that the Number contains an int64 and performs
|
||||
// a comparison between the value and the other value. It returns the
|
||||
// typical result of the compare function: -1 if the value is less
|
||||
// than the other, 0 if both are equal, 1 if the value is greater than
|
||||
// the other.
|
||||
func (n *Number) CompareInt64(i int64) int {
|
||||
this := n.AsInt64()
|
||||
if this < i {
|
||||
return -1
|
||||
} else if this > i {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// CompareFloat64 assumes that the Number contains a float64 and
|
||||
// performs a comparison between the value and the other value. It
|
||||
// returns the typical result of the compare function: -1 if the value
|
||||
// is less than the other, 0 if both are equal, 1 if the value is
|
||||
// greater than the other.
|
||||
//
|
||||
// Do not compare NaN values.
|
||||
func (n *Number) CompareFloat64(f float64) int {
|
||||
this := n.AsFloat64()
|
||||
if this < f {
|
||||
return -1
|
||||
} else if this > f {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// - relations to zero
|
||||
|
||||
// IsPositive returns true if the actual value is greater than zero.
|
||||
func (n *Number) IsPositive(kind Kind) bool {
|
||||
return n.compareWithZero(kind) > 0
|
||||
}
|
||||
|
||||
// IsNegative returns true if the actual value is less than zero.
|
||||
func (n *Number) IsNegative(kind Kind) bool {
|
||||
return n.compareWithZero(kind) < 0
|
||||
}
|
||||
|
||||
// IsZero returns true if the actual value is equal to zero.
|
||||
func (n *Number) IsZero(kind Kind) bool {
|
||||
return n.compareWithZero(kind) == 0
|
||||
}
|
||||
|
||||
// - misc
|
||||
|
||||
// Emit returns a string representation of the raw value of the
|
||||
// Number. A %d is used for integral values, %f for floating point
|
||||
// values.
|
||||
func (n *Number) Emit(kind Kind) string {
|
||||
switch kind {
|
||||
case Int64Kind:
|
||||
return fmt.Sprintf("%d", n.AsInt64())
|
||||
case Float64Kind:
|
||||
return fmt.Sprintf("%f", n.AsFloat64())
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// AsInterface returns the number as an interface{}, typically used
|
||||
// for Kind-correct JSON conversion.
|
||||
func (n *Number) AsInterface(kind Kind) interface{} {
|
||||
switch kind {
|
||||
case Int64Kind:
|
||||
return n.AsInt64()
|
||||
case Float64Kind:
|
||||
return n.AsFloat64()
|
||||
default:
|
||||
return math.NaN()
|
||||
}
|
||||
}
|
||||
|
||||
// - private stuff
|
||||
|
||||
func (n *Number) compareWithZero(kind Kind) int {
|
||||
switch kind {
|
||||
case Int64Kind:
|
||||
return n.CompareInt64(0)
|
||||
case Float64Kind:
|
||||
return n.CompareFloat64(0.)
|
||||
default:
|
||||
// you get what you deserve
|
||||
return 0
|
||||
}
|
||||
}
|
24
vendor/go.opentelemetry.io/otel/metric/registry/doc.go
generated
vendored
Normal file
24
vendor/go.opentelemetry.io/otel/metric/registry/doc.go
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/*
|
||||
Package registry provides a non-standalone implementation of
|
||||
MeterProvider that adds uniqueness checking for instrument descriptors
|
||||
on top of other MeterProvider it wraps.
|
||||
|
||||
This package is currently in a pre-GA phase. Backwards incompatible changes
|
||||
may be introduced in subsequent minor version releases as we work to track the
|
||||
evolving OpenTelemetry specification and user feedback.
|
||||
*/
|
||||
package registry // import "go.opentelemetry.io/otel/metric/registry"
|
170
vendor/go.opentelemetry.io/otel/metric/registry/registry.go
generated
vendored
Normal file
170
vendor/go.opentelemetry.io/otel/metric/registry/registry.go
generated
vendored
Normal file
@ -0,0 +1,170 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package registry // import "go.opentelemetry.io/otel/metric/registry"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
// MeterProvider is a standard MeterProvider for wrapping `MeterImpl`
|
||||
type MeterProvider struct {
|
||||
impl metric.MeterImpl
|
||||
}
|
||||
|
||||
var _ metric.MeterProvider = (*MeterProvider)(nil)
|
||||
|
||||
// uniqueInstrumentMeterImpl implements the metric.MeterImpl interface, adding
|
||||
// uniqueness checking for instrument descriptors. Use NewUniqueInstrumentMeter
|
||||
// to wrap an implementation with uniqueness checking.
|
||||
type uniqueInstrumentMeterImpl struct {
|
||||
lock sync.Mutex
|
||||
impl metric.MeterImpl
|
||||
state map[key]metric.InstrumentImpl
|
||||
}
|
||||
|
||||
var _ metric.MeterImpl = (*uniqueInstrumentMeterImpl)(nil)
|
||||
|
||||
type key struct {
|
||||
instrumentName string
|
||||
instrumentationName string
|
||||
InstrumentationVersion string
|
||||
}
|
||||
|
||||
// NewMeterProvider returns a new provider that implements instrument
|
||||
// name-uniqueness checking.
|
||||
func NewMeterProvider(impl metric.MeterImpl) *MeterProvider {
|
||||
return &MeterProvider{
|
||||
impl: NewUniqueInstrumentMeterImpl(impl),
|
||||
}
|
||||
}
|
||||
|
||||
// Meter implements MeterProvider.
|
||||
func (p *MeterProvider) Meter(instrumentationName string, opts ...metric.MeterOption) metric.Meter {
|
||||
return metric.WrapMeterImpl(p.impl, instrumentationName, opts...)
|
||||
}
|
||||
|
||||
// ErrMetricKindMismatch is the standard error for mismatched metric
|
||||
// instrument definitions.
|
||||
var ErrMetricKindMismatch = fmt.Errorf(
|
||||
"a metric was already registered by this name with another kind or number type")
|
||||
|
||||
// NewUniqueInstrumentMeterImpl returns a wrapped metric.MeterImpl with
|
||||
// the addition of uniqueness checking.
|
||||
func NewUniqueInstrumentMeterImpl(impl metric.MeterImpl) metric.MeterImpl {
|
||||
return &uniqueInstrumentMeterImpl{
|
||||
impl: impl,
|
||||
state: map[key]metric.InstrumentImpl{},
|
||||
}
|
||||
}
|
||||
|
||||
// RecordBatch implements metric.MeterImpl.
|
||||
func (u *uniqueInstrumentMeterImpl) RecordBatch(ctx context.Context, labels []attribute.KeyValue, ms ...metric.Measurement) {
|
||||
u.impl.RecordBatch(ctx, labels, ms...)
|
||||
}
|
||||
|
||||
func keyOf(descriptor metric.Descriptor) key {
|
||||
return key{
|
||||
descriptor.Name(),
|
||||
descriptor.InstrumentationName(),
|
||||
descriptor.InstrumentationVersion(),
|
||||
}
|
||||
}
|
||||
|
||||
// NewMetricKindMismatchError formats an error that describes a
|
||||
// mismatched metric instrument definition.
|
||||
func NewMetricKindMismatchError(desc metric.Descriptor) error {
|
||||
return fmt.Errorf("metric was %s (%s %s)registered as a %s %s: %w",
|
||||
desc.Name(),
|
||||
desc.InstrumentationName(),
|
||||
desc.InstrumentationVersion(),
|
||||
desc.NumberKind(),
|
||||
desc.InstrumentKind(),
|
||||
ErrMetricKindMismatch)
|
||||
}
|
||||
|
||||
// Compatible determines whether two metric.Descriptors are considered
|
||||
// the same for the purpose of uniqueness checking.
|
||||
func Compatible(candidate, existing metric.Descriptor) bool {
|
||||
return candidate.InstrumentKind() == existing.InstrumentKind() &&
|
||||
candidate.NumberKind() == existing.NumberKind()
|
||||
}
|
||||
|
||||
// checkUniqueness returns an ErrMetricKindMismatch error if there is
|
||||
// a conflict between a descriptor that was already registered and the
|
||||
// `descriptor` argument. If there is an existing compatible
|
||||
// registration, this returns the already-registered instrument. If
|
||||
// there is no conflict and no prior registration, returns (nil, nil).
|
||||
func (u *uniqueInstrumentMeterImpl) checkUniqueness(descriptor metric.Descriptor) (metric.InstrumentImpl, error) {
|
||||
impl, ok := u.state[keyOf(descriptor)]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if !Compatible(descriptor, impl.Descriptor()) {
|
||||
return nil, NewMetricKindMismatchError(impl.Descriptor())
|
||||
}
|
||||
|
||||
return impl, nil
|
||||
}
|
||||
|
||||
// NewSyncInstrument implements metric.MeterImpl.
|
||||
func (u *uniqueInstrumentMeterImpl) NewSyncInstrument(descriptor metric.Descriptor) (metric.SyncImpl, error) {
|
||||
u.lock.Lock()
|
||||
defer u.lock.Unlock()
|
||||
|
||||
impl, err := u.checkUniqueness(descriptor)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if impl != nil {
|
||||
return impl.(metric.SyncImpl), nil
|
||||
}
|
||||
|
||||
syncInst, err := u.impl.NewSyncInstrument(descriptor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u.state[keyOf(descriptor)] = syncInst
|
||||
return syncInst, nil
|
||||
}
|
||||
|
||||
// NewAsyncInstrument implements metric.MeterImpl.
|
||||
func (u *uniqueInstrumentMeterImpl) NewAsyncInstrument(
|
||||
descriptor metric.Descriptor,
|
||||
runner metric.AsyncRunner,
|
||||
) (metric.AsyncImpl, error) {
|
||||
u.lock.Lock()
|
||||
defer u.lock.Unlock()
|
||||
|
||||
impl, err := u.checkUniqueness(descriptor)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if impl != nil {
|
||||
return impl.(metric.AsyncImpl), nil
|
||||
}
|
||||
|
||||
asyncInst, err := u.impl.NewAsyncInstrument(descriptor, runner)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u.state[keyOf(descriptor)] = asyncInst
|
||||
return asyncInst, nil
|
||||
}
|
95
vendor/go.opentelemetry.io/otel/pre_release.sh
generated
vendored
Normal file
95
vendor/go.opentelemetry.io/otel/pre_release.sh
generated
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright The OpenTelemetry Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set -e
|
||||
|
||||
help()
|
||||
{
|
||||
printf "\n"
|
||||
printf "Usage: $0 -t tag\n"
|
||||
printf "\t-t Unreleased tag. Update all go.mod with this tag.\n"
|
||||
exit 1 # Exit script after printing help
|
||||
}
|
||||
|
||||
while getopts "t:" opt
|
||||
do
|
||||
case "$opt" in
|
||||
t ) TAG="$OPTARG" ;;
|
||||
? ) help ;; # Print help
|
||||
esac
|
||||
done
|
||||
|
||||
# Print help in case parameters are empty
|
||||
if [ -z "$TAG" ]
|
||||
then
|
||||
printf "Tag is missing\n";
|
||||
help
|
||||
fi
|
||||
|
||||
# Validate semver
|
||||
SEMVER_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$"
|
||||
if [[ "${TAG}" =~ ${SEMVER_REGEX} ]]; then
|
||||
printf "${TAG} is valid semver tag.\n"
|
||||
else
|
||||
printf "${TAG} is not a valid semver tag.\n"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
TAG_FOUND=`git tag --list ${TAG}`
|
||||
if [[ ${TAG_FOUND} = ${TAG} ]] ; then
|
||||
printf "Tag ${TAG} already exists\n"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# Get version for version.go
|
||||
OTEL_VERSION=$(echo "${TAG}" | grep -o '^v[0-9]\+\.[0-9]\+\.[0-9]\+')
|
||||
# Strip leading v
|
||||
OTEL_VERSION="${OTEL_VERSION#v}"
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
if ! git diff --quiet; then \
|
||||
printf "Working tree is not clean, can't proceed with the release process\n"
|
||||
git status
|
||||
git diff
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Update version.go
|
||||
cp ./version.go ./version.go.bak
|
||||
sed "s/\(return \"\)[0-9]*\.[0-9]*\.[0-9]*\"/\1${OTEL_VERSION}\"/" ./version.go.bak >./version.go
|
||||
rm -f ./version.go.bak
|
||||
|
||||
# Update go.mod
|
||||
git checkout -b pre_release_${TAG} main
|
||||
PACKAGE_DIRS=$(find . -mindepth 2 -type f -name 'go.mod' -exec dirname {} \; | egrep -v 'tools' | sed 's/^\.\///' | sort)
|
||||
|
||||
for dir in $PACKAGE_DIRS; do
|
||||
cp "${dir}/go.mod" "${dir}/go.mod.bak"
|
||||
sed "s/opentelemetry.io\/otel\([^ ]*\) v[0-9]*\.[0-9]*\.[0-9]/opentelemetry.io\/otel\1 ${TAG}/" "${dir}/go.mod.bak" >"${dir}/go.mod"
|
||||
rm -f "${dir}/go.mod.bak"
|
||||
done
|
||||
|
||||
# Run lint to update go.sum
|
||||
make lint
|
||||
|
||||
# Add changes and commit.
|
||||
git add .
|
||||
make ci
|
||||
git commit -m "Prepare for releasing $TAG"
|
||||
|
||||
printf "Now run following to verify the changes.\ngit diff main\n"
|
||||
printf "\nThen push the changes to upstream\n"
|
31
vendor/go.opentelemetry.io/otel/propagation.go
generated
vendored
Normal file
31
vendor/go.opentelemetry.io/otel/propagation.go
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package otel // import "go.opentelemetry.io/otel"
|
||||
|
||||
import (
|
||||
"go.opentelemetry.io/otel/internal/global"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
)
|
||||
|
||||
// GetTextMapPropagator returns the global TextMapPropagator. If none has been
|
||||
// set, a No-Op TextMapPropagator is returned.
|
||||
func GetTextMapPropagator() propagation.TextMapPropagator {
|
||||
return global.TextMapPropagator()
|
||||
}
|
||||
|
||||
// SetTextMapPropagator sets propagator as the global TextMapPropagator.
|
||||
func SetTextMapPropagator(propagator propagation.TextMapPropagator) {
|
||||
global.SetTextMapPropagator(propagator)
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user