From aa552c7382b6e56f96dea278936e8607f60a1f86 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Tue, 16 Aug 2022 20:08:16 +0100 Subject: [PATCH] Upgrade ai3/go-common --- go.mod | 2 +- go.sum | 6 +- vendor/git.autistici.org/ai3/go-common/go.mod | 1 + vendor/git.autistici.org/ai3/go-common/go.sum | 4 +- .../ai3/go-common/tracing/tracing.go | 8 + .../contrib/propagators/b3/LICENSE | 201 +++++++++++ .../contrib/propagators/b3/b3_config.go | 77 ++++ .../contrib/propagators/b3/b3_propagator.go | 341 ++++++++++++++++++ .../contrib/propagators/b3/context.go | 60 +++ .../contrib/propagators/b3/doc.go | 17 + .../contrib/propagators/b3/go.mod | 18 + .../contrib/propagators/b3/go.sum | 26 ++ .../contrib/propagators/b3/version.go | 26 ++ vendor/modules.txt | 4 +- 14 files changed, 785 insertions(+), 6 deletions(-) create mode 100644 vendor/go.opentelemetry.io/contrib/propagators/b3/LICENSE create mode 100644 vendor/go.opentelemetry.io/contrib/propagators/b3/b3_config.go create mode 100644 vendor/go.opentelemetry.io/contrib/propagators/b3/b3_propagator.go create mode 100644 vendor/go.opentelemetry.io/contrib/propagators/b3/context.go create mode 100644 vendor/go.opentelemetry.io/contrib/propagators/b3/doc.go create mode 100644 vendor/go.opentelemetry.io/contrib/propagators/b3/go.mod create mode 100644 vendor/go.opentelemetry.io/contrib/propagators/b3/go.sum create mode 100644 vendor/go.opentelemetry.io/contrib/propagators/b3/version.go diff --git a/go.mod b/go.mod index 123b4bd..43fd7bb 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.autistici.org/id/usermetadb go 1.14 require ( - git.autistici.org/ai3/go-common v0.0.0-20220816164411-b1b0f1bafe4c + git.autistici.org/ai3/go-common v0.0.0-20220816190733-e0ceb95832bc github.com/google/go-cmp v0.5.8 github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf // indirect diff --git a/go.sum b/go.sum index 9347e85..cc80162 100644 --- a/go.sum +++ b/go.sum @@ -50,8 +50,8 @@ contrib.go.opencensus.io/exporter/stackdriver v0.13.5/go.mod h1:aXENhDJ1Y4lIg4EU contrib.go.opencensus.io/integrations/ocsql v0.1.4/go.mod h1:8DsSdjz3F+APR+0z0WkU1aRorQCFfRxvqjUUPMbF3fE= contrib.go.opencensus.io/resource v0.1.1/go.mod h1:F361eGI91LCmW1I/Saf+rX0+OFcigGlFvXwEGEnkRLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -git.autistici.org/ai3/go-common v0.0.0-20220816164411-b1b0f1bafe4c h1:ig7MPkyvJGLrFjyY1d1KhYY9Tk/vfSd6mJ2m/2Th5ns= -git.autistici.org/ai3/go-common v0.0.0-20220816164411-b1b0f1bafe4c/go.mod h1:RSRMIh+m+Oc0qaGgQFVEJFKwmkF7+v2Vk4LKNNo22h0= +git.autistici.org/ai3/go-common v0.0.0-20220816190733-e0ceb95832bc h1:aWPCJUiyROs3ZmzG6Jo3kzO9Rb+xAXQek2rRBJA6Rgg= +git.autistici.org/ai3/go-common v0.0.0-20220816190733-e0ceb95832bc/go.mod h1:KckkZ6BZT7trRIKwnGoGj1DyfxywC/p+y2qHaQkT+xE= github.com/Azure/azure-amqp-common-go/v2 v2.1.0/go.mod h1:R8rea+gJRuJR6QxTir/XuEd+YuKoUiazDC/N96FiDEU= github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= github.com/Azure/azure-sdk-for-go v29.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= @@ -790,6 +790,8 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.34.0 h1:9NkMW03wwEzPtP/KciZ4Ozu/Uz5ZA7kfqXJIObnrjGU= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.34.0/go.mod h1:548ZsYzmT4PL4zWKRd8q/N4z0Wxzn/ZxUE+lkEpwWQA= +go.opentelemetry.io/contrib/propagators/b3 v1.9.0 h1:Lzb9zU98jCE2kyfCjWfSSsiQoGtvBL+COxvUBf7FNhU= +go.opentelemetry.io/contrib/propagators/b3 v1.9.0/go.mod h1:fyx3gFXn+4w5uWTTiqaI8oBNBW/6w9Ow5zxXf7NGixU= go.opentelemetry.io/otel v1.8.0/go.mod h1:2pkj+iMj0o03Y+cW6/m8Y4WkRdYN3AvCXCnzRMp9yvM= go.opentelemetry.io/otel v1.9.0 h1:8WZNQFIB2a71LnANS9JeyidJKKGOOremcUtb/OtHISw= go.opentelemetry.io/otel v1.9.0/go.mod h1:np4EoPGzoPs3O67xUVNoPPcmSvsfOxNlNA4F4AC+0Eo= diff --git a/vendor/git.autistici.org/ai3/go-common/go.mod b/vendor/git.autistici.org/ai3/go-common/go.mod index 0c6c64a..013d924 100644 --- a/vendor/git.autistici.org/ai3/go-common/go.mod +++ b/vendor/git.autistici.org/ai3/go-common/go.mod @@ -22,6 +22,7 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 github.com/theckman/go-flock v0.8.1 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.34.0 + go.opentelemetry.io/contrib/propagators/b3 v1.9.0 go.opentelemetry.io/otel v1.9.0 go.opentelemetry.io/otel/exporters/zipkin v1.9.0 go.opentelemetry.io/otel/sdk v1.9.0 diff --git a/vendor/git.autistici.org/ai3/go-common/go.sum b/vendor/git.autistici.org/ai3/go-common/go.sum index fcf2247..26f2430 100644 --- a/vendor/git.autistici.org/ai3/go-common/go.sum +++ b/vendor/git.autistici.org/ai3/go-common/go.sum @@ -208,8 +208,6 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8 github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= github.com/duo-labs/webauthn v0.0.0-20220330035159-03696f3d4499 h1:jaQHuGKk9NVcfu9VbA7ygslr/7utxdYs47i4osBhZP8= github.com/duo-labs/webauthn v0.0.0-20220330035159-03696f3d4499/go.mod h1:UMk1JMDgQDcdI2vQz+WJOIUTSjIq07qSepAVgc93rUc= -github.com/duo-labs/webauthn v0.0.0-20220815211337-00c9fb5711f5 h1:BaeJtFDlto/NjX9t730OebRRJf2P+t9YEDz3ur18824= -github.com/duo-labs/webauthn v0.0.0-20220815211337-00c9fb5711f5/go.mod h1:Jcj7rFNlTknb18v9jpSA58BveX2LDhXqaoy+6YV1N9g= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -862,6 +860,8 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.34.0 h1:9NkMW03wwEzPtP/KciZ4Ozu/Uz5ZA7kfqXJIObnrjGU= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.34.0/go.mod h1:548ZsYzmT4PL4zWKRd8q/N4z0Wxzn/ZxUE+lkEpwWQA= +go.opentelemetry.io/contrib/propagators/b3 v1.9.0 h1:Lzb9zU98jCE2kyfCjWfSSsiQoGtvBL+COxvUBf7FNhU= +go.opentelemetry.io/contrib/propagators/b3 v1.9.0/go.mod h1:fyx3gFXn+4w5uWTTiqaI8oBNBW/6w9Ow5zxXf7NGixU= go.opentelemetry.io/otel v1.8.0/go.mod h1:2pkj+iMj0o03Y+cW6/m8Y4WkRdYN3AvCXCnzRMp9yvM= go.opentelemetry.io/otel v1.9.0 h1:8WZNQFIB2a71LnANS9JeyidJKKGOOremcUtb/OtHISw= go.opentelemetry.io/otel v1.9.0/go.mod h1:np4EoPGzoPs3O67xUVNoPPcmSvsfOxNlNA4F4AC+0Eo= diff --git a/vendor/git.autistici.org/ai3/go-common/tracing/tracing.go b/vendor/git.autistici.org/ai3/go-common/tracing/tracing.go index f51f986..f563090 100644 --- a/vendor/git.autistici.org/ai3/go-common/tracing/tracing.go +++ b/vendor/git.autistici.org/ai3/go-common/tracing/tracing.go @@ -12,8 +12,10 @@ import ( "sync" othttp "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" + b3 "go.opentelemetry.io/contrib/propagators/b3" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/exporters/zipkin" + "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/sdk/resource" "go.opentelemetry.io/otel/sdk/trace" semconv "go.opentelemetry.io/otel/semconv/v1.12.0" @@ -138,6 +140,12 @@ func initTracing(serviceName string) { otel.SetTracerProvider(tp) Tracer = tp.Tracer(serviceName) + otel.SetTextMapPropagator( + propagation.NewCompositeTextMapPropagator( + propagation.TraceContext{}, + propagation.Baggage{}, + b3.New())) + log.Printf("tracing enabled (report_url %s)", config.ReportURL) Enabled = true diff --git a/vendor/go.opentelemetry.io/contrib/propagators/b3/LICENSE b/vendor/go.opentelemetry.io/contrib/propagators/b3/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/propagators/b3/LICENSE @@ -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. diff --git a/vendor/go.opentelemetry.io/contrib/propagators/b3/b3_config.go b/vendor/go.opentelemetry.io/contrib/propagators/b3/b3_config.go new file mode 100644 index 0000000..b09dbd3 --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/propagators/b3/b3_config.go @@ -0,0 +1,77 @@ +// 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 b3 // import "go.opentelemetry.io/contrib/propagators/b3" + +type config struct { + // InjectEncoding are the B3 encodings used when injecting trace + // information. If no encoding is specified (i.e. `B3Unspecified`) + // `B3SingleHeader` will be used as the default. + InjectEncoding Encoding +} + +// Option interface used for setting optional config properties. +type Option interface { + apply(*config) +} + +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{} + for _, opt := range opts { + opt.apply(c) + } + return c +} + +// Encoding is a bitmask representation of the B3 encoding type. +type Encoding uint8 + +// supports returns if e has o bit(s) set. +func (e Encoding) supports(o Encoding) bool { + return e&o == o +} + +const ( + // B3Unspecified is an unspecified B3 encoding. + B3Unspecified Encoding = 0 + // B3MultipleHeader is a B3 encoding that uses multiple headers to + // transmit tracing information all prefixed with `x-b3-`. + // x-b3-traceid: {TraceId} + // x-b3-parentspanid: {ParentSpanId} + // x-b3-spanid: {SpanId} + // x-b3-sampled: {SamplingState} + // x-b3-flags: {DebugFlag} + B3MultipleHeader Encoding = 1 << iota + // B3SingleHeader is a B3 encoding that uses a single header named `b3` + // to transmit tracing information. + // b3: {TraceId}-{SpanId}-{SamplingState}-{ParentSpanId} + B3SingleHeader +) + +// WithInjectEncoding sets the encoding the propagator will inject. +// The encoding is interpreted as a bitmask. Therefore +// WithInjectEncoding(B3SingleHeader | B3MultipleHeader) +// means the propagator will inject both single and multi B3 headers. +func WithInjectEncoding(encoding Encoding) Option { + return optionFunc(func(c *config) { + c.InjectEncoding = encoding + }) +} diff --git a/vendor/go.opentelemetry.io/contrib/propagators/b3/b3_propagator.go b/vendor/go.opentelemetry.io/contrib/propagators/b3/b3_propagator.go new file mode 100644 index 0000000..17dfa0b --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/propagators/b3/b3_propagator.go @@ -0,0 +1,341 @@ +// 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 b3 // import "go.opentelemetry.io/contrib/propagators/b3" + +import ( + "context" + "errors" + "strings" + + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" +) + +const ( + // Default B3 Header names. + b3ContextHeader = "b3" + b3DebugFlagHeader = "x-b3-flags" + b3TraceIDHeader = "x-b3-traceid" + b3SpanIDHeader = "x-b3-spanid" + b3SampledHeader = "x-b3-sampled" + b3ParentSpanIDHeader = "x-b3-parentspanid" + + b3TraceIDPadding = "0000000000000000" + + // B3 Single Header encoding widths. + separatorWidth = 1 // Single "-" character. + samplingWidth = 1 // Single hex character. + traceID64BitsWidth = 64 / 4 // 16 hex character Trace ID. + traceID128BitsWidth = 128 / 4 // 32 hex character Trace ID. + spanIDWidth = 16 // 16 hex character ID. + parentSpanIDWidth = 16 // 16 hex character ID. +) + +var ( + empty = trace.SpanContext{} + + errInvalidSampledByte = errors.New("invalid B3 Sampled found") + errInvalidSampledHeader = errors.New("invalid B3 Sampled header found") + errInvalidTraceIDHeader = errors.New("invalid B3 traceID header found") + errInvalidSpanIDHeader = errors.New("invalid B3 spanID header found") + errInvalidParentSpanIDHeader = errors.New("invalid B3 ParentSpanID header found") + errInvalidScope = errors.New("require either both traceID and spanID or none") + errInvalidScopeParent = errors.New("traceID and spanID required for ParentSpanID") + errInvalidScopeParentSingle = errors.New("traceID, spanID and Sampled required for ParentSpanID") + errEmptyContext = errors.New("empty request context") + errInvalidTraceIDValue = errors.New("invalid B3 traceID value found") + errInvalidSpanIDValue = errors.New("invalid B3 spanID value found") + errInvalidParentSpanIDValue = errors.New("invalid B3 ParentSpanID value found") +) + +type propagator struct { + cfg config +} + +var _ propagation.TextMapPropagator = propagator{} + +// New creates a B3 implementation of propagation.TextMapPropagator. +// B3 propagator serializes SpanContext to/from B3 Headers. +// This propagator supports both versions of B3 headers, +// 1. Single Header: +// b3: {TraceId}-{SpanId}-{SamplingState}-{ParentSpanId} +// 2. Multiple Headers: +// x-b3-traceid: {TraceId} +// x-b3-parentspanid: {ParentSpanId} +// x-b3-spanid: {SpanId} +// x-b3-sampled: {SamplingState} +// x-b3-flags: {DebugFlag} +// The Single Header propagator is used by default. +func New(opts ...Option) propagation.TextMapPropagator { + cfg := newConfig(opts...) + return propagator{ + cfg: *cfg, + } +} + +// Inject injects a context into the carrier as B3 headers. +// The parent span ID is omitted because it is not tracked in the +// SpanContext. +func (b3 propagator) Inject(ctx context.Context, carrier propagation.TextMapCarrier) { + sc := trace.SpanFromContext(ctx).SpanContext() + + if b3.cfg.InjectEncoding.supports(B3SingleHeader) || b3.cfg.InjectEncoding == B3Unspecified { + header := []string{} + if sc.TraceID().IsValid() && sc.SpanID().IsValid() { + header = append(header, sc.TraceID().String(), sc.SpanID().String()) + } + + if debugFromContext(ctx) { + header = append(header, "d") + } else if !(deferredFromContext(ctx)) { + if sc.IsSampled() { + header = append(header, "1") + } else { + header = append(header, "0") + } + } + + carrier.Set(b3ContextHeader, strings.Join(header, "-")) + } + + if b3.cfg.InjectEncoding.supports(B3MultipleHeader) { + if sc.TraceID().IsValid() && sc.SpanID().IsValid() { + carrier.Set(b3TraceIDHeader, sc.TraceID().String()) + carrier.Set(b3SpanIDHeader, sc.SpanID().String()) + } + + if debugFromContext(ctx) { + // Since Debug implies deferred, don't also send "X-B3-Sampled". + carrier.Set(b3DebugFlagHeader, "1") + } else if !(deferredFromContext(ctx)) { + if sc.IsSampled() { + carrier.Set(b3SampledHeader, "1") + } else { + carrier.Set(b3SampledHeader, "0") + } + } + } +} + +// Extract extracts a context from the carrier if it contains B3 headers. +func (b3 propagator) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context { + var ( + sc trace.SpanContext + err error + ) + + // Default to Single Header if a valid value exists. + if h := carrier.Get(b3ContextHeader); h != "" { + ctx, sc, err = extractSingle(ctx, h) + if err == nil && sc.IsValid() { + return trace.ContextWithRemoteSpanContext(ctx, sc) + } + // The Single Header value was invalid, fallback to Multiple Header. + } + + var ( + traceID = carrier.Get(b3TraceIDHeader) + spanID = carrier.Get(b3SpanIDHeader) + parentSpanID = carrier.Get(b3ParentSpanIDHeader) + sampled = carrier.Get(b3SampledHeader) + debugFlag = carrier.Get(b3DebugFlagHeader) + ) + ctx, sc, err = extractMultiple(ctx, traceID, spanID, parentSpanID, sampled, debugFlag) + if err != nil || !sc.IsValid() { + // clear the deferred flag if we don't have a valid SpanContext + return withDeferred(ctx, false) + } + return trace.ContextWithRemoteSpanContext(ctx, sc) +} + +func (b3 propagator) Fields() []string { + header := []string{} + if b3.cfg.InjectEncoding.supports(B3SingleHeader) { + header = append(header, b3ContextHeader) + } + if b3.cfg.InjectEncoding.supports(B3MultipleHeader) || b3.cfg.InjectEncoding == B3Unspecified { + header = append(header, b3TraceIDHeader, b3SpanIDHeader, b3SampledHeader, b3DebugFlagHeader) + } + return header +} + +// extractMultiple reconstructs a SpanContext from header values based on B3 +// Multiple header. It is based on the implementation found here: +// https://github.com/openzipkin/zipkin-go/blob/v0.2.2/propagation/b3/spancontext.go +// and adapted to support a SpanContext. +func extractMultiple(ctx context.Context, traceID, spanID, parentSpanID, sampled, flags string) (context.Context, trace.SpanContext, error) { + var ( + err error + requiredCount int + scc = trace.SpanContextConfig{} + ) + + // correct values for an existing sampled header are "0" and "1". + // For legacy support and being lenient to other tracing implementations we + // allow "true" and "false" as inputs for interop purposes. + switch strings.ToLower(sampled) { + case "0", "false": + // Zero value for TraceFlags sample bit is unset. + case "1", "true": + scc.TraceFlags = trace.FlagsSampled + case "": + ctx = withDeferred(ctx, true) + default: + return ctx, empty, errInvalidSampledHeader + } + + // The only accepted value for Flags is "1". This will set Debug bitmask and + // sampled bitmask to 1 since debug implicitly means sampled. All other + // values and omission of header will be ignored. According to the spec. User + // shouldn't send X-B3-Sampled header along with X-B3-Flags header. Thus we will + // ignore X-B3-Sampled header when X-B3-Flags header is sent and valid. + if flags == "1" { + ctx = withDeferred(ctx, false) + ctx = withDebug(ctx, true) + scc.TraceFlags |= trace.FlagsSampled + } + + if traceID != "" { + requiredCount++ + id := traceID + if len(traceID) == 16 { + // Pad 64-bit trace IDs. + id = b3TraceIDPadding + traceID + } + if scc.TraceID, err = trace.TraceIDFromHex(id); err != nil { + return ctx, empty, errInvalidTraceIDHeader + } + } + + if spanID != "" { + requiredCount++ + if scc.SpanID, err = trace.SpanIDFromHex(spanID); err != nil { + return ctx, empty, errInvalidSpanIDHeader + } + } + + if requiredCount != 0 && requiredCount != 2 { + return ctx, empty, errInvalidScope + } + + if parentSpanID != "" { + if requiredCount == 0 { + return ctx, empty, errInvalidScopeParent + } + // Validate parent span ID but we do not use it so do not save it. + if _, err = trace.SpanIDFromHex(parentSpanID); err != nil { + return ctx, empty, errInvalidParentSpanIDHeader + } + } + + return ctx, trace.NewSpanContext(scc), nil +} + +// extractSingle reconstructs a SpanContext from contextHeader based on a B3 +// Single header. It is based on the implementation found here: +// https://github.com/openzipkin/zipkin-go/blob/v0.2.2/propagation/b3/spancontext.go +// and adapted to support a SpanContext. +func extractSingle(ctx context.Context, contextHeader string) (context.Context, trace.SpanContext, error) { + if contextHeader == "" { + return ctx, empty, errEmptyContext + } + + var ( + scc = trace.SpanContextConfig{} + sampling string + ) + + headerLen := len(contextHeader) + + switch { + case headerLen == samplingWidth: + sampling = contextHeader + case headerLen == traceID64BitsWidth || headerLen == traceID128BitsWidth: + // Trace ID by itself is invalid. + return ctx, empty, errInvalidScope + case headerLen >= traceID64BitsWidth+spanIDWidth+separatorWidth: + pos := 0 + var traceID string + switch { + case string(contextHeader[traceID64BitsWidth]) == "-": + // traceID must be 64 bits + pos += traceID64BitsWidth // {traceID} + traceID = b3TraceIDPadding + string(contextHeader[0:pos]) + case string(contextHeader[32]) == "-": + // traceID must be 128 bits + pos += traceID128BitsWidth // {traceID} + traceID = string(contextHeader[0:pos]) + default: + return ctx, empty, errInvalidTraceIDValue + } + var err error + scc.TraceID, err = trace.TraceIDFromHex(traceID) + if err != nil { + return ctx, empty, errInvalidTraceIDValue + } + pos += separatorWidth // {traceID}- + + scc.SpanID, err = trace.SpanIDFromHex(contextHeader[pos : pos+spanIDWidth]) + if err != nil { + return ctx, empty, errInvalidSpanIDValue + } + pos += spanIDWidth // {traceID}-{spanID} + + if headerLen > pos { + if headerLen == pos+separatorWidth { + // {traceID}-{spanID}- is invalid. + return ctx, empty, errInvalidSampledByte + } + pos += separatorWidth // {traceID}-{spanID}- + + switch { + case headerLen == pos+samplingWidth: + sampling = string(contextHeader[pos]) + case headerLen == pos+parentSpanIDWidth: + // {traceID}-{spanID}-{parentSpanID} is invalid. + return ctx, empty, errInvalidScopeParentSingle + case headerLen == pos+samplingWidth+separatorWidth+parentSpanIDWidth: + sampling = string(contextHeader[pos]) + pos += samplingWidth + separatorWidth // {traceID}-{spanID}-{sampling}- + + // Validate parent span ID but we do not use it so do not + // save it. + _, err = trace.SpanIDFromHex(contextHeader[pos:]) + if err != nil { + return ctx, empty, errInvalidParentSpanIDValue + } + default: + return ctx, empty, errInvalidParentSpanIDValue + } + } + default: + return ctx, empty, errInvalidTraceIDValue + } + switch sampling { + case "": + ctx = withDeferred(ctx, true) + case "d": + ctx = withDebug(ctx, true) + scc.TraceFlags = trace.FlagsSampled + case "1": + scc.TraceFlags = trace.FlagsSampled + case "0": + // Zero value for TraceFlags sample bit is unset. + default: + return ctx, empty, errInvalidSampledByte + } + + return ctx, trace.NewSpanContext(scc), nil +} diff --git a/vendor/go.opentelemetry.io/contrib/propagators/b3/context.go b/vendor/go.opentelemetry.io/contrib/propagators/b3/context.go new file mode 100644 index 0000000..988cd2c --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/propagators/b3/context.go @@ -0,0 +1,60 @@ +// 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 b3 // import "go.opentelemetry.io/contrib/propagators/b3" + +import "context" + +type b3KeyType int + +const ( + debugKey b3KeyType = iota + deferredKey +) + +// withDebug returns a copy of parent with debug set as the debug flag value . +func withDebug(parent context.Context, debug bool) context.Context { + return context.WithValue(parent, debugKey, debug) +} + +// debugFromContext returns the debug value stored in ctx. +// +// If no debug value is stored in ctx false is returned. +func debugFromContext(ctx context.Context) bool { + if ctx == nil { + return false + } + if debug, ok := ctx.Value(debugKey).(bool); ok { + return debug + } + return false +} + +// withDeferred returns a copy of parent with deferred set as the deferred flag value . +func withDeferred(parent context.Context, deferred bool) context.Context { + return context.WithValue(parent, deferredKey, deferred) +} + +// deferredFromContext returns the deferred value stored in ctx. +// +// If no deferred value is stored in ctx false is returned. +func deferredFromContext(ctx context.Context) bool { + if ctx == nil { + return false + } + if deferred, ok := ctx.Value(deferredKey).(bool); ok { + return deferred + } + return false +} diff --git a/vendor/go.opentelemetry.io/contrib/propagators/b3/doc.go b/vendor/go.opentelemetry.io/contrib/propagators/b3/doc.go new file mode 100644 index 0000000..21578cf --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/propagators/b3/doc.go @@ -0,0 +1,17 @@ +// 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 b3 implements the B3 propagator specification as defined at +// https://github.com/openzipkin/b3-propagation +package b3 // import "go.opentelemetry.io/contrib/propagators/b3" diff --git a/vendor/go.opentelemetry.io/contrib/propagators/b3/go.mod b/vendor/go.opentelemetry.io/contrib/propagators/b3/go.mod new file mode 100644 index 0000000..78cd190 --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/propagators/b3/go.mod @@ -0,0 +1,18 @@ +module go.opentelemetry.io/contrib/propagators/b3 + +go 1.17 + +require ( + github.com/google/go-cmp v0.5.8 + github.com/stretchr/testify v1.8.0 + go.opentelemetry.io/otel v1.9.0 + go.opentelemetry.io/otel/trace v1.9.0 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/go-logr/logr v1.2.3 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/vendor/go.opentelemetry.io/contrib/propagators/b3/go.sum b/vendor/go.opentelemetry.io/contrib/propagators/b3/go.sum new file mode 100644 index 0000000..7b73094 --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/propagators/b3/go.sum @@ -0,0 +1,26 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= +github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +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/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +go.opentelemetry.io/otel v1.9.0 h1:8WZNQFIB2a71LnANS9JeyidJKKGOOremcUtb/OtHISw= +go.opentelemetry.io/otel v1.9.0/go.mod h1:np4EoPGzoPs3O67xUVNoPPcmSvsfOxNlNA4F4AC+0Eo= +go.opentelemetry.io/otel/trace v1.9.0 h1:oZaCNJUjWcg60VXWee8lJKlqhPbXAPB51URuR47pQYc= +go.opentelemetry.io/otel/trace v1.9.0/go.mod h1:2737Q0MuG8q1uILYm2YYVkAyLtOofiTNGg6VODnOiPo= +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/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vendor/go.opentelemetry.io/contrib/propagators/b3/version.go b/vendor/go.opentelemetry.io/contrib/propagators/b3/version.go new file mode 100644 index 0000000..47adc5d --- /dev/null +++ b/vendor/go.opentelemetry.io/contrib/propagators/b3/version.go @@ -0,0 +1,26 @@ +// 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 b3 // import "go.opentelemetry.io/contrib/propagators/b3" + +// Version is the current release version of the B3 propagator. +func Version() string { + return "1.9.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() +} diff --git a/vendor/modules.txt b/vendor/modules.txt index aeee45a..2a03873 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# git.autistici.org/ai3/go-common v0.0.0-20220816164411-b1b0f1bafe4c +# git.autistici.org/ai3/go-common v0.0.0-20220816190733-e0ceb95832bc ## explicit git.autistici.org/ai3/go-common git.autistici.org/ai3/go-common/clientutil @@ -58,6 +58,8 @@ github.com/prometheus/procfs/internal/fs github.com/prometheus/procfs/internal/util # go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.34.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp +# go.opentelemetry.io/contrib/propagators/b3 v1.9.0 +go.opentelemetry.io/contrib/propagators/b3 # go.opentelemetry.io/otel v1.9.0 go.opentelemetry.io/otel go.opentelemetry.io/otel/attribute -- GitLab