Compare commits
No commits in common. "v3" and "v3.10.3" have entirely different histories.
@ -1,29 +0,0 @@
|
|||||||
name: lint
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [opened, reopened, synchronize]
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- v3
|
|
||||||
- v4
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
filter: 'blob:none'
|
|
||||||
- name: setup go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
cache-dependency-path: "**/*.sum"
|
|
||||||
go-version: 'stable'
|
|
||||||
- name: setup deps
|
|
||||||
run: go get -v ./...
|
|
||||||
- name: run lint
|
|
||||||
uses: https://github.com/golangci/golangci-lint-action@v6
|
|
||||||
with:
|
|
||||||
version: 'latest'
|
|
@ -1,34 +0,0 @@
|
|||||||
name: test
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [opened, reopened, synchronize]
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- v3
|
|
||||||
- v4
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- v3
|
|
||||||
- v4
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
filter: 'blob:none'
|
|
||||||
- name: setup go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
cache-dependency-path: "**/*.sum"
|
|
||||||
go-version: 'stable'
|
|
||||||
- name: setup deps
|
|
||||||
run: go get -v ./...
|
|
||||||
- name: run test
|
|
||||||
env:
|
|
||||||
INTEGRATION_TESTS: yes
|
|
||||||
run: go test -mod readonly -v ./...
|
|
@ -1,53 +0,0 @@
|
|||||||
name: test
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
types: [opened, reopened, synchronize]
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- v3
|
|
||||||
- v4
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- v3
|
|
||||||
- v4
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
filter: 'blob:none'
|
|
||||||
- name: checkout tests
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: master
|
|
||||||
filter: 'blob:none'
|
|
||||||
repository: unistack-org/micro-tests
|
|
||||||
path: micro-tests
|
|
||||||
- name: setup go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
cache-dependency-path: "**/*.sum"
|
|
||||||
go-version: 'stable'
|
|
||||||
- name: setup go work
|
|
||||||
env:
|
|
||||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
|
||||||
run: |
|
|
||||||
go work init
|
|
||||||
go work use .
|
|
||||||
go work use micro-tests
|
|
||||||
- name: setup deps
|
|
||||||
env:
|
|
||||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
|
||||||
run: go get -v ./...
|
|
||||||
- name: run tests
|
|
||||||
env:
|
|
||||||
INTEGRATION_TESTS: yes
|
|
||||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
|
||||||
run: |
|
|
||||||
cd micro-tests
|
|
||||||
go test -mod readonly -v ./... || true
|
|
19
.github/dependabot.yml
vendored
Normal file
19
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# To get started with Dependabot version updates, you'll need to specify which
|
||||||
|
# package ecosystems to update and where the package manifests are located.
|
||||||
|
# Please see the documentation for all configuration options:
|
||||||
|
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
|
||||||
|
# Maintain dependencies for GitHub Actions
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
||||||
|
|
||||||
|
# Maintain dependencies for Golang
|
||||||
|
- package-ecosystem: "gomod"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "daily"
|
20
.github/workflows/autoapprove.yml
vendored
Normal file
20
.github/workflows/autoapprove.yml
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
name: "autoapprove"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [assigned, opened, synchronize, reopened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
autoapprove:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: approve
|
||||||
|
uses: hmarr/auto-approve-action@v3
|
||||||
|
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
||||||
|
id: approve
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
21
.github/workflows/automerge.yml
vendored
Normal file
21
.github/workflows/automerge.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
name: "automerge"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [assigned, opened, synchronize, reopened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
automerge:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.actor == 'vtolstov'
|
||||||
|
steps:
|
||||||
|
- name: merge
|
||||||
|
id: merge
|
||||||
|
run: gh pr merge --auto --merge "$PR_URL"
|
||||||
|
env:
|
||||||
|
PR_URL: ${{github.event.pull_request.html_url}}
|
||||||
|
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
47
.github/workflows/build.yml
vendored
Normal file
47
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
name: build
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- v3
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: setup
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 1.17
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: ${{ runner.os }}-go-
|
||||||
|
- name: deps
|
||||||
|
run: go get -v -t -d ./...
|
||||||
|
- name: test
|
||||||
|
env:
|
||||||
|
INTEGRATION_TESTS: yes
|
||||||
|
run: go test -mod readonly -v ./...
|
||||||
|
lint:
|
||||||
|
name: lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: lint
|
||||||
|
uses: golangci/golangci-lint-action@v3.4.0
|
||||||
|
continue-on-error: true
|
||||||
|
with:
|
||||||
|
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||||
|
version: v1.30
|
||||||
|
# Optional: working directory, useful for monorepos
|
||||||
|
# working-directory: somedir
|
||||||
|
# Optional: golangci-lint command line arguments.
|
||||||
|
# args: --issues-exit-code=0
|
||||||
|
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||||
|
# only-new-issues: true
|
78
.github/workflows/codeql-analysis.yml
vendored
Normal file
78
.github/workflows/codeql-analysis.yml
vendored
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: "codeql"
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows: ["prbuild"]
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
|
push:
|
||||||
|
branches: [ master, v3 ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ master, v3 ]
|
||||||
|
schedule:
|
||||||
|
- cron: '34 1 * * 0'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'go' ]
|
||||||
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||||
|
# Learn more:
|
||||||
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: setup
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 1.17
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: init
|
||||||
|
uses: github/codeql-action/init@v2
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
#- run: |
|
||||||
|
# make bootstrap
|
||||||
|
# make release
|
||||||
|
|
||||||
|
- name: analyze
|
||||||
|
uses: github/codeql-action/analyze@v2
|
27
.github/workflows/dependabot-automerge.yml
vendored
Normal file
27
.github/workflows/dependabot-automerge.yml
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
name: "dependabot-automerge"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [assigned, opened, synchronize, reopened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
automerge:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.actor == 'dependabot[bot]'
|
||||||
|
steps:
|
||||||
|
- name: metadata
|
||||||
|
id: metadata
|
||||||
|
uses: dependabot/fetch-metadata@v1.3.6
|
||||||
|
with:
|
||||||
|
github-token: "${{ secrets.TOKEN }}"
|
||||||
|
- name: merge
|
||||||
|
id: merge
|
||||||
|
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
|
||||||
|
run: gh pr merge --auto --merge "$PR_URL"
|
||||||
|
env:
|
||||||
|
PR_URL: ${{github.event.pull_request.html_url}}
|
||||||
|
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
47
.github/workflows/pr.yml
vendored
Normal file
47
.github/workflows/pr.yml
vendored
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
name: prbuild
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- v3
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: setup
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 1.17
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: cache
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: ${{ runner.os }}-go-
|
||||||
|
- name: deps
|
||||||
|
run: go get -v -t -d ./...
|
||||||
|
- name: test
|
||||||
|
env:
|
||||||
|
INTEGRATION_TESTS: yes
|
||||||
|
run: go test -mod readonly -v ./...
|
||||||
|
lint:
|
||||||
|
name: lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: lint
|
||||||
|
uses: golangci/golangci-lint-action@v3.4.0
|
||||||
|
continue-on-error: true
|
||||||
|
with:
|
||||||
|
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||||
|
version: v1.30
|
||||||
|
# Optional: working directory, useful for monorepos
|
||||||
|
# working-directory: somedir
|
||||||
|
# Optional: golangci-lint command line arguments.
|
||||||
|
# args: --issues-exit-code=0
|
||||||
|
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||||
|
# only-new-issues: true
|
@ -1,5 +0,0 @@
|
|||||||
run:
|
|
||||||
concurrency: 8
|
|
||||||
deadline: 5m
|
|
||||||
issues-exit-code: 1
|
|
||||||
tests: true
|
|
16
go.mod
16
go.mod
@ -1,17 +1,11 @@
|
|||||||
module go.unistack.org/micro-tracer-opentracing/v3
|
module go.unistack.org/micro-tracer-opentracing/v3
|
||||||
|
|
||||||
go 1.22.0
|
go 1.16
|
||||||
|
|
||||||
toolchain go1.23.4
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/opentracing/opentracing-go v1.2.0
|
github.com/opentracing/opentracing-go v1.2.0
|
||||||
go.opentelemetry.io/otel v1.33.0
|
github.com/stretchr/testify v1.5.1 // indirect
|
||||||
go.unistack.org/micro/v3 v3.11.17
|
go.unistack.org/micro/v3 v3.10.24
|
||||||
)
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
|
||||||
github.com/stretchr/testify v1.10.0 // indirect
|
|
||||||
)
|
)
|
||||||
|
35
go.sum
35
go.sum
@ -1,24 +1,25 @@
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/imdario/mergo v0.3.14/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
|
||||||
|
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
|
||||||
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
|
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/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
|
||||||
|
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||||
|
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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=
|
go.unistack.org/micro/v3 v3.10.19 h1:JtPacglETxHyb+GiuMdfxqGtnWSTYXPQm6PlDQfNIl8=
|
||||||
go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
|
go.unistack.org/micro/v3 v3.10.19/go.mod h1:XIArw29f0b3uvF4cq96X/nQt2f0J2OGnjh8J+DBbC0s=
|
||||||
go.opentelemetry.io/otel v1.33.0 h1:/FerN9bax5LoK51X/sI0SVYrjSE0/yUL7DpxW4K3FWw=
|
go.unistack.org/micro/v3 v3.10.24 h1:gIi4r0vUSpNLs+uRb4KKEXBLkE8iNp6ZnJsI5FV42j0=
|
||||||
go.opentelemetry.io/otel v1.33.0/go.mod h1:SUUkR6csvUQl+yjReHu5uM3EtVV7MBm5FHKRlNx4I8I=
|
go.unistack.org/micro/v3 v3.10.24/go.mod h1:aywPekJP0n07xvmDgj+Si3VPmQzGMfj6tkHk/6kjXhU=
|
||||||
go.unistack.org/micro/v3 v3.10.81 h1:zHttMUEwL/f9GtrNAQOk8bK0NrEwAuKeUW8DEoywgJI=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
go.unistack.org/micro/v3 v3.10.81/go.mod h1:erMgt3Bl7vQQ0e9UpQyR5NlLiZ9pKeEJ9+1tfYFaqUg=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
go.unistack.org/micro/v3 v3.11.17 h1:Ix3833Ri8/T1Y+wUoAF5HJAn7+Aw/NEPkDdR3v3IXFs=
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
go.unistack.org/micro/v3 v3.11.17/go.mod h1:anELQdvF4yjGIqoaJU8SIWbTpKPFYA6Y1UMzzi/M7Hk=
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
293
opentracing.go
293
opentracing.go
@ -3,38 +3,35 @@ package opentracing
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
|
||||||
|
|
||||||
ot "github.com/opentracing/opentracing-go"
|
"github.com/opentracing/opentracing-go"
|
||||||
otlog "github.com/opentracing/opentracing-go/log"
|
"github.com/opentracing/opentracing-go/log"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
|
||||||
"go.unistack.org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"go.unistack.org/micro/v3/tracer"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
"go.unistack.org/micro/v3/util/sort"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ tracer.Tracer = &otTracer{}
|
var _ tracer.Tracer = &otTracer{}
|
||||||
|
|
||||||
type otTracer struct {
|
type otTracer struct {
|
||||||
opts tracer.Options
|
opts tracer.Options
|
||||||
tracer ot.Tracer
|
tracer opentracing.Tracer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *otTracer) Name() string {
|
func (ot *otTracer) Name() string {
|
||||||
return t.opts.Name
|
return ot.opts.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *otTracer) Flush(ctx context.Context) error {
|
func (ot *otTracer) Flush(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *otTracer) Init(opts ...tracer.Option) error {
|
func (ot *otTracer) Init(opts ...tracer.Option) error {
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&t.opts)
|
o(&ot.opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tr, ok := t.opts.Context.Value(tracerKey{}).(ot.Tracer); ok {
|
if tr, ok := ot.opts.Context.Value(tracerKey{}).(opentracing.Tracer); ok {
|
||||||
t.tracer = tr
|
ot.tracer = tr
|
||||||
} else {
|
} else {
|
||||||
return errors.New("Tracer option missing")
|
return errors.New("Tracer option missing")
|
||||||
}
|
}
|
||||||
@ -42,108 +39,32 @@ func (t *otTracer) Init(opts ...tracer.Option) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type otSpanContext interface {
|
func (ot *otTracer) Start(ctx context.Context, name string, opts ...tracer.SpanOption) (context.Context, tracer.Span) {
|
||||||
TraceID() idStringer
|
|
||||||
SpanID() idStringer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *otTracer) Start(ctx context.Context, name string, opts ...tracer.SpanOption) (context.Context, tracer.Span) {
|
|
||||||
options := tracer.NewSpanOptions(opts...)
|
options := tracer.NewSpanOptions(opts...)
|
||||||
|
var span opentracing.Span
|
||||||
if len(options.Labels)%2 != 0 {
|
|
||||||
options.Labels = options.Labels[:len(options.Labels)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, fn := range t.opts.ContextAttrFuncs {
|
|
||||||
options.Labels = append(options.Labels, fn(ctx)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
var span ot.Span
|
|
||||||
switch options.Kind {
|
switch options.Kind {
|
||||||
case tracer.SpanKindUnspecified:
|
case tracer.SpanKindInternal, tracer.SpanKindUnspecified:
|
||||||
ctx, span = t.startSpanFromAny(ctx, name)
|
ctx, span = ot.startSpanFromContext(ctx, name)
|
||||||
case tracer.SpanKindInternal:
|
|
||||||
ctx, span = t.startSpanFromContext(ctx, name)
|
|
||||||
case tracer.SpanKindClient, tracer.SpanKindProducer:
|
case tracer.SpanKindClient, tracer.SpanKindProducer:
|
||||||
ctx, span = t.startSpanFromOutgoingContext(ctx, name)
|
ctx, span = ot.startSpanFromOutgoingContext(ctx, name)
|
||||||
case tracer.SpanKindServer, tracer.SpanKindConsumer:
|
case tracer.SpanKindServer, tracer.SpanKindConsumer:
|
||||||
ctx, span = t.startSpanFromIncomingContext(ctx, name)
|
ctx, span = ot.startSpanFromIncomingContext(ctx, ot.tracer, name)
|
||||||
}
|
}
|
||||||
|
return ctx, &otSpan{span: span, opts: options}
|
||||||
sp := &otSpan{span: span, opts: options}
|
|
||||||
|
|
||||||
spctx := span.Context()
|
|
||||||
|
|
||||||
var traceID, spanID, parentID string
|
|
||||||
|
|
||||||
if v, ok := spctx.(otSpanContext); ok {
|
|
||||||
traceID = v.TraceID().String()
|
|
||||||
spanID = v.SpanID().String()
|
|
||||||
} else {
|
|
||||||
carrier := make(map[string]string, 1)
|
|
||||||
_ = span.Tracer().Inject(spctx, ot.TextMap, ot.TextMapCarrier(carrier))
|
|
||||||
for k, v := range carrier {
|
|
||||||
switch k {
|
|
||||||
case "mockpfx-ids-sampled":
|
|
||||||
continue
|
|
||||||
case "mockpfx-ids-spanid":
|
|
||||||
spanID = v
|
|
||||||
case "mockpfx-ids-traceid":
|
|
||||||
traceID = v
|
|
||||||
default: // reasonable default
|
|
||||||
p := strings.Split(v, ":")
|
|
||||||
traceID = p[0]
|
|
||||||
spanID = p[1]
|
|
||||||
parentID = p[2]
|
|
||||||
case "uber-trace-id": // jaeger trace span
|
|
||||||
p := strings.Split(v, ":")
|
|
||||||
traceID = p[0]
|
|
||||||
spanID = p[1]
|
|
||||||
parentID = p[2]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sp.traceID = traceID
|
|
||||||
sp.spanID = spanID
|
|
||||||
sp.parentID = parentID
|
|
||||||
|
|
||||||
return tracer.NewSpanContext(ctx, sp), sp
|
|
||||||
}
|
|
||||||
|
|
||||||
type idStringer struct {
|
|
||||||
s string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s idStringer) String() string {
|
|
||||||
return s.s
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type otSpan struct {
|
type otSpan struct {
|
||||||
span ot.Span
|
span opentracing.Span
|
||||||
spanID string
|
|
||||||
traceID string
|
|
||||||
parentID string
|
|
||||||
opts tracer.SpanOptions
|
opts tracer.SpanOptions
|
||||||
status tracer.SpanStatus
|
status tracer.SpanStatus
|
||||||
statusMsg string
|
statusMsg string
|
||||||
labels []interface{}
|
|
||||||
finished bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (os *otSpan) TraceID() string {
|
|
||||||
return os.traceID
|
|
||||||
}
|
|
||||||
|
|
||||||
func (os *otSpan) SpanID() string {
|
|
||||||
return os.spanID
|
|
||||||
}
|
|
||||||
|
|
||||||
func (os *otSpan) ParentID() string {
|
|
||||||
return os.parentID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (os *otSpan) SetStatus(st tracer.SpanStatus, msg string) {
|
func (os *otSpan) SetStatus(st tracer.SpanStatus, msg string) {
|
||||||
|
switch st {
|
||||||
|
case tracer.SpanStatusError:
|
||||||
|
os.span.SetTag("error", true)
|
||||||
|
}
|
||||||
os.status = st
|
os.status = st
|
||||||
os.statusMsg = msg
|
os.statusMsg = msg
|
||||||
}
|
}
|
||||||
@ -157,64 +78,18 @@ func (os *otSpan) Tracer() tracer.Tracer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (os *otSpan) Finish(opts ...tracer.SpanOption) {
|
func (os *otSpan) Finish(opts ...tracer.SpanOption) {
|
||||||
if os.finished {
|
if len(os.opts.Labels) > 0 {
|
||||||
return
|
os.span.LogKV(os.opts.Labels...)
|
||||||
}
|
}
|
||||||
|
|
||||||
options := os.opts
|
|
||||||
|
|
||||||
options.Status = os.status
|
|
||||||
options.StatusMsg = os.statusMsg
|
|
||||||
options.Labels = append(options.Labels, os.labels...)
|
|
||||||
|
|
||||||
for _, o := range opts {
|
|
||||||
o(&options)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !options.Record {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(options.Labels)%2 != 0 {
|
|
||||||
options.Labels = options.Labels[:len(options.Labels)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
os.opts.Labels = sort.Uniq(os.opts.Labels)
|
|
||||||
|
|
||||||
l := len(options.Labels)
|
|
||||||
for idx := 0; idx < l; idx++ {
|
|
||||||
switch lt := options.Labels[idx].(type) {
|
|
||||||
case attribute.KeyValue:
|
|
||||||
os.span.SetTag(string(lt.Key), lt.Value.AsInterface())
|
|
||||||
case string:
|
|
||||||
if l > idx+1 {
|
|
||||||
os.span.SetTag(lt, options.Labels[idx+1])
|
|
||||||
idx++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if options.Status == tracer.SpanStatusError {
|
|
||||||
os.span.SetTag("error", true)
|
|
||||||
os.span.LogKV("error", options.StatusMsg)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.span.SetTag("span.kind", options.Kind)
|
|
||||||
os.span.Finish()
|
os.span.Finish()
|
||||||
|
|
||||||
os.finished = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (os *otSpan) AddEvent(name string, opts ...tracer.EventOption) {
|
func (os *otSpan) AddEvent(name string, opts ...tracer.EventOption) {
|
||||||
os.span.LogFields(otlog.Event(name))
|
os.span.LogFields(log.Event(name))
|
||||||
}
|
|
||||||
|
|
||||||
func (os *otSpan) AddLogs(kv ...interface{}) {
|
|
||||||
os.span.LogKV(kv...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (os *otSpan) Context() context.Context {
|
func (os *otSpan) Context() context.Context {
|
||||||
return ot.ContextWithSpan(context.Background(), os.span)
|
return opentracing.ContextWithSpan(context.Background(), os.span)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (os *otSpan) SetName(name string) {
|
func (os *otSpan) SetName(name string) {
|
||||||
@ -230,7 +105,7 @@ func (os *otSpan) Kind() tracer.SpanKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (os *otSpan) AddLabels(labels ...interface{}) {
|
func (os *otSpan) AddLabels(labels ...interface{}) {
|
||||||
os.labels = append(os.labels, labels...)
|
os.opts.Labels = append(os.opts.Labels, labels...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTracer(opts ...tracer.Option) *otTracer {
|
func NewTracer(opts ...tracer.Option) *otTracer {
|
||||||
@ -238,145 +113,75 @@ func NewTracer(opts ...tracer.Option) *otTracer {
|
|||||||
return &otTracer{opts: options}
|
return &otTracer{opts: options}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *otTracer) startSpanFromAny(ctx context.Context, name string, opts ...ot.StartSpanOption) (context.Context, ot.Span) {
|
func spanFromContext(ctx context.Context) opentracing.Span {
|
||||||
if tracerSpan, ok := tracer.SpanFromContext(ctx); ok && tracerSpan != nil {
|
return opentracing.SpanFromContext(ctx)
|
||||||
return t.startSpanFromContext(ctx, name, opts...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if otSpan := ot.SpanFromContext(ctx); otSpan != nil {
|
func (ot *otTracer) startSpanFromContext(ctx context.Context, name string, opts ...opentracing.StartSpanOption) (context.Context, opentracing.Span) {
|
||||||
return t.startSpanFromContext(ctx, name, opts...)
|
if parentSpan := opentracing.SpanFromContext(ctx); parentSpan != nil {
|
||||||
}
|
opts = append(opts, opentracing.ChildOf(parentSpan.Context()))
|
||||||
|
|
||||||
if md, ok := metadata.FromIncomingContext(ctx); ok && md != nil {
|
|
||||||
return t.startSpanFromIncomingContext(ctx, name, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
if md, ok := metadata.FromOutgoingContext(ctx); ok && md != nil {
|
|
||||||
return t.startSpanFromOutgoingContext(ctx, name, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
return t.startSpanFromContext(ctx, name, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *otTracer) startSpanFromContext(ctx context.Context, name string, opts ...ot.StartSpanOption) (context.Context, ot.Span) {
|
|
||||||
var parentSpan ot.Span
|
|
||||||
if tracerSpan, ok := tracer.SpanFromContext(ctx); ok && tracerSpan != nil {
|
|
||||||
if sp, ok := tracerSpan.(*otSpan); ok {
|
|
||||||
parentSpan = sp.span
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if parentSpan == nil {
|
|
||||||
if otSpan := ot.SpanFromContext(ctx); otSpan != nil {
|
|
||||||
parentSpan = otSpan
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if parentSpan != nil {
|
|
||||||
opts = append(opts, ot.ChildOf(parentSpan.Context()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
md := metadata.New(1)
|
md := metadata.New(1)
|
||||||
|
|
||||||
sp := t.tracer.StartSpan(name, opts...)
|
sp := ot.tracer.StartSpan(name, opts...)
|
||||||
if err := sp.Tracer().Inject(sp.Context(), ot.TextMap, ot.TextMapCarrier(md)); err != nil {
|
if err := sp.Tracer().Inject(sp.Context(), opentracing.TextMap, opentracing.TextMapCarrier(md)); err != nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = ot.ContextWithSpan(ctx, sp)
|
ctx = opentracing.ContextWithSpan(ctx, sp)
|
||||||
|
|
||||||
return ctx, sp
|
return ctx, sp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *otTracer) startSpanFromOutgoingContext(ctx context.Context, name string, opts ...ot.StartSpanOption) (context.Context, ot.Span) {
|
func (ot *otTracer) startSpanFromOutgoingContext(ctx context.Context, name string, opts ...opentracing.StartSpanOption) (context.Context, opentracing.Span) {
|
||||||
var parentSpan ot.Span
|
var parentCtx opentracing.SpanContext
|
||||||
if tracerSpan, ok := tracer.SpanFromContext(ctx); ok && tracerSpan != nil {
|
|
||||||
if sp, ok := tracerSpan.(*otSpan); ok {
|
|
||||||
parentSpan = sp.span
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if parentSpan == nil {
|
|
||||||
if otSpan := ot.SpanFromContext(ctx); otSpan != nil {
|
|
||||||
parentSpan = otSpan
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
md, ok := metadata.FromOutgoingContext(ctx)
|
md, ok := metadata.FromOutgoingContext(ctx)
|
||||||
|
|
||||||
if parentSpan != nil {
|
|
||||||
opts = append(opts, ot.ChildOf(parentSpan.Context()))
|
|
||||||
} else {
|
|
||||||
var parentCtx ot.SpanContext
|
|
||||||
|
|
||||||
if ok && md != nil {
|
if ok && md != nil {
|
||||||
if spanCtx, err := t.tracer.Extract(ot.TextMap, ot.TextMapCarrier(md)); err == nil && ok {
|
if spanCtx, err := ot.tracer.Extract(opentracing.TextMap, opentracing.TextMapCarrier(md)); err == nil && ok {
|
||||||
parentCtx = spanCtx
|
parentCtx = spanCtx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if parentCtx != nil {
|
if parentCtx != nil {
|
||||||
opts = append(opts, ot.ChildOf(parentCtx))
|
opts = append(opts, opentracing.ChildOf(parentCtx))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nmd := metadata.Copy(md)
|
nmd := metadata.Copy(md)
|
||||||
smd := metadata.New(1)
|
|
||||||
|
|
||||||
sp := t.tracer.StartSpan(name, opts...)
|
sp := ot.tracer.StartSpan(name, opts...)
|
||||||
if err := sp.Tracer().Inject(sp.Context(), ot.TextMap, ot.TextMapCarrier(smd)); err != nil {
|
if err := sp.Tracer().Inject(sp.Context(), opentracing.TextMap, opentracing.TextMapCarrier(nmd)); err != nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
for k, v := range smd {
|
|
||||||
nmd.Set(k, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = metadata.NewOutgoingContext(ot.ContextWithSpan(ctx, sp), nmd)
|
ctx = metadata.NewOutgoingContext(opentracing.ContextWithSpan(ctx, sp), nmd)
|
||||||
|
|
||||||
return ctx, sp
|
return ctx, sp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *otTracer) startSpanFromIncomingContext(ctx context.Context, name string, opts ...ot.StartSpanOption) (context.Context, ot.Span) {
|
func (ot *otTracer) startSpanFromIncomingContext(ctx context.Context, tracer opentracing.Tracer, name string, opts ...opentracing.StartSpanOption) (context.Context, opentracing.Span) {
|
||||||
var parentSpan ot.Span
|
var parentCtx opentracing.SpanContext
|
||||||
if tracerSpan, ok := tracer.SpanFromContext(ctx); ok && tracerSpan != nil {
|
|
||||||
if sp, ok := tracerSpan.(*otSpan); ok {
|
|
||||||
parentSpan = sp.span
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if parentSpan == nil {
|
|
||||||
if otSpan := ot.SpanFromContext(ctx); otSpan != nil {
|
|
||||||
parentSpan = otSpan
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
md, ok := metadata.FromIncomingContext(ctx)
|
md, ok := metadata.FromIncomingContext(ctx)
|
||||||
|
|
||||||
if parentSpan != nil {
|
|
||||||
opts = append(opts, ot.ChildOf(parentSpan.Context()))
|
|
||||||
} else {
|
|
||||||
var parentCtx ot.SpanContext
|
|
||||||
|
|
||||||
if ok && md != nil {
|
if ok && md != nil {
|
||||||
if spanCtx, err := t.tracer.Extract(ot.TextMap, ot.TextMapCarrier(md)); err == nil {
|
if spanCtx, err := tracer.Extract(opentracing.TextMap, opentracing.TextMapCarrier(md)); err == nil {
|
||||||
parentCtx = spanCtx
|
parentCtx = spanCtx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if parentCtx != nil {
|
if parentCtx != nil {
|
||||||
opts = append(opts, ot.ChildOf(parentCtx))
|
opts = append(opts, opentracing.ChildOf(parentCtx))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nmd := metadata.Copy(md)
|
nmd := metadata.Copy(md)
|
||||||
smd := metadata.New(1)
|
|
||||||
|
|
||||||
sp := t.tracer.StartSpan(name, opts...)
|
sp := tracer.StartSpan(name, opts...)
|
||||||
if err := sp.Tracer().Inject(sp.Context(), ot.TextMap, ot.TextMapCarrier(smd)); err != nil {
|
if err := sp.Tracer().Inject(sp.Context(), opentracing.TextMap, opentracing.TextMapCarrier(nmd)); err != nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
for k, v := range smd {
|
|
||||||
nmd.Set(k, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = metadata.NewIncomingContext(ot.ContextWithSpan(ctx, sp), nmd)
|
ctx = metadata.NewIncomingContext(opentracing.ContextWithSpan(ctx, sp), nmd)
|
||||||
|
|
||||||
return ctx, sp
|
return ctx, sp
|
||||||
}
|
}
|
||||||
|
@ -2,116 +2,47 @@ package opentracing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/opentracing/opentracing-go/mocktracer"
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
// jconfig "github.com/uber/jaeger-client-go/config"
|
|
||||||
"go.unistack.org/micro/v3/logger/slog"
|
|
||||||
"go.unistack.org/micro/v3/metadata"
|
"go.unistack.org/micro/v3/metadata"
|
||||||
"go.unistack.org/micro/v3/tracer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNoopTraceID(t *testing.T) {
|
func TestStartSpanFromIncomingContext(t *testing.T) {
|
||||||
md := metadata.New(1)
|
md := metadata.New(2)
|
||||||
|
md.Set("key", "val")
|
||||||
|
|
||||||
|
var g sync.WaitGroup
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ctx = metadata.NewIncomingContext(ctx, md)
|
ctx = metadata.NewIncomingContext(ctx, md)
|
||||||
|
|
||||||
tr := NewTracer(Tracer(mocktracer.New()))
|
tracer := opentracing.GlobalTracer()
|
||||||
if err := tr.Init(); err != nil {
|
ot := &otTracer{tracer: tracer}
|
||||||
t.Fatal(err)
|
|
||||||
|
g.Add(8000)
|
||||||
|
cherr := make(chan error)
|
||||||
|
for i := 0; i < 8000; i++ {
|
||||||
|
go func() {
|
||||||
|
defer g.Done()
|
||||||
|
_, sp := ot.startSpanFromIncomingContext(ctx, tracer, "test")
|
||||||
|
sp.Finish()
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
var sp tracer.Span
|
for {
|
||||||
|
select {
|
||||||
ctx, sp = tr.Start(ctx, "test")
|
default:
|
||||||
if v := sp.TraceID(); v != "43" {
|
g.Wait()
|
||||||
t.Fatalf("invalid span trace id %#+v", v)
|
close(cherr)
|
||||||
}
|
case err, ok := <-cherr:
|
||||||
if v := sp.SpanID(); v != "44" {
|
|
||||||
t.Fatalf("invalid span span id %#+v", v)
|
|
||||||
}
|
|
||||||
|
|
||||||
l := slog.NewLogger()
|
|
||||||
if err := l.Init(); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
l.Info(ctx, "msg")
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
func TestRealTraceID(t *testing.T) {
|
|
||||||
md := metadata.New(1)
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
ctx = metadata.NewIncomingContext(ctx, md)
|
|
||||||
|
|
||||||
jcfg := &jconfig.Configuration{
|
|
||||||
ServiceName: "test",
|
|
||||||
Sampler: &jconfig.SamplerConfig{
|
|
||||||
Type: "const",
|
|
||||||
Param: 1,
|
|
||||||
},
|
|
||||||
Reporter: &jconfig.ReporterConfig{
|
|
||||||
LogSpans: true,
|
|
||||||
QueueSize: 100,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
jtr, closer, err := jcfg.NewTracer()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
} else if !ok {
|
||||||
defer closer.Close()
|
return
|
||||||
|
}
|
||||||
tr := NewTracer(Tracer(jtr))
|
}
|
||||||
if err := tr.Init(); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var sp tracer.Span
|
|
||||||
|
|
||||||
ctx, sp = tr.Start(ctx, "test")
|
|
||||||
if v := sp.TraceID(); v != "43" {
|
|
||||||
t.Fatalf("invalid span trace id %#+v", v)
|
|
||||||
}
|
|
||||||
if v := sp.SpanID(); v != "44" {
|
|
||||||
t.Fatalf("invalid span span id %#+v", v)
|
|
||||||
}
|
|
||||||
|
|
||||||
l := slog.NewLogger()
|
|
||||||
if err := l.Init(); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
l.Info(ctx, "msg")
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func TestTraceTags(t *testing.T) {
|
|
||||||
md := metadata.New(1)
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
ctx = metadata.NewIncomingContext(ctx, md)
|
|
||||||
|
|
||||||
mtr := mocktracer.New()
|
|
||||||
tr := NewTracer(Tracer(mtr))
|
|
||||||
if err := tr.Init(); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var sp tracer.Span
|
|
||||||
|
|
||||||
ctx, sp = tr.Start(ctx, "test", tracer.WithSpanLabels("key", "val", "odd"))
|
|
||||||
sp.Finish(tracer.WithSpanLabels("xkey", "xval"))
|
|
||||||
_ = ctx
|
|
||||||
msp := mtr.FinishedSpans()[0]
|
|
||||||
|
|
||||||
if "val" != fmt.Sprintf("%v", msp.Tags()["key"]) {
|
|
||||||
t.Fatal("mock span invalid")
|
|
||||||
}
|
|
||||||
|
|
||||||
if "xval" != fmt.Sprintf("%v", msp.Tags()["xkey"]) {
|
|
||||||
t.Fatalf("mock span invalid %#+v", msp)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user