pax_global_header00006660000000000000000000000064151675351110014517gustar00rootroot0000000000000052 comment=07c966860b1262b0fc87963c9001e66f7bcb9464 go-grpc-0.1.3/000077500000000000000000000000001516753511100130565ustar00rootroot00000000000000go-grpc-0.1.3/.editorconfig000066400000000000000000000003111516753511100155260ustar00rootroot00000000000000root = true [*] charset = utf-8 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true indent_size = 4 indent_style = tab [*.{md,yml,yaml}] indent_size = 2 indent_style = space go-grpc-0.1.3/.github/000077500000000000000000000000001516753511100144165ustar00rootroot00000000000000go-grpc-0.1.3/.github/release.yml000066400000000000000000000010651516753511100165630ustar00rootroot00000000000000changelog: exclude: labels: - skip changelog categories: - title: ๐Ÿ’ฃ Breaking Changes labels: - change - title: ๐Ÿš€ Features labels: - enhancement - title: ๐Ÿ› Bug Fixes labels: - bug - title: ๐Ÿงช Tests labels: - tests - title: ๐Ÿ”จ Maintenance labels: - chore - title: ๐Ÿ“ Documentation labels: - documentation - title: โฌ†๏ธ Dependencies labels: - dependencies - title: Other Changes labels: - "*" go-grpc-0.1.3/.github/workflows/000077500000000000000000000000001516753511100164535ustar00rootroot00000000000000go-grpc-0.1.3/.github/workflows/ci.yml000066400000000000000000000020251516753511100175700ustar00rootroot00000000000000name: CI on: push: branches: - master tags: - "v[0-9]+.[0-9]+.[0-9]+*" pull_request: branches: - master defaults: run: shell: bash concurrency: group: ${{ github.ref_name }}-ci cancel-in-progress: true jobs: unit-tests: runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: go-version: [oldstable, stable] steps: - name: Checkout Repository uses: actions/checkout@v6 - name: Setup Golang Environment uses: actions/setup-go@v6 with: go-version: ${{ matrix.go-version }} - name: Run Unit Tests run: go test ./... -race -shuffle=on -v draft-release: runs-on: ubuntu-24.04 if: github.event_name != 'pull_request' steps: - name: Checkout Repository uses: actions/checkout@v6 - name: Create/Update Draft Release uses: lucacome/draft-release@v2.1.1 with: minor-label: "enhancement" major-label: "change" collapse-after: 20 go-grpc-0.1.3/.github/workflows/codeql.yml000066400000000000000000000022241516753511100204450ustar00rootroot00000000000000name: "CodeQL" on: push: branches: - master pull_request: branches: - master schedule: - cron: '41 15 * * 6' concurrency: group: ${{ github.ref_name }}-codeql cancel-in-progress: true jobs: analyze: name: Analyze (${{ matrix.language }}) runs-on: ubuntu-24.04 permissions: # required for all workflows security-events: write # required to fetch internal or private CodeQL packs packages: read # only required for workflows in private repositories actions: read contents: read strategy: fail-fast: false matrix: include: - language: go build-mode: autobuild steps: - name: Checkout repository uses: actions/checkout@v6 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v4 with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} queries: security-and-quality - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v4 with: category: "/language:${{matrix.language}}" go-grpc-0.1.3/.github/workflows/dependency-review.yml000066400000000000000000000011231516753511100226100ustar00rootroot00000000000000name: Dependency review on: pull_request: branches: - master permissions: contents: read # Write permissions for pull-requests are required for using the `comment-summary-in-pr` option, comment out if you aren't using this option pull-requests: write jobs: dependency-review: runs-on: ubuntu-24.04 steps: - name: Checkout Repository uses: actions/checkout@v6 - name: Dependency Review uses: actions/dependency-review-action@v4 with: config-file: "opentracing-contrib/common/dependency-review-config.yml@main" go-grpc-0.1.3/.github/workflows/labeler.yml000066400000000000000000000010701516753511100206020ustar00rootroot00000000000000name: Pull Request Labeler on: - pull_request_target permissions: contents: read jobs: triage: permissions: contents: read pull-requests: write runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v6 with: sparse-checkout: | labeler.yml sparse-checkout-cone-mode: false repository: opentracing-contrib/common - uses: actions/labeler@v6 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" sync-labels: true configuration-path: labeler.yml go-grpc-0.1.3/.github/workflows/lint.yml000066400000000000000000000014461516753511100201510ustar00rootroot00000000000000name: Lint on: push: branches: - master pull_request: branches: - master defaults: run: shell: bash concurrency: group: ${{ github.ref_name }}-lint cancel-in-progress: true jobs: lint: name: Go Lint runs-on: ubuntu-24.04 steps: - name: Checkout Repository uses: actions/checkout@v6 - name: Setup Golang Environment uses: actions/setup-go@v6 with: go-version: stable - name: Lint Go uses: golangci/golangci-lint-action@v9 actionlint: name: Actionlint runs-on: ubuntu-24.04 steps: - name: Checkout Repository uses: actions/checkout@v6 - name: Lint Actions uses: reviewdog/action-actionlint@v1 with: actionlint_flags: -shellcheck "" go-grpc-0.1.3/.gitignore000066400000000000000000000003001516753511100150370ustar00rootroot00000000000000# Binaries for programs and plugins *.exe *.exe~ *.dll *.so *.dylib # Test binary, build with `go test -c` *.test # Output of the go coverage tool, specifically when used with LiteIDE *.out go-grpc-0.1.3/.golangci.yml000066400000000000000000000037531516753511100154520ustar00rootroot00000000000000version: "2" linters: default: none enable: - asasalint - asciicheck - bidichk # - contextcheck - copyloopvar - dupword - durationcheck - errcheck - errchkjson - errname - errorlint - fatcontext - forcetypeassert - gocheckcompilerdirectives - gochecksumtype - gocritic - godot - gosec - gosmopolitan - govet - ineffassign - intrange - makezero - misspell - musttag - nilerr - noctx - nolintlint - paralleltest - perfsprint - prealloc - predeclared - reassign - revive - staticcheck - tagalign - thelper - tparallel - unconvert - unparam - unused - usestdlibvars - wastedassign - whitespace - wrapcheck settings: govet: enable-all: true misspell: locale: US revive: rules: - name: blank-imports - name: context-as-argument - name: context-keys-type - name: dot-imports - name: empty-block - name: error-naming - name: error-return - name: error-strings - name: errorf - name: exported - name: increment-decrement - name: indent-error-flow - name: package-comments - name: range - name: receiver-naming - name: redefines-builtin-id - name: superfluous-else - name: time-naming - name: unexported-return - name: unreachable-code - name: unused-parameter - name: var-declaration - name: var-naming exclusions: generated: lax presets: - comments - common-false-positives - legacy - std-error-handling paths: - third_party$ - builtin$ - examples$ issues: max-issues-per-linter: 0 max-same-issues: 0 formatters: enable: - gci - gofmt - gofumpt - goimports exclusions: generated: lax paths: - third_party$ - builtin$ - examples$ go-grpc-0.1.3/LICENSE000066400000000000000000000261351516753511100140720ustar00rootroot00000000000000 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. go-grpc-0.1.3/README.md000066400000000000000000000037601516753511100143430ustar00rootroot00000000000000# OpenTracing support for gRPC in Go [![CI](https://github.com/opentracing-contrib/go-grpc/actions/workflows/ci.yml/badge.svg)](https://github.com/opentracing-contrib/go-grpc/actions/workflows/ci.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/opentracing-contrib/go-grpc)](https://goreportcard.com/report/github.com/opentracing-contrib/go-grpc) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/opentracing-contrib/go-grpc) [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/opentracing-contrib/go-grpc?logo=github&sort=semver)](https://github.com/opentracing-contrib/go-grpc/releases/latest) The `otgrpc` package makes it easy to add OpenTracing support to gRPC-based systems in Go. ## Installation ```shell go get github.com/opentracing-contrib/go-grpc ``` ## Documentation See the basic usage examples below and the [package documentation on godoc.org](https://godoc.org/github.com/opentracing-contrib/go-grpc). ## Client-side usage example Wherever you call `grpc.Dial`: ```go // You must have some sort of OpenTracing Tracer instance on hand. var tracer opentracing.Tracer = ... ... // Set up a connection to the server peer. conn, err := grpc.Dial( address, ... // other options grpc.WithUnaryInterceptor( otgrpc.OpenTracingClientInterceptor(tracer)), grpc.WithStreamInterceptor( otgrpc.OpenTracingStreamClientInterceptor(tracer))) // All future RPC activity involving `conn` will be automatically traced. ``` ## Server-side usage example Wherever you call `grpc.NewServer`: ```go // You must have some sort of OpenTracing Tracer instance on hand. var tracer opentracing.Tracer = ... ... // Initialize the gRPC server. s := grpc.NewServer( ... // other options grpc.UnaryInterceptor( otgrpc.OpenTracingServerInterceptor(tracer)), grpc.StreamInterceptor( otgrpc.OpenTracingStreamServerInterceptor(tracer))) // All future RPC activity involving `s` will be automatically traced. ``` go-grpc-0.1.3/client.go000066400000000000000000000167621516753511100146770ustar00rootroot00000000000000package otgrpc import ( "context" "errors" "fmt" "io" "runtime" "sync/atomic" opentracing "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/log" "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) // OpenTracingClientInterceptor returns a grpc.UnaryClientInterceptor suitable // for use in a grpc.Dial call. // // For example: // // conn, err := grpc.Dial( // address, // ..., // (existing DialOptions) // grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(tracer))) // // All gRPC client spans will inject the OpenTracing SpanContext into the gRPC // metadata; they will also look in the context.Context for an active // in-process parent Span and establish a ChildOf reference if such a parent // Span could be found. func OpenTracingClientInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.UnaryClientInterceptor { otgrpcOpts := newOptions() otgrpcOpts.apply(optFuncs...) return func( ctx context.Context, method string, req, resp interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption, ) error { var err error var parentCtx opentracing.SpanContext if parent := opentracing.SpanFromContext(ctx); parent != nil { parentCtx = parent.Context() } if otgrpcOpts.inclusionFunc != nil && !otgrpcOpts.inclusionFunc(parentCtx, method, req, resp) { return invoker(ctx, method, req, resp, cc, opts...) } clientSpan := tracer.StartSpan( method, opentracing.ChildOf(parentCtx), ext.SpanKindRPCClient, gRPCComponentTag, ) defer clientSpan.Finish() ctx = injectSpanContext(ctx, tracer, clientSpan) if otgrpcOpts.logPayloads { clientSpan.LogFields(log.Object("gRPC request", req)) } err = invoker(ctx, method, req, resp, cc, opts...) if err == nil { if otgrpcOpts.logPayloads { clientSpan.LogFields(log.Object("gRPC response", resp)) } } else { SetSpanTags(clientSpan, err, true) clientSpan.LogFields(log.String("event", "error"), log.String("message", err.Error())) } if otgrpcOpts.decorator != nil { otgrpcOpts.decorator(ctx, clientSpan, method, req, resp, err) } return err } } // OpenTracingStreamClientInterceptor returns a grpc.StreamClientInterceptor suitable // for use in a grpc.Dial call. The interceptor instruments streaming RPCs by creating // a single span to correspond to the lifetime of the RPC's stream. // // For example: // // conn, err := grpc.Dial( // address, // ..., // (existing DialOptions) // grpc.WithStreamInterceptor(otgrpc.OpenTracingStreamClientInterceptor(tracer))) // // All gRPC client spans will inject the OpenTracing SpanContext into the gRPC // metadata; they will also look in the context.Context for an active // in-process parent Span and establish a ChildOf reference if such a parent // Span could be found. func OpenTracingStreamClientInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.StreamClientInterceptor { otgrpcOpts := newOptions() otgrpcOpts.apply(optFuncs...) return func( ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption, ) (grpc.ClientStream, error) { var err error var parentCtx opentracing.SpanContext if parent := opentracing.SpanFromContext(ctx); parent != nil { parentCtx = parent.Context() } if otgrpcOpts.inclusionFunc != nil && !otgrpcOpts.inclusionFunc(parentCtx, method, nil, nil) { return streamer(ctx, desc, cc, method, opts...) } clientSpan := tracer.StartSpan( method, opentracing.ChildOf(parentCtx), ext.SpanKindRPCClient, gRPCComponentTag, ) ctx = injectSpanContext(ctx, tracer, clientSpan) cs, err := streamer(ctx, desc, cc, method, opts...) if err != nil { clientSpan.LogFields(log.String("event", "error"), log.String("message", err.Error())) SetSpanTags(clientSpan, err, true) clientSpan.Finish() return cs, err } return newOpenTracingClientStream(cs, method, desc, clientSpan, otgrpcOpts), nil } } func newOpenTracingClientStream(cs grpc.ClientStream, method string, desc *grpc.StreamDesc, clientSpan opentracing.Span, otgrpcOpts *options) grpc.ClientStream { // Grab the client stream context because when the finish function or the goroutine below will be // executed it's not guaranteed cs.Context() will be valid. csCtx := cs.Context() finishChan := make(chan struct{}) isFinished := new(int32) *isFinished = 0 finishFunc := func(err error) { // The current OpenTracing specification forbids finishing a span more than // once. Since we have multiple code paths that could concurrently call // `finishFunc`, we need to add some sort of synchronization to guard against // multiple finishing. if !atomic.CompareAndSwapInt32(isFinished, 0, 1) { return } close(finishChan) defer clientSpan.Finish() if err != nil { clientSpan.LogFields(log.String("event", "error"), log.String("message", err.Error())) SetSpanTags(clientSpan, err, true) } if otgrpcOpts.decorator != nil { otgrpcOpts.decorator(csCtx, clientSpan, method, nil, nil, err) } } go func() { select { case <-finishChan: // The client span is being finished by another code path; hence, no // action is necessary. case <-csCtx.Done(): finishFunc(csCtx.Err()) } }() otcs := &openTracingClientStream{ ClientStream: cs, desc: desc, finishFunc: finishFunc, } // The `ClientStream` interface allows one to omit calling `Recv` if it's // known that the result will be `io.EOF`. See // http://stackoverflow.com/q/42915337 // In such cases, there's nothing that triggers the span to finish. We, // therefore, set a finalizer so that the span and the context goroutine will // at least be cleaned up when the garbage collector is run. runtime.SetFinalizer(otcs, func(otcs *openTracingClientStream) { otcs.finishFunc(nil) }) return otcs } type openTracingClientStream struct { grpc.ClientStream desc *grpc.StreamDesc finishFunc func(error) } func (cs *openTracingClientStream) Header() (metadata.MD, error) { md, err := cs.ClientStream.Header() if err != nil { cs.finishFunc(err) return md, fmt.Errorf("failed to get header: %w", err) } return md, nil } func (cs *openTracingClientStream) SendMsg(m interface{}) error { err := cs.ClientStream.SendMsg(m) if err != nil { cs.finishFunc(err) return fmt.Errorf("failed to send message: %w", err) } return nil } func (cs *openTracingClientStream) RecvMsg(m interface{}) error { err := cs.ClientStream.RecvMsg(m) if errors.Is(err, io.EOF) { cs.finishFunc(nil) return err //nolint:wrapcheck } else if err != nil { cs.finishFunc(err) return fmt.Errorf("failed to receive message: %w", err) } if !cs.desc.ServerStreams { cs.finishFunc(nil) } return nil } func (cs *openTracingClientStream) CloseSend() error { err := cs.ClientStream.CloseSend() if err != nil { cs.finishFunc(err) return fmt.Errorf("failed to close send: %w", err) } return nil } func injectSpanContext(ctx context.Context, tracer opentracing.Tracer, clientSpan opentracing.Span) context.Context { md, ok := metadata.FromOutgoingContext(ctx) if !ok { md = metadata.New(nil) } else { md = md.Copy() } mdWriter := metadataReaderWriter{md} err := tracer.Inject(clientSpan.Context(), opentracing.HTTPHeaders, mdWriter) // We have no better place to record an error than the Span itself :-/ if err != nil { clientSpan.LogFields(log.String("event", "Tracer.Inject() failed"), log.Error(err)) } return metadata.NewOutgoingContext(ctx, md) } go-grpc-0.1.3/errors.go000066400000000000000000000033571516753511100147310ustar00rootroot00000000000000package otgrpc import ( "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) // A Class is a set of types of outcomes (including errors) that will often // be handled in the same way. type Class string const ( Unknown Class = "0xx" // Success represents outcomes that achieved the desired results. Success Class = "2xx" // ClientError represents errors that were the client's fault. ClientError Class = "4xx" // ServerError represents errors that were the server's fault. ServerError Class = "5xx" ) // ErrorClass returns the class of the given error. func ErrorClass(err error) Class { if s, ok := status.FromError(err); ok { switch s.Code() { // Success or "success" case codes.OK, codes.Canceled: return Success // Client errors case codes.InvalidArgument, codes.NotFound, codes.AlreadyExists, codes.PermissionDenied, codes.Unauthenticated, codes.FailedPrecondition, codes.OutOfRange: return ClientError // Server errors case codes.DeadlineExceeded, codes.ResourceExhausted, codes.Aborted, codes.Unimplemented, codes.Internal, codes.Unavailable, codes.DataLoss: return ServerError // Not sure case codes.Unknown: fallthrough default: return Unknown } } return Unknown } // SetSpanTags sets one or more tags on the given span according to the // error. func SetSpanTags(span opentracing.Span, err error, client bool) { c := ErrorClass(err) code := codes.Unknown if s, ok := status.FromError(err); ok { code = s.Code() } span.SetTag("response_code", code) span.SetTag("response_class", c) if err == nil { return } if c != Success && (client || c == ServerError) { ext.Error.Set(span, true) } } go-grpc-0.1.3/errors_test.go000066400000000000000000000024561516753511100157670ustar00rootroot00000000000000package otgrpc import ( "testing" "github.com/opentracing/opentracing-go/mocktracer" "github.com/stretchr/testify/assert" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) const ( firstCode = codes.OK lastCode = codes.DataLoss ) func TestSpanTags(t *testing.T) { t.Parallel() tracer := mocktracer.New() for code := firstCode; code <= lastCode; code++ { // Client error tracer.Reset() span := tracer.StartSpan("test-trace-client") err := status.Error(code, "") SetSpanTags(span, err, true) span.Finish() // Assert added tags rawSpan := tracer.FinishedSpans()[0] expectedTags := map[string]interface{}{ "response_code": code, "response_class": ErrorClass(err), } if err != nil && ErrorClass(err) != Success { expectedTags["error"] = true } assert.Equal(t, expectedTags, rawSpan.Tags()) // Server error tracer.Reset() span = tracer.StartSpan("test-trace-server") err = status.Error(code, "") SetSpanTags(span, err, false) span.Finish() // Assert added tags rawSpan = tracer.FinishedSpans()[0] expectedTags = map[string]interface{}{ "response_code": code, "response_class": ErrorClass(err), } if err != nil && ErrorClass(err) == ServerError { expectedTags["error"] = true } assert.Equal(t, expectedTags, rawSpan.Tags()) } } go-grpc-0.1.3/go.mod000066400000000000000000000011131516753511100141600ustar00rootroot00000000000000module github.com/opentracing-contrib/go-grpc go 1.24.13 require ( github.com/opentracing/opentracing-go v1.2.0 github.com/stretchr/testify v1.11.1 google.golang.org/grpc v1.80.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/net v0.49.0 // indirect golang.org/x/sys v0.40.0 // indirect golang.org/x/text v0.33.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 // indirect google.golang.org/protobuf v1.36.11 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) go-grpc-0.1.3/go.sum000066400000000000000000000110371516753511100142130ustar00rootroot00000000000000github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 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.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= 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/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= 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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48= go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8= go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0= go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs= go.opentelemetry.io/otel/sdk v1.39.0 h1:nMLYcjVsvdui1B/4FRkwjzoRVsMK8uL/cj0OyhKzt18= go.opentelemetry.io/otel/sdk v1.39.0/go.mod h1:vDojkC4/jsTJsE+kh+LXYQlbL8CgrEcwmt1ENZszdJE= go.opentelemetry.io/otel/sdk/metric v1.39.0 h1:cXMVVFVgsIf2YL6QkRF4Urbr/aMInf+2WKg+sEJTtB8= go.opentelemetry.io/otel/sdk/metric v1.39.0/go.mod h1:xq9HEVH7qeX69/JnwEfp6fVq5wosJsY1mt4lLfYdVew= go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI= go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA= golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 h1:sNrWoksmOyF5bvJUcnmbeAmQi8baNhqg5IWaI3llQqU= google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ= google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM= google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= 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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= go-grpc-0.1.3/options.go000066400000000000000000000042411516753511100151010ustar00rootroot00000000000000package otgrpc import ( "context" opentracing "github.com/opentracing/opentracing-go" ) // Option instances may be used in OpenTracing(Server|Client)Interceptor // initialization. // // See this post about the "functional options" pattern: // http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis type Option func(o *options) // LogPayloads returns an Option that tells the OpenTracing instrumentation to // try to log application payloads in both directions. func LogPayloads() Option { return func(o *options) { o.logPayloads = true } } // SpanInclusionFunc provides an optional mechanism to decide whether or not // to trace a given gRPC call. Return true to create a Span and initiate // tracing, false to not create a Span and not trace. // // parentSpanCtx may be nil if no parent could be extraction from either the Go // context.Context (on the client) or the RPC (on the server). type SpanInclusionFunc func( parentSpanCtx opentracing.SpanContext, method string, req, resp interface{}) bool // IncludingSpans binds a IncludeSpanFunc to the options. func IncludingSpans(inclusionFunc SpanInclusionFunc) Option { return func(o *options) { o.inclusionFunc = inclusionFunc } } // SpanDecoratorFunc provides an (optional) mechanism for otgrpc users to add // arbitrary tags/logs/etc to the opentracing.Span associated with client // and/or server RPCs. type SpanDecoratorFunc func( ctx context.Context, span opentracing.Span, method string, req, resp interface{}, grpcError error) // SpanDecorator binds a function that decorates gRPC Spans. func SpanDecorator(decorator SpanDecoratorFunc) Option { return func(o *options) { o.decorator = decorator } } // The internal-only options struct. Obviously overkill at the moment; but will // scale well as production use dictates other configuration and tuning // parameters. type options struct { decorator SpanDecoratorFunc inclusionFunc SpanInclusionFunc logPayloads bool } // newOptions returns the default options. func newOptions() *options { return &options{ logPayloads: false, inclusionFunc: nil, } } func (o *options) apply(opts ...Option) { for _, opt := range opts { opt(o) } } go-grpc-0.1.3/package.go000066400000000000000000000003111516753511100147730ustar00rootroot00000000000000// Package otgrpc provides OpenTracing support for any gRPC client or server. // // See the README for simple usage examples: // https://github.com/opentracing-contrib/go-grpc/README.md package otgrpc go-grpc-0.1.3/renovate.json000066400000000000000000000002201516753511100155660ustar00rootroot00000000000000{ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "github>opentracing-contrib/common", "schedule:daily" ] } go-grpc-0.1.3/server.go000066400000000000000000000116411516753511100147160ustar00rootroot00000000000000package otgrpc import ( "context" "fmt" opentracing "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/log" "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) // OpenTracingServerInterceptor returns a grpc.UnaryServerInterceptor suitable // for use in a grpc.NewServer call. // // For example: // // s := grpc.NewServer( // ..., // (existing ServerOptions) // grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer))) // // All gRPC server spans will look for an OpenTracing SpanContext in the gRPC // metadata; if found, the server span will act as the ChildOf that RPC // SpanContext. // // Root or not, the server Span will be embedded in the context.Context for the // application-specific gRPC handler(s) to access. func OpenTracingServerInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.UnaryServerInterceptor { otgrpcOpts := newOptions() otgrpcOpts.apply(optFuncs...) return func( ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler, ) (resp interface{}, err error) { spanContext, _ := extractSpanContext(ctx, tracer) // if err != nil && !errors.Is(err, opentracing.ErrSpanContextNotFound) { // // TODO: establish some sort of error reporting mechanism here. We // // don't know where to put such an error and must rely on Tracer // // implementations to do something appropriate for the time being. // } if otgrpcOpts.inclusionFunc != nil && !otgrpcOpts.inclusionFunc(spanContext, info.FullMethod, req, nil) { return handler(ctx, req) } serverSpan := tracer.StartSpan( info.FullMethod, ext.RPCServerOption(spanContext), gRPCComponentTag, ) defer serverSpan.Finish() ctx = opentracing.ContextWithSpan(ctx, serverSpan) if otgrpcOpts.logPayloads { serverSpan.LogFields(log.Object("gRPC request", req)) } resp, err = handler(ctx, req) if err == nil { if otgrpcOpts.logPayloads { serverSpan.LogFields(log.Object("gRPC response", resp)) } } else { SetSpanTags(serverSpan, err, false) serverSpan.LogFields(log.String("event", "error"), log.String("message", err.Error())) } if otgrpcOpts.decorator != nil { otgrpcOpts.decorator(ctx, serverSpan, info.FullMethod, req, resp, err) } return resp, err } } // OpenTracingStreamServerInterceptor returns a grpc.StreamServerInterceptor suitable // for use in a grpc.NewServer call. The interceptor instruments streaming RPCs by // creating a single span to correspond to the lifetime of the RPC's stream. // // For example: // // s := grpc.NewServer( // ..., // (existing ServerOptions) // grpc.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(tracer))) // // All gRPC server spans will look for an OpenTracing SpanContext in the gRPC // metadata; if found, the server span will act as the ChildOf that RPC // SpanContext. // // Root or not, the server Span will be embedded in the context.Context for the // application-specific gRPC handler(s) to access. func OpenTracingStreamServerInterceptor(tracer opentracing.Tracer, optFuncs ...Option) grpc.StreamServerInterceptor { otgrpcOpts := newOptions() otgrpcOpts.apply(optFuncs...) return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { spanContext, _ := extractSpanContext(ss.Context(), tracer) // if err != nil && !errors.Is(err, opentracing.ErrSpanContextNotFound) { // // TODO: establish some sort of error reporting mechanism here. We // // don't know where to put such an error and must rely on Tracer // // implementations to do something appropriate for the time being. // } if otgrpcOpts.inclusionFunc != nil && !otgrpcOpts.inclusionFunc(spanContext, info.FullMethod, nil, nil) { return handler(srv, ss) } serverSpan := tracer.StartSpan( info.FullMethod, ext.RPCServerOption(spanContext), gRPCComponentTag, ) defer serverSpan.Finish() ss = &openTracingServerStream{ ServerStream: ss, ctx: opentracing.ContextWithSpan(ss.Context(), serverSpan), } err := handler(srv, ss) if err != nil { SetSpanTags(serverSpan, err, false) serverSpan.LogFields(log.String("event", "error"), log.String("message", err.Error())) } if otgrpcOpts.decorator != nil { otgrpcOpts.decorator(ss.Context(), serverSpan, info.FullMethod, nil, nil, err) } return err } } type openTracingServerStream struct { grpc.ServerStream ctx context.Context } func (ss *openTracingServerStream) Context() context.Context { return ss.ctx } func extractSpanContext(ctx context.Context, tracer opentracing.Tracer) (opentracing.SpanContext, error) { md, ok := metadata.FromIncomingContext(ctx) if !ok { md = metadata.New(nil) } spanContext, err := tracer.Extract(opentracing.HTTPHeaders, metadataReaderWriter{md}) if err != nil { return nil, fmt.Errorf("failed to extract span context: %w", err) } return spanContext, nil } go-grpc-0.1.3/shared.go000066400000000000000000000020321516753511100146500ustar00rootroot00000000000000package otgrpc import ( "strings" opentracing "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" "google.golang.org/grpc/metadata" ) // Morally a const:. var gRPCComponentTag = opentracing.Tag{Key: string(ext.Component), Value: "gRPC"} // metadataReaderWriter satisfies both the opentracing.TextMapReader and // opentracing.TextMapWriter interfaces. type metadataReaderWriter struct { metadata.MD } func (w metadataReaderWriter) Set(key, val string) { // The GRPC HPACK implementation rejects any uppercase keys here. // // As such, since the HTTP_HEADERS format is case-insensitive anyway, we // blindly lowercase the key (which is guaranteed to work in the // Inject/Extract sense per the OpenTracing spec). key = strings.ToLower(key) w.MD[key] = append(w.MD[key], val) } func (w metadataReaderWriter) ForeachKey(handler func(key, val string) error) error { for k, vals := range w.MD { for _, v := range vals { if err := handler(k, v); err != nil { return err } } } return nil } go-grpc-0.1.3/test/000077500000000000000000000000001516753511100140355ustar00rootroot00000000000000go-grpc-0.1.3/test/go.mod000066400000000000000000000013311516753511100151410ustar00rootroot00000000000000module github.com/opentracing-contrib/go-grpc/test go 1.24.13 replace github.com/opentracing-contrib/go-grpc => ../ require ( github.com/golang/protobuf v1.5.4 github.com/opentracing-contrib/go-grpc v0.0.0 github.com/opentracing/opentracing-go v1.2.0 github.com/stretchr/testify v1.11.1 google.golang.org/grpc v1.80.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/net v0.49.0 // indirect golang.org/x/sys v0.40.0 // indirect golang.org/x/text v0.33.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 // indirect google.golang.org/protobuf v1.36.11 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) go-grpc-0.1.3/test/go.sum000066400000000000000000000110371516753511100151720ustar00rootroot00000000000000github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 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.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= 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/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= 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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= go.opentelemetry.io/otel v1.39.0 h1:8yPrr/S0ND9QEfTfdP9V+SiwT4E0G7Y5MO7p85nis48= go.opentelemetry.io/otel v1.39.0/go.mod h1:kLlFTywNWrFyEdH0oj2xK0bFYZtHRYUdv1NklR/tgc8= go.opentelemetry.io/otel/metric v1.39.0 h1:d1UzonvEZriVfpNKEVmHXbdf909uGTOQjA0HF0Ls5Q0= go.opentelemetry.io/otel/metric v1.39.0/go.mod h1:jrZSWL33sD7bBxg1xjrqyDjnuzTUB0x1nBERXd7Ftcs= go.opentelemetry.io/otel/sdk v1.39.0 h1:nMLYcjVsvdui1B/4FRkwjzoRVsMK8uL/cj0OyhKzt18= go.opentelemetry.io/otel/sdk v1.39.0/go.mod h1:vDojkC4/jsTJsE+kh+LXYQlbL8CgrEcwmt1ENZszdJE= go.opentelemetry.io/otel/sdk/metric v1.39.0 h1:cXMVVFVgsIf2YL6QkRF4Urbr/aMInf+2WKg+sEJTtB8= go.opentelemetry.io/otel/sdk/metric v1.39.0/go.mod h1:xq9HEVH7qeX69/JnwEfp6fVq5wosJsY1mt4lLfYdVew= go.opentelemetry.io/otel/trace v1.39.0 h1:2d2vfpEDmCJ5zVYz7ijaJdOF59xLomrvj7bjt6/qCJI= go.opentelemetry.io/otel/trace v1.39.0/go.mod h1:88w4/PnZSazkGzz/w84VHpQafiU4EtqqlVdxWy+rNOA= golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE= golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516 h1:sNrWoksmOyF5bvJUcnmbeAmQi8baNhqg5IWaI3llQqU= google.golang.org/genproto/googleapis/rpc v0.0.0-20260120221211-b8f7ae30c516/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ= google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM= google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= 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.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= go-grpc-0.1.3/test/interceptor_test.go000066400000000000000000000175551516753511100177760ustar00rootroot00000000000000package interceptor_test import ( "context" "errors" "io" "net" "testing" "time" otgrpc "github.com/opentracing-contrib/go-grpc" testpb "github.com/opentracing-contrib/go-grpc/test/otgrpc_testing" "github.com/opentracing/opentracing-go/mocktracer" "github.com/stretchr/testify/assert" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) const ( streamLength = 5 ) type testServer struct{} func (s *testServer) UnaryCall(_ context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { return &testpb.SimpleResponse{Payload: in.Payload}, nil } func (s *testServer) StreamingOutputCall(in *testpb.SimpleRequest, stream testpb.TestService_StreamingOutputCallServer) error { for range streamLength { if err := stream.Send(&testpb.SimpleResponse{Payload: in.Payload}); err != nil { return err } } return nil } func (s *testServer) StreamingInputCall(stream testpb.TestService_StreamingInputCallServer) error { sum := int32(0) for { in, err := stream.Recv() if errors.Is(err, io.EOF) { break } if err != nil { return err } sum += in.Payload } return stream.SendAndClose(&testpb.SimpleResponse{Payload: sum}) } func (s *testServer) StreamingBidirectionalCall(stream testpb.TestService_StreamingBidirectionalCallServer) error { for { in, err := stream.Recv() if errors.Is(err, io.EOF) { return nil } if err != nil { return err } if err = stream.Send(&testpb.SimpleResponse{Payload: in.Payload}); err != nil { return err } } } type env struct { unaryClientInt grpc.UnaryClientInterceptor streamClientInt grpc.StreamClientInterceptor unaryServerInt grpc.UnaryServerInterceptor streamServerInt grpc.StreamServerInterceptor } type test struct { t *testing.T e env srv *grpc.Server cc *grpc.ClientConn c testpb.TestServiceClient } func newTest(t *testing.T, e env) *test { t.Helper() te := &test{ t: t, e: e, } // Set up the server. sOpts := []grpc.ServerOption{} if e.unaryServerInt != nil { sOpts = append(sOpts, grpc.UnaryInterceptor(e.unaryServerInt)) } if e.streamServerInt != nil { sOpts = append(sOpts, grpc.StreamInterceptor(e.streamServerInt)) } lis, err := net.Listen("tcp", "localhost:0") if err != nil { te.t.Fatalf("Failed to listen: %v", err) } te.srv = grpc.NewServer(sOpts...) testpb.RegisterTestServiceServer(te.srv, &testServer{}) errChan := make(chan error, 1) go func() { errChan <- te.srv.Serve(lis) }() // Check for immediate server startup errors select { case errServe := <-errChan: if errServe != nil { te.t.Fatalf("Failed to serve: %v", errServe) } default: } // Set up a connection to the server. cOpts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())} if e.unaryClientInt != nil { cOpts = append(cOpts, grpc.WithUnaryInterceptor(e.unaryClientInt)) } if e.streamClientInt != nil { cOpts = append(cOpts, grpc.WithStreamInterceptor(e.streamClientInt)) } _, port, err := net.SplitHostPort(lis.Addr().String()) if err != nil { te.t.Fatalf("Failed to parse listener address: %v", err) } srvAddr := "localhost:" + port te.cc, err = grpc.NewClient(srvAddr, cOpts...) if err != nil { te.t.Fatalf("Dial(%q) = %v", srvAddr, err) } te.c = testpb.NewTestServiceClient(te.cc) return te } func (te *test) tearDown() { te.cc.Close() } func assertChildParentSpans(t *testing.T, tracer *mocktracer.MockTracer) { t.Helper() spans := tracer.FinishedSpans() assert.Equal(t, 2, len(spans)) if len(spans) != 2 { t.Fatalf("Incorrect span length") } parent := spans[1] child := spans[0] parentContext, ok := parent.Context().(mocktracer.MockSpanContext) if !ok { t.Fatalf("Failed to assert parent context as mocktracer.MockSpanContext") } assert.Equal(t, child.ParentID, parentContext.SpanID) } func TestUnaryOpenTracing(t *testing.T) { t.Parallel() tracer := mocktracer.New() e := env{ unaryClientInt: otgrpc.OpenTracingClientInterceptor(tracer), unaryServerInt: otgrpc.OpenTracingServerInterceptor(tracer), } te := newTest(t, e) defer te.tearDown() payload := int32(0) resp, err := te.c.UnaryCall(context.Background(), &testpb.SimpleRequest{Payload: payload}) if err != nil { t.Fatalf("Failed UnaryCall: %v", err) } assert.Equal(t, payload, resp.Payload) assertChildParentSpans(t, tracer) } func TestStreamingOutputCallOpenTracing(t *testing.T) { t.Parallel() tracer := mocktracer.New() e := env{ streamClientInt: otgrpc.OpenTracingStreamClientInterceptor(tracer), streamServerInt: otgrpc.OpenTracingStreamServerInterceptor(tracer), } te := newTest(t, e) defer te.tearDown() payload := int32(0) stream, err := te.c.StreamingOutputCall(context.Background(), &testpb.SimpleRequest{Payload: payload}) if err != nil { t.Fatalf("Failed StreamingOutputCall: %v", err) } for { resp, err := stream.Recv() if errors.Is(err, io.EOF) { break } if err != nil { t.Fatalf("Failed StreamingOutputCall: %v", err) } assert.Equal(t, payload, resp.Payload) } assertChildParentSpans(t, tracer) } func TestStreamingInputCallOpenTracing(t *testing.T) { t.Parallel() tracer := mocktracer.New() e := env{ streamClientInt: otgrpc.OpenTracingStreamClientInterceptor(tracer), streamServerInt: otgrpc.OpenTracingStreamServerInterceptor(tracer), } te := newTest(t, e) defer te.tearDown() payload := int32(1) stream, err := te.c.StreamingInputCall(context.Background()) if err != nil { t.Fatalf("Failed StreamingInputCall: %v", err) } for range streamLength { if err = stream.Send(&testpb.SimpleRequest{Payload: payload}); err != nil { t.Fatalf("Failed StreamingInputCall: %v", err) } } resp, err := stream.CloseAndRecv() if err != nil { t.Fatalf("Failed StreamingInputCall: %v", err) } assert.Equal(t, streamLength*payload, resp.Payload) assertChildParentSpans(t, tracer) } func TestStreamingBidirectionalCallOpenTracing(t *testing.T) { t.Parallel() tracer := mocktracer.New() e := env{ streamClientInt: otgrpc.OpenTracingStreamClientInterceptor(tracer), streamServerInt: otgrpc.OpenTracingStreamServerInterceptor(tracer), } te := newTest(t, e) defer te.tearDown() payload := int32(0) stream, err := te.c.StreamingBidirectionalCall(context.Background()) if err != nil { t.Fatalf("Failed StreamingInputCall: %v", err) } errChan := make(chan error, 1) go func() { for range streamLength { if err := stream.Send(&testpb.SimpleRequest{Payload: payload}); err != nil { errChan <- err return } } if err := stream.CloseSend(); err != nil { errChan <- err return } errChan <- nil }() if err := <-errChan; err != nil { t.Fatalf("Failed StreamingInputCall: %v", err) } for { resp, err := stream.Recv() if errors.Is(err, io.EOF) { break } if err != nil { t.Fatalf("Failed StreamingOutputCall: %v", err) } assert.Equal(t, payload, resp.Payload) } assertChildParentSpans(t, tracer) } func TestStreamingContextCancellationOpenTracing(t *testing.T) { t.Parallel() tracer := mocktracer.New() e := env{ streamClientInt: otgrpc.OpenTracingStreamClientInterceptor(tracer), streamServerInt: otgrpc.OpenTracingStreamServerInterceptor(tracer), } te := newTest(t, e) defer te.tearDown() payload := int32(0) ctx, cancel := context.WithCancel(context.Background()) _, err := te.c.StreamingOutputCall(ctx, &testpb.SimpleRequest{Payload: payload}) if err != nil { t.Fatalf("Failed StreamingOutputCall: %v", err) } cancel() time.Sleep(100 * time.Millisecond) spans := tracer.FinishedSpans() assert.Equal(t, 2, len(spans)) if len(spans) != 2 { t.Fatalf("Incorrect span length") } parent := spans[0] child := spans[1] parentContext, ok := parent.Context().(mocktracer.MockSpanContext) if !ok { t.Fatalf("Failed to assert parent context as mocktracer.MockSpanContext") } assert.Equal(t, child.ParentID, parentContext.SpanID) errorTag, ok := parent.Tag("error").(bool) if !ok { t.Fatalf("Failed to assert error tag as bool") } assert.True(t, errorTag) } go-grpc-0.1.3/test/otgrpc_testing/000077500000000000000000000000001516753511100170705ustar00rootroot00000000000000go-grpc-0.1.3/test/otgrpc_testing/test.pb.go000066400000000000000000000266571516753511100210160ustar00rootroot00000000000000// Code generated by protoc-gen-go. // source: test.proto // DO NOT EDIT! /* Package otgrpc_testing is a generated protocol buffer package. It is generated from these files: test.proto It has these top-level messages: SimpleRequest SimpleResponse */ package otgrpc_testing import proto "github.com/golang/protobuf/proto" import fmt "fmt" import math "math" import ( context "context" grpc "google.golang.org/grpc" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type SimpleRequest struct { Payload int32 `protobuf:"varint,1,opt,name=payload" json:"payload,omitempty"` } func (m *SimpleRequest) Reset() { *m = SimpleRequest{} } func (m *SimpleRequest) String() string { return proto.CompactTextString(m) } func (*SimpleRequest) ProtoMessage() {} func (*SimpleRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } func (m *SimpleRequest) GetPayload() int32 { if m != nil { return m.Payload } return 0 } type SimpleResponse struct { Payload int32 `protobuf:"varint,1,opt,name=payload" json:"payload,omitempty"` } func (m *SimpleResponse) Reset() { *m = SimpleResponse{} } func (m *SimpleResponse) String() string { return proto.CompactTextString(m) } func (*SimpleResponse) ProtoMessage() {} func (*SimpleResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } func (m *SimpleResponse) GetPayload() int32 { if m != nil { return m.Payload } return 0 } func init() { proto.RegisterType((*SimpleRequest)(nil), "otgrpc.testing.SimpleRequest") proto.RegisterType((*SimpleResponse)(nil), "otgrpc.testing.SimpleResponse") } // Reference imports to suppress errors if they are not otherwise used. var _ context.Context var _ grpc.ClientConn // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. const _ = grpc.SupportPackageIsVersion4 // Client API for TestService service type TestServiceClient interface { UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error) StreamingOutputCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (TestService_StreamingOutputCallClient, error) StreamingInputCall(ctx context.Context, opts ...grpc.CallOption) (TestService_StreamingInputCallClient, error) StreamingBidirectionalCall(ctx context.Context, opts ...grpc.CallOption) (TestService_StreamingBidirectionalCallClient, error) } type testServiceClient struct { cc *grpc.ClientConn } func NewTestServiceClient(cc *grpc.ClientConn) TestServiceClient { return &testServiceClient{cc} } func (c *testServiceClient) UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error) { out := new(SimpleResponse) err := grpc.Invoke(ctx, "/otgrpc.testing.TestService/UnaryCall", in, out, c.cc, opts...) if err != nil { return nil, err } return out, nil } func (c *testServiceClient) StreamingOutputCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (TestService_StreamingOutputCallClient, error) { stream, err := grpc.NewClientStream(ctx, &_TestService_serviceDesc.Streams[0], c.cc, "/otgrpc.testing.TestService/StreamingOutputCall", opts...) if err != nil { return nil, err } x := &testServiceStreamingOutputCallClient{stream} if err := x.ClientStream.SendMsg(in); err != nil { return nil, err } if err := x.ClientStream.CloseSend(); err != nil { return nil, err } return x, nil } type TestService_StreamingOutputCallClient interface { Recv() (*SimpleResponse, error) grpc.ClientStream } type testServiceStreamingOutputCallClient struct { grpc.ClientStream } func (x *testServiceStreamingOutputCallClient) Recv() (*SimpleResponse, error) { m := new(SimpleResponse) if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err } return m, nil } func (c *testServiceClient) StreamingInputCall(ctx context.Context, opts ...grpc.CallOption) (TestService_StreamingInputCallClient, error) { stream, err := grpc.NewClientStream(ctx, &_TestService_serviceDesc.Streams[1], c.cc, "/otgrpc.testing.TestService/StreamingInputCall", opts...) if err != nil { return nil, err } x := &testServiceStreamingInputCallClient{stream} return x, nil } type TestService_StreamingInputCallClient interface { Send(*SimpleRequest) error CloseAndRecv() (*SimpleResponse, error) grpc.ClientStream } type testServiceStreamingInputCallClient struct { grpc.ClientStream } func (x *testServiceStreamingInputCallClient) Send(m *SimpleRequest) error { return x.ClientStream.SendMsg(m) } func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*SimpleResponse, error) { if err := x.ClientStream.CloseSend(); err != nil { return nil, err } m := new(SimpleResponse) if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err } return m, nil } func (c *testServiceClient) StreamingBidirectionalCall(ctx context.Context, opts ...grpc.CallOption) (TestService_StreamingBidirectionalCallClient, error) { stream, err := grpc.NewClientStream(ctx, &_TestService_serviceDesc.Streams[2], c.cc, "/otgrpc.testing.TestService/StreamingBidirectionalCall", opts...) if err != nil { return nil, err } x := &testServiceStreamingBidirectionalCallClient{stream} return x, nil } type TestService_StreamingBidirectionalCallClient interface { Send(*SimpleRequest) error Recv() (*SimpleResponse, error) grpc.ClientStream } type testServiceStreamingBidirectionalCallClient struct { grpc.ClientStream } func (x *testServiceStreamingBidirectionalCallClient) Send(m *SimpleRequest) error { return x.ClientStream.SendMsg(m) } func (x *testServiceStreamingBidirectionalCallClient) Recv() (*SimpleResponse, error) { m := new(SimpleResponse) if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err } return m, nil } // Server API for TestService service type TestServiceServer interface { UnaryCall(context.Context, *SimpleRequest) (*SimpleResponse, error) StreamingOutputCall(*SimpleRequest, TestService_StreamingOutputCallServer) error StreamingInputCall(TestService_StreamingInputCallServer) error StreamingBidirectionalCall(TestService_StreamingBidirectionalCallServer) error } func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) } func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(SimpleRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { return srv.(TestServiceServer).UnaryCall(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, FullMethod: "/otgrpc.testing.TestService/UnaryCall", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(TestServiceServer).UnaryCall(ctx, req.(*SimpleRequest)) } return interceptor(ctx, in, info, handler) } func _TestService_StreamingOutputCall_Handler(srv interface{}, stream grpc.ServerStream) error { m := new(SimpleRequest) if err := stream.RecvMsg(m); err != nil { return err } return srv.(TestServiceServer).StreamingOutputCall(m, &testServiceStreamingOutputCallServer{stream}) } type TestService_StreamingOutputCallServer interface { Send(*SimpleResponse) error grpc.ServerStream } type testServiceStreamingOutputCallServer struct { grpc.ServerStream } func (x *testServiceStreamingOutputCallServer) Send(m *SimpleResponse) error { return x.ServerStream.SendMsg(m) } func _TestService_StreamingInputCall_Handler(srv interface{}, stream grpc.ServerStream) error { return srv.(TestServiceServer).StreamingInputCall(&testServiceStreamingInputCallServer{stream}) } type TestService_StreamingInputCallServer interface { SendAndClose(*SimpleResponse) error Recv() (*SimpleRequest, error) grpc.ServerStream } type testServiceStreamingInputCallServer struct { grpc.ServerStream } func (x *testServiceStreamingInputCallServer) SendAndClose(m *SimpleResponse) error { return x.ServerStream.SendMsg(m) } func (x *testServiceStreamingInputCallServer) Recv() (*SimpleRequest, error) { m := new(SimpleRequest) if err := x.ServerStream.RecvMsg(m); err != nil { return nil, err } return m, nil } func _TestService_StreamingBidirectionalCall_Handler(srv interface{}, stream grpc.ServerStream) error { return srv.(TestServiceServer).StreamingBidirectionalCall(&testServiceStreamingBidirectionalCallServer{stream}) } type TestService_StreamingBidirectionalCallServer interface { Send(*SimpleResponse) error Recv() (*SimpleRequest, error) grpc.ServerStream } type testServiceStreamingBidirectionalCallServer struct { grpc.ServerStream } func (x *testServiceStreamingBidirectionalCallServer) Send(m *SimpleResponse) error { return x.ServerStream.SendMsg(m) } func (x *testServiceStreamingBidirectionalCallServer) Recv() (*SimpleRequest, error) { m := new(SimpleRequest) if err := x.ServerStream.RecvMsg(m); err != nil { return nil, err } return m, nil } var _TestService_serviceDesc = grpc.ServiceDesc{ ServiceName: "otgrpc.testing.TestService", HandlerType: (*TestServiceServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "UnaryCall", Handler: _TestService_UnaryCall_Handler, }, }, Streams: []grpc.StreamDesc{ { StreamName: "StreamingOutputCall", Handler: _TestService_StreamingOutputCall_Handler, ServerStreams: true, }, { StreamName: "StreamingInputCall", Handler: _TestService_StreamingInputCall_Handler, ClientStreams: true, }, { StreamName: "StreamingBidirectionalCall", Handler: _TestService_StreamingBidirectionalCall_Handler, ServerStreams: true, ClientStreams: true, }, }, Metadata: "test.proto", } func init() { proto.RegisterFile("test.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ // 210 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2a, 0x49, 0x2d, 0x2e, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xcb, 0x2f, 0x49, 0x2f, 0x2a, 0x48, 0xd6, 0x03, 0x09, 0x65, 0xe6, 0xa5, 0x2b, 0x69, 0x72, 0xf1, 0x06, 0x67, 0xe6, 0x16, 0xe4, 0xa4, 0x06, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x08, 0x49, 0x70, 0xb1, 0x17, 0x24, 0x56, 0xe6, 0xe4, 0x27, 0xa6, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x06, 0xc1, 0xb8, 0x4a, 0x5a, 0x5c, 0x7c, 0x30, 0xa5, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0xb8, 0xd5, 0x1a, 0xbd, 0x64, 0xe2, 0xe2, 0x0e, 0x49, 0x2d, 0x2e, 0x09, 0x4e, 0x2d, 0x2a, 0xcb, 0x4c, 0x4e, 0x15, 0xf2, 0xe2, 0xe2, 0x0c, 0xcd, 0x4b, 0x2c, 0xaa, 0x74, 0x4e, 0xcc, 0xc9, 0x11, 0x92, 0xd5, 0x43, 0x75, 0x84, 0x1e, 0x8a, 0x0b, 0xa4, 0xe4, 0x70, 0x49, 0x43, 0x6d, 0x0d, 0xe3, 0x12, 0x0e, 0x2e, 0x29, 0x4a, 0x4d, 0xcc, 0xcd, 0xcc, 0x4b, 0xf7, 0x2f, 0x2d, 0x29, 0x28, 0x2d, 0xa1, 0x82, 0xa9, 0x06, 0x8c, 0x42, 0xa1, 0x5c, 0x42, 0x70, 0x73, 0x3d, 0xf3, 0xa8, 0x63, 0xac, 0x06, 0xa3, 0x50, 0x3c, 0x97, 0x14, 0xdc, 0x58, 0xa7, 0xcc, 0x94, 0xcc, 0xa2, 0xd4, 0xe4, 0x92, 0xcc, 0xfc, 0xbc, 0xc4, 0x1c, 0xaa, 0x18, 0x6f, 0xc0, 0x98, 0xc4, 0x06, 0x8e, 0x59, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xfd, 0x50, 0x3e, 0xe4, 0xe7, 0x01, 0x00, 0x00, } go-grpc-0.1.3/test/otgrpc_testing/test.proto000066400000000000000000000007151516753511100211370ustar00rootroot00000000000000syntax = "proto3"; package otgrpc.testing; message SimpleRequest { int32 payload = 1; } message SimpleResponse { int32 payload = 1; } service TestService { rpc UnaryCall(SimpleRequest) returns (SimpleResponse); rpc StreamingOutputCall(SimpleRequest) returns (stream SimpleResponse); rpc StreamingInputCall(stream SimpleRequest) returns (SimpleResponse); rpc StreamingBidirectionalCall(stream SimpleRequest) returns (stream SimpleResponse); }