Compare commits
23 Commits
v3.10.15
...
e058f049a7
Author | SHA1 | Date | |
---|---|---|---|
e058f049a7 | |||
3718494ba6 | |||
|
1dad9b13e8 | ||
4bc5facf9f | |||
26908c1d44 | |||
18197c63f1 | |||
38d57f8829 | |||
aa61010405 | |||
b729620976 | |||
16b180bfaa | |||
|
efe77803ff | ||
31350e8c21 | |||
|
d3d5925747 | ||
89f75e0431 | |||
9f6620676a | |||
e1f85545d9 | |||
e887edb475 | |||
2149a713d5 | |||
9b553cfa62 | |||
65ac3aff56 | |||
e9933df477 | |||
905910e8ce | |||
7948652293 |
19
.github/dependabot.yml
vendored
19
.github/dependabot.yml
vendored
@@ -1,19 +0,0 @@
|
|||||||
# 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
20
.github/workflows/autoapprove.yml
vendored
@@ -1,20 +0,0 @@
|
|||||||
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
21
.github/workflows/automerge.yml
vendored
@@ -1,21 +0,0 @@
|
|||||||
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
47
.github/workflows/build.yml
vendored
@@ -1,47 +0,0 @@
|
|||||||
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
78
.github/workflows/codeql-analysis.yml
vendored
@@ -1,78 +0,0 @@
|
|||||||
# 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
27
.github/workflows/dependabot-automerge.yml
vendored
@@ -1,27 +0,0 @@
|
|||||||
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}}
|
|
53
.github/workflows/job_coverage.yml
vendored
Normal file
53
.github/workflows/job_coverage.yml
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
name: coverage
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main, v3, v4 ]
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '.gitea/**'
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, v3, v4 ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
if: github.server_url != 'https://github.com'
|
||||||
|
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: test coverage
|
||||||
|
run: |
|
||||||
|
go test -v -cover ./... -covermode=count -coverprofile coverage.out -coverpkg ./...
|
||||||
|
go tool cover -func coverage.out -o coverage.out
|
||||||
|
|
||||||
|
- name: coverage badge
|
||||||
|
uses: tj-actions/coverage-badge-go@v2
|
||||||
|
with:
|
||||||
|
green: 80
|
||||||
|
filename: coverage.out
|
||||||
|
|
||||||
|
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
|
name: autocommit
|
||||||
|
with:
|
||||||
|
commit_message: Apply Code Coverage Badge
|
||||||
|
skip_fetch: false
|
||||||
|
skip_checkout: false
|
||||||
|
file_pattern: ./README.md
|
||||||
|
|
||||||
|
- name: push
|
||||||
|
if: steps.auto-commit-action.outputs.changes_detected == 'true'
|
||||||
|
uses: ad-m/github-push-action@master
|
||||||
|
with:
|
||||||
|
github_token: ${{ github.token }}
|
||||||
|
branch: ${{ github.ref }}
|
29
.github/workflows/job_lint.yml
vendored
Normal file
29
.github/workflows/job_lint.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
name: lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, synchronize]
|
||||||
|
branches: [ master, v3, v4 ]
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '.gitea/**'
|
||||||
|
|
||||||
|
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: golangci/golangci-lint-action@v6
|
||||||
|
with:
|
||||||
|
version: 'latest'
|
31
.github/workflows/job_test.yml
vendored
Normal file
31
.github/workflows/job_test.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, synchronize]
|
||||||
|
branches: [ master, v3, v4 ]
|
||||||
|
push:
|
||||||
|
branches: [ master, v3, v4 ]
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '.gitea/**'
|
||||||
|
|
||||||
|
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 ./...
|
50
.github/workflows/job_tests.yml
vendored
Normal file
50
.github/workflows/job_tests.yml
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
name: test
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, synchronize]
|
||||||
|
branches: [ master, v3, v4 ]
|
||||||
|
push:
|
||||||
|
branches: [ master, v3, v4 ]
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '.gitea/**'
|
||||||
|
|
||||||
|
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: ${{ github.workspace }}/go.work
|
||||||
|
run: |
|
||||||
|
go work init
|
||||||
|
go work use .
|
||||||
|
go work use micro-tests
|
||||||
|
- name: setup deps
|
||||||
|
env:
|
||||||
|
GOWORK: ${{ github.workspace }}/go.work
|
||||||
|
run: go get -v ./...
|
||||||
|
- name: run tests
|
||||||
|
env:
|
||||||
|
INTEGRATION_TESTS: yes
|
||||||
|
GOWORK: ${{ github.workspace }}/go.work
|
||||||
|
run: |
|
||||||
|
cd micro-tests
|
||||||
|
go test -mod readonly -v ./... || true
|
47
.github/workflows/pr.yml
vendored
47
.github/workflows/pr.yml
vendored
@@ -1,47 +0,0 @@
|
|||||||
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
.gitignore
vendored
1
.gitignore
vendored
@@ -13,3 +13,4 @@
|
|||||||
|
|
||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/
|
# vendor/
|
||||||
|
.idea
|
5
.golangci.yml
Normal file
5
.golangci.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
run:
|
||||||
|
concurrency: 8
|
||||||
|
timeout: 5m
|
||||||
|
issues-exit-code: 1
|
||||||
|
tests: true
|
@@ -1 +1,2 @@
|
|||||||
# micro-tracer-opentracing
|
# micro-tracer-opentracing
|
||||||
|

|
||||||
|
14
go.mod
14
go.mod
@@ -1,9 +1,17 @@
|
|||||||
module go.unistack.org/micro-tracer-opentracing/v3
|
module go.unistack.org/micro-tracer-opentracing/v3
|
||||||
|
|
||||||
go 1.20
|
go 1.22.0
|
||||||
|
|
||||||
|
toolchain go1.23.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/opentracing/opentracing-go v1.2.0
|
github.com/opentracing/opentracing-go v1.2.0
|
||||||
go.opentelemetry.io/otel v1.24.0
|
go.opentelemetry.io/otel v1.35.0
|
||||||
go.unistack.org/micro/v3 v3.10.43
|
go.unistack.org/micro/v3 v3.11.44
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/ash3in/uuidv8 v1.2.0 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/matoous/go-nanoid v1.5.1 // indirect
|
||||||
)
|
)
|
||||||
|
29
go.sum
29
go.sum
@@ -1,15 +1,28 @@
|
|||||||
|
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
|
||||||
|
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||||
|
github.com/ash3in/uuidv8 v1.2.0 h1:2oogGdtCPwaVtyvPPGin4TfZLtOGE5F+W++E880G6SI=
|
||||||
|
github.com/ash3in/uuidv8 v1.2.0/go.mod h1:BnU0wJBxnzdEKmVg4xckBkD+VZuecTFTUP3M0dWgyY4=
|
||||||
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.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
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/matoous/go-nanoid v1.5.1 h1:aCjdvTyO9LLnTIi0fgdXhOPPvOHjpXN6Ik9DaNjIct4=
|
||||||
|
github.com/matoous/go-nanoid v1.5.1/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U=
|
||||||
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/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/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.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
|
go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
|
||||||
go.unistack.org/micro/v3 v3.10.43 h1:GjUgu1lSKrhIov67jZQg6hUVUw0xZ6+ub8s6JRu6uj4=
|
go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
|
||||||
go.unistack.org/micro/v3 v3.10.43/go.mod h1:CSmEf5ddmft94MyKHnUSMM0W5dpmmTVbgImbgQWV5Ak=
|
go.unistack.org/micro/v3 v3.11.44 h1:A+T8zVcL2vlL66kn/Y4rqhtBybLO829wFEYZJYorDOU=
|
||||||
|
go.unistack.org/micro/v3 v3.11.44/go.mod h1:13EFW2ps3BN9mpYbp9K0oQu/VDjEN6LJ4wwdom7hcXQ=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
131
opentracing.go
131
opentracing.go
@@ -3,14 +3,13 @@ package opentracing
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"strings"
|
||||||
|
|
||||||
ot "github.com/opentracing/opentracing-go"
|
ot "github.com/opentracing/opentracing-go"
|
||||||
otlog "github.com/opentracing/opentracing-go/log"
|
otlog "github.com/opentracing/opentracing-go/log"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"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"
|
||||||
rutil "go.unistack.org/micro/v3/util/reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ tracer.Tracer = &otTracer{}
|
var _ tracer.Tracer = &otTracer{}
|
||||||
@@ -42,13 +41,22 @@ func (t *otTracer) Init(opts ...tracer.Option) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type spanContext interface {
|
type otSpanContext interface {
|
||||||
TraceID() idStringer
|
TraceID() idStringer
|
||||||
SpanID() idStringer
|
SpanID() idStringer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *otTracer) Start(ctx context.Context, name string, opts ...tracer.SpanOption) (context.Context, tracer.Span) {
|
func (t *otTracer) Start(ctx context.Context, name string, opts ...tracer.SpanOption) (context.Context, tracer.Span) {
|
||||||
options := tracer.NewSpanOptions(opts...)
|
options := tracer.NewSpanOptions(opts...)
|
||||||
|
|
||||||
|
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
|
var span ot.Span
|
||||||
switch options.Kind {
|
switch options.Kind {
|
||||||
case tracer.SpanKindUnspecified:
|
case tracer.SpanKindUnspecified:
|
||||||
@@ -64,19 +72,40 @@ func (t *otTracer) Start(ctx context.Context, name string, opts ...tracer.SpanOp
|
|||||||
sp := &otSpan{span: span, opts: options}
|
sp := &otSpan{span: span, opts: options}
|
||||||
|
|
||||||
spctx := span.Context()
|
spctx := span.Context()
|
||||||
if v, ok := spctx.(spanContext); ok {
|
|
||||||
sp.traceID = v.TraceID().String()
|
var traceID, spanID, parentID string
|
||||||
sp.spanID = v.SpanID().String()
|
|
||||||
|
if v, ok := spctx.(otSpanContext); ok {
|
||||||
|
traceID = v.TraceID().String()
|
||||||
|
spanID = v.SpanID().String()
|
||||||
} else {
|
} else {
|
||||||
if val, err := rutil.StructFieldByName(spctx, "TraceID"); err == nil {
|
carrier := make(map[string]string, 1)
|
||||||
sp.traceID = fmt.Sprintf("%v", val)
|
_ = span.Tracer().Inject(spctx, ot.TextMap, ot.TextMapCarrier(carrier))
|
||||||
}
|
for k, v := range carrier {
|
||||||
if val, err := rutil.StructFieldByName(spctx, "SpanID"); err == nil {
|
switch k {
|
||||||
sp.spanID = fmt.Sprintf("%v", val)
|
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.AddLabels(options.Labels...)
|
sp.traceID = traceID
|
||||||
|
sp.spanID = spanID
|
||||||
|
sp.parentID = parentID
|
||||||
|
|
||||||
return tracer.NewSpanContext(ctx, sp), sp
|
return tracer.NewSpanContext(ctx, sp), sp
|
||||||
}
|
}
|
||||||
@@ -93,9 +122,12 @@ type otSpan struct {
|
|||||||
span ot.Span
|
span ot.Span
|
||||||
spanID string
|
spanID string
|
||||||
traceID 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 {
|
func (os *otSpan) TraceID() string {
|
||||||
@@ -106,6 +138,14 @@ func (os *otSpan) SpanID() string {
|
|||||||
return os.spanID
|
return os.spanID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (os *otSpan) ParentID() string {
|
||||||
|
return os.parentID
|
||||||
|
}
|
||||||
|
|
||||||
|
func (os *otSpan) IsRecording() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (os *otSpan) SetStatus(st tracer.SpanStatus, msg string) {
|
func (os *otSpan) SetStatus(st tracer.SpanStatus, msg string) {
|
||||||
os.status = st
|
os.status = st
|
||||||
os.statusMsg = msg
|
os.statusMsg = msg
|
||||||
@@ -120,30 +160,52 @@ func (os *otSpan) Tracer() tracer.Tracer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (os *otSpan) Finish(opts ...tracer.SpanOption) {
|
func (os *otSpan) Finish(opts ...tracer.SpanOption) {
|
||||||
|
if os.finished {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
options := os.opts
|
options := os.opts
|
||||||
|
|
||||||
|
options.Status = os.status
|
||||||
|
options.StatusMsg = os.statusMsg
|
||||||
|
options.Labels = append(options.Labels, os.labels...)
|
||||||
|
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !options.Record {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(options.Labels)%2 != 0 {
|
||||||
|
options.Labels = options.Labels[:len(options.Labels)-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// options.Labels = sort.Uniq(options.Labels)
|
||||||
|
|
||||||
l := len(options.Labels)
|
l := len(options.Labels)
|
||||||
for idx := 0; idx < len(options.Labels); idx++ {
|
for idx := 0; idx < l; idx++ {
|
||||||
switch lt := options.Labels[idx].(type) {
|
switch lt := options.Labels[idx].(type) {
|
||||||
case attribute.KeyValue:
|
case attribute.KeyValue:
|
||||||
os.span.SetTag(string(lt.Key), lt.Value.AsInterface())
|
os.span.SetTag(string(lt.Key), lt.Value.AsInterface())
|
||||||
case string:
|
case string:
|
||||||
if l < idx+1 {
|
if l > idx+1 {
|
||||||
os.span.SetTag(lt, options.Labels[idx+1])
|
os.span.SetTag(lt, options.Labels[idx+1])
|
||||||
idx++
|
idx++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if os.status == tracer.SpanStatusError {
|
if options.Status == tracer.SpanStatusError {
|
||||||
os.span.SetTag("error", true)
|
os.span.SetTag("error", true)
|
||||||
os.span.LogKV("error", os.statusMsg)
|
os.span.LogKV("error", options.StatusMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.span.SetTag("span.kind", options.Kind)
|
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) {
|
||||||
@@ -171,18 +233,7 @@ func (os *otSpan) Kind() tracer.SpanKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (os *otSpan) AddLabels(labels ...interface{}) {
|
func (os *otSpan) AddLabels(labels ...interface{}) {
|
||||||
l := len(labels)
|
os.labels = append(os.labels, labels...)
|
||||||
for idx := 0; idx < len(labels); idx++ {
|
|
||||||
switch lt := 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, labels[idx+1])
|
|
||||||
idx++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTracer(opts ...tracer.Option) *otTracer {
|
func NewTracer(opts ...tracer.Option) *otTracer {
|
||||||
@@ -210,6 +261,10 @@ func (t *otTracer) startSpanFromAny(ctx context.Context, name string, opts ...ot
|
|||||||
return t.startSpanFromContext(ctx, name, opts...)
|
return t.startSpanFromContext(ctx, name, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *otTracer) Enabled() bool {
|
||||||
|
return t.opts.Enabled
|
||||||
|
}
|
||||||
|
|
||||||
func (t *otTracer) startSpanFromContext(ctx context.Context, name string, opts ...ot.StartSpanOption) (context.Context, ot.Span) {
|
func (t *otTracer) startSpanFromContext(ctx context.Context, name string, opts ...ot.StartSpanOption) (context.Context, ot.Span) {
|
||||||
var parentSpan ot.Span
|
var parentSpan ot.Span
|
||||||
if tracerSpan, ok := tracer.SpanFromContext(ctx); ok && tracerSpan != nil {
|
if tracerSpan, ok := tracer.SpanFromContext(ctx); ok && tracerSpan != nil {
|
||||||
@@ -227,7 +282,7 @@ func (t *otTracer) startSpanFromContext(ctx context.Context, name string, opts .
|
|||||||
opts = append(opts, ot.ChildOf(parentSpan.Context()))
|
opts = append(opts, ot.ChildOf(parentSpan.Context()))
|
||||||
}
|
}
|
||||||
|
|
||||||
md := metadata.New(1)
|
md := make(map[string]string, 1)
|
||||||
|
|
||||||
sp := t.tracer.StartSpan(name, opts...)
|
sp := t.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(), ot.TextMap, ot.TextMapCarrier(md)); err != nil {
|
||||||
@@ -260,7 +315,8 @@ func (t *otTracer) startSpanFromOutgoingContext(ctx context.Context, name string
|
|||||||
var parentCtx ot.SpanContext
|
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 {
|
smd := make(map[string]string, 1)
|
||||||
|
if spanCtx, err := t.tracer.Extract(ot.TextMap, ot.TextMapCarrier(smd)); err == nil && ok {
|
||||||
parentCtx = spanCtx
|
parentCtx = spanCtx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,11 +327,15 @@ func (t *otTracer) startSpanFromOutgoingContext(ctx context.Context, name string
|
|||||||
}
|
}
|
||||||
|
|
||||||
nmd := metadata.Copy(md)
|
nmd := metadata.Copy(md)
|
||||||
|
smd := make(map[string]string, 1)
|
||||||
|
|
||||||
sp := t.tracer.StartSpan(name, opts...)
|
sp := t.tracer.StartSpan(name, opts...)
|
||||||
if err := sp.Tracer().Inject(sp.Context(), ot.TextMap, ot.TextMapCarrier(nmd)); err != nil {
|
if err := sp.Tracer().Inject(sp.Context(), ot.TextMap, ot.TextMapCarrier(smd)); 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(ot.ContextWithSpan(ctx, sp), nmd)
|
||||||
|
|
||||||
@@ -303,7 +363,8 @@ func (t *otTracer) startSpanFromIncomingContext(ctx context.Context, name string
|
|||||||
var parentCtx ot.SpanContext
|
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 {
|
smd := make(map[string]string, 1)
|
||||||
|
if spanCtx, err := t.tracer.Extract(ot.TextMap, ot.TextMapCarrier(smd)); err == nil {
|
||||||
parentCtx = spanCtx
|
parentCtx = spanCtx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,11 +375,15 @@ func (t *otTracer) startSpanFromIncomingContext(ctx context.Context, name string
|
|||||||
}
|
}
|
||||||
|
|
||||||
nmd := metadata.Copy(md)
|
nmd := metadata.Copy(md)
|
||||||
|
smd := make(map[string]string, 1)
|
||||||
|
|
||||||
sp := t.tracer.StartSpan(name, opts...)
|
sp := t.tracer.StartSpan(name, opts...)
|
||||||
if err := sp.Tracer().Inject(sp.Context(), ot.TextMap, ot.TextMapCarrier(nmd)); err != nil {
|
if err := sp.Tracer().Inject(sp.Context(), ot.TextMap, ot.TextMapCarrier(smd)); 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(ot.ContextWithSpan(ctx, sp), nmd)
|
||||||
|
|
||||||
|
@@ -2,14 +2,17 @@ package opentracing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/opentracing/opentracing-go/mocktracer"
|
"github.com/opentracing/opentracing-go/mocktracer"
|
||||||
|
// 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"
|
"go.unistack.org/micro/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTraceID(t *testing.T) {
|
func TestNoopTraceID(t *testing.T) {
|
||||||
md := metadata.New(1)
|
md := metadata.New(1)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -22,6 +25,53 @@ func TestTraceID(t *testing.T) {
|
|||||||
|
|
||||||
var sp tracer.Span
|
var sp tracer.Span
|
||||||
|
|
||||||
|
_, 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 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 {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer closer.Close()
|
||||||
|
|
||||||
|
tr := NewTracer(Tracer(jtr))
|
||||||
|
if err := tr.Init(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var sp tracer.Span
|
||||||
|
|
||||||
ctx, sp = tr.Start(ctx, "test")
|
ctx, sp = tr.Start(ctx, "test")
|
||||||
if v := sp.TraceID(); v != "43" {
|
if v := sp.TraceID(); v != "43" {
|
||||||
t.Fatalf("invalid span trace id %#+v", v)
|
t.Fatalf("invalid span trace id %#+v", v)
|
||||||
@@ -29,4 +79,39 @@ func TestTraceID(t *testing.T) {
|
|||||||
if v := sp.SpanID(); v != "44" {
|
if v := sp.SpanID(); v != "44" {
|
||||||
t.Fatalf("invalid span span id %#+v", v)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user