zipkin-tracer 0.45.0 → 0.47.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d468909c2b28497b50dba2901e92f651ec45b555cca6fc1453258140e996f0d
4
- data.tar.gz: 79508ca6c29d18906610ddf0950e33951e05f5db185e169af895a3982df3c40d
3
+ metadata.gz: 853e0ae1f408f68a420193b5deb379ab1acbd697b75f98bfbd9115071eb62902
4
+ data.tar.gz: 960b5be09c3c54a38ea23596a6e085a4d5beb9908ab2309c36027dbc6fe3933a
5
5
  SHA512:
6
- metadata.gz: e3f979dfa0f2be704ab85940dd4e6d6738fd9c587750b04929304eb72b55b122375a7e1c3e8ac2b8fac238aa8c154d24a8dae86e07bdf36f1d0e974a604cdbf5
7
- data.tar.gz: 8bc0b4f4b2ee75570563d0a4aaba3823a8f6b6a8ccb1c99c0063e38726e9cedf749ab9722be3eb3837db0947e8f43b2ee44c47df6a8e6f378815adf7a6ceca58
6
+ metadata.gz: 9b11d82d1c20be368f1b0ec44c98d53648f9bba071880b65e4a37f455d529014d693a0a8808cb46e4aa661375b40ecc9725aa267f177a322297d6f74be0166a8
7
+ data.tar.gz: 3a9650a7b7a9e926af207c1064f5e45206545c879f8b00625d83dc020e82dbc388e5574dea1974697cd46a301e78730198d660095b862e01e539300a18c5556c
@@ -0,0 +1,11 @@
1
+ # Contributing to Zipkin
2
+
3
+ If you would like to contribute code, fork this GitHub repository and
4
+ send a pull request (on a branch other than `master` or `gh-pages`).
5
+
6
+ ## License
7
+
8
+ By contributing your code, you agree to license your contribution under
9
+ the terms of the [APLv2](../LICENSE).
10
+
11
+ All files are copyright "The OpenZipkin Authors" and released with the Apache 2.0 license.
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: Bug
3
+ about: If you’ve found a bug, spend the time to write a failing test. Bugs with tests get fixed and stay fixed. If you have a solution in mind, skip raising an issue and open a pull request instead.
4
+ labels: bug
5
+ ---
6
+ ## Describe the Bug
7
+ A clear and concise description of what the bug is. If you have a solution in mind, skip raising an issue and open a pull request instead.
8
+
9
+ Regardless, the best is to spend some time to write a failing test. Bugs with tests get fixed and stay fixed.
10
+
11
+ ## Steps to Reproduce
12
+ Steps to reproduce the behavior:
13
+
14
+ ## Expected Behaviour
15
+ Suggest what you think correct behaviour should be. Note, it may be solved differently depending on the problem.
@@ -0,0 +1,5 @@
1
+ blank_issues_enabled: false
2
+ contact_links:
3
+ - name: Question
4
+ url: https://gitter.im/openzipkin/zipkin
5
+ about: Please ask questions about how to do something or to understand why something isn't working on our Gitter chat - we'll be happy to respond there in detail. This issue tracker is not for questions.
@@ -0,0 +1,19 @@
1
+ ---
2
+ name: Feature Request
3
+ about: Please first, look at existing issues to see if the feature has been requested before.
4
+ labels: enhancement
5
+ ---
6
+ Please first, look at [existing issues](https://github.com/openzipkin/zipkin-ruby/issues) to see if the feature has been requested before. If you don't find anything tell us what problem you’re trying to solve. Often a solution already exists! Don’t send pull requests to implement new features without first getting our support. Sometimes we leave features out on purpose to keep the project small.
7
+
8
+ ## Feature
9
+ Description of the feature
10
+
11
+ ## Rationale
12
+ Why would this feature help others besides me?
13
+
14
+ ## Example Scenario
15
+ What kind of use cases would benefit from this feature?
16
+
17
+ ## Prior Art
18
+ * Links to prior art
19
+ * More links
@@ -0,0 +1,34 @@
1
+ # yamllint --format github .github/workflows/deploy.yml
2
+ ---
3
+ name: deploy
4
+
5
+ # We deploy on a release versions, regardless of if the commit is documentation-only or not.
6
+ #
7
+ # See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
8
+ on:
9
+ push:
10
+ tags: '[0-9]+.[0-9]+.[0-9]+**' # Ex. 1.2.3
11
+
12
+ jobs:
13
+ deploy:
14
+ runs-on: ubuntu-20.04 # newest available distribution, aka focal
15
+ steps:
16
+ - name: Checkout Repository
17
+ uses: actions/checkout@v2
18
+ with:
19
+ fetch-depth: 1 # full history is not needed
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: 2.7
24
+ bundler-cache: true
25
+ - name: Deploy
26
+ env:
27
+ # RUBYGEMS_API_KEY=<hex token value>
28
+ # - needs to own the gem
29
+ # - generated at https://rubygems.org/settings/edit
30
+ RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
31
+ BUNDLE_GEMFILE: gemfiles/faraday_1.x.gemfile
32
+ run: | # GITHUB_REF will be refs/tags/MAJOR.MINOR.PATCH
33
+ build-bin/configure_deploy &&
34
+ build-bin/deploy $(echo ${GITHUB_REF} | cut -d/ -f 3)
@@ -0,0 +1,40 @@
1
+ # yamllint --format github .github/workflows/test.yml
2
+ ---
3
+ name: test
4
+
5
+ # We don't test documentation-only commits.
6
+ on:
7
+ # We run tests on non-tagged pushes to master
8
+ push:
9
+ tags: ''
10
+ branches: master
11
+ paths-ignore: '**/*.md'
12
+ # We also run tests on pull requests targeted at the master branch.
13
+ pull_request:
14
+ branches: master
15
+ paths-ignore: '**/*.md'
16
+
17
+ jobs:
18
+ test:
19
+ runs-on: ubuntu-20.04 # newest available distribution, aka focal
20
+ strategy:
21
+ fail-fast: false
22
+ matrix: # https://github.com/ruby/setup-ruby/blob/master/README.md#supported-versions
23
+ ruby: [2.3, 2.4, 2.5, 2.6, 2.7, jruby-9.1, jruby-9.2]
24
+ gemfile:
25
+ - gemfiles/faraday_0.x.gemfile
26
+ - gemfiles/faraday_1.x.gemfile
27
+ steps:
28
+ - name: Checkout Repository
29
+ uses: actions/checkout@v2
30
+ with:
31
+ fetch-depth: 1 # full history is not needed
32
+ - name: Set up Ruby
33
+ uses: ruby/setup-ruby@v1
34
+ with:
35
+ ruby-version: ${{ matrix.ruby }}
36
+ bundler-cache: true
37
+ - name: Test
38
+ run: build-bin/configure_test && build-bin/test
39
+ env:
40
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
data/.gitignore CHANGED
@@ -33,3 +33,7 @@
33
33
  Gemfile.lock
34
34
 
35
35
  .byebug_history
36
+
37
+ # IntelliJ
38
+ .idea
39
+ *.iml
@@ -1,3 +1,18 @@
1
+ # 0.47.3
2
+ * Moved CI to [GitHub Actions](https://github.com/openzipkin/zipkin-ruby/workflows).
3
+
4
+ # 0.47.2
5
+ * Fix to not flush local component span when a server span or a consumer span is in the stack.
6
+
7
+ # 0.47.1
8
+ * Fix to set `SERVER` span kind at the beginning to avoid being flushed before closing.
9
+
10
+ # 0.47.0
11
+ * Add a `check_routes` option to make the routable request check optional.
12
+
13
+ # 0.46.0
14
+ * Add Amazon SQS tracer.
15
+
1
16
  # 0.45.0
2
17
  * Add a `trace_context` option to the TraceWrapper utility class to retrieve trace data.
3
18
 
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # ZipkinTracer: Zipkin client for Ruby
2
2
 
3
- [![Build Status](https://api.travis-ci.org/openzipkin/zipkin-ruby.svg?branch=master)](https://travis-ci.org/openzipkin/zipkin-ruby)
3
+ [![Gitter chat](http://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg)](https://gitter.im/openzipkin/zipkin)
4
+ [![Build Status](https://github.com/openzipkin/zipkin-ruby/workflows/test/badge.svg)](https://github.com/openzipkin/zipkin-ruby/actions?query=workflow%3Atest)
5
+ [![Gem Version](https://badge.fury.io/rb/zipkin-tracer.svg)](https://badge.fury.io/rb/zipkin-tracer)
4
6
 
5
7
  Rack and Faraday integration middlewares for Zipkin tracing.
6
8
 
@@ -21,6 +23,7 @@ use ZipkinTracer::RackHandler, config
21
23
  * `:service_name` **REQUIRED** - the name of the service being traced. There are two ways to configure this value. Either write the service name in the config file or set the "DOMAIN" environment variable (e.g. 'test-service.example.com' or 'test-service'). The environment variable takes precedence over the config file value.
22
24
  * `:sample_rate` (default: 0.1) - the ratio of requests to sample, from 0 to 1
23
25
  * `:sampled_as_boolean` - When set to true (default but deprecrated), it uses true/false for the `X-B3-Sampled` header. When set to false uses 1/0 which is preferred.
26
+ * `:check_routes` - When set to `true`, only routable requests are sampled. Defaults to `false`.
24
27
  * `:trace_id_128bit` - When set to true, high 8-bytes will be prepended to trace_id. The upper 4-bytes are epoch seconds and the lower 4-bytes are random. This makes it convertible to Amazon X-Ray trace ID format v1. (See http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-request-tracing.html)
25
28
  * `:async` - By default senders will flush traces asynchronously. Set to `false` to make that process synchronous. Only supported by the HTTP, RabbitMQ, and SQS senders.
26
29
  * `:logger` - The default logger for Rails apps is `Rails.logger`, else it is `STDOUT`. Use this option to pass a custom logger.
@@ -81,6 +84,38 @@ end
81
84
 
82
85
  By default workers aren't traced. You can specify the workers that you want to trace with traceable_workers config option. If you want all your workers to be traced pass [:all] to traceable_workers option (traceable_workers: [:all]).
83
86
 
87
+ ### Tracing Amazon SQS messages
88
+
89
+ Amazon SQS tracing can be turned on by requiring [zipkin-tracer/sqs/adapter](lib/zipkin-tracer/sqs/adapter.rb):
90
+ ```ruby
91
+ require 'zipkin-tracer/sqs/adapter'
92
+ ```
93
+
94
+ This SQS adapter overrides the `send_message` and `send_message_batch` methods to add trace data as message attributes and to generate a producer span when the methods are called. Since all SQS messages are affected, it is not recommended to use this feature with the [SQS sender](lib/zipkin-tracer/zipkin_sqs_sender.rb).
95
+
96
+ When receiving messages, you need to pass the `message_attribute_names: ['All']` option to retrive message attributes:
97
+ ```ruby
98
+ resp = sqs.receive_message(
99
+ queue_url: queue_url,
100
+ message_attribute_names: ['All']
101
+ )
102
+ ```
103
+
104
+ Then you can utilize the [TraceWrapper](#tracewrapper) class to generate a consumer span:
105
+ ```ruby
106
+ msg = resp.messages.first
107
+ trace_context = msg.message_attributes.each_with_object({}) { |(key, value), hsh| hsh[key.to_sym] = value.string_value }
108
+
109
+ TraceWrapper.wrap_in_custom_span(config, 'receive_message',
110
+ span_kind: Trace::Span::Kind::CONSUMER,
111
+ trace_context: trace_context
112
+ ) do |span|
113
+ span.remote_endpoint = Trace::Endpoint.remote_endpoint(nil, 'amazon-sqs')
114
+ span.record_tag('queue.url', queue_url)
115
+ :
116
+ end
117
+ ```
118
+
84
119
  ### Local tracing
85
120
 
86
121
  `ZipkinTracer::TraceClient` provides an API to record local traces in your application.
data/RELEASE.md CHANGED
@@ -1,6 +1,44 @@
1
- ## Release Process
1
+ # OpenZipkin Release Process
2
2
 
3
- * tag the commit `git tag -v0.0.0`
4
- * push tags to origin `git push origin --tags`
5
- * Travis will automatically build and push to rubygems
6
- * TODO: have travis push the tag using info from version.rb
3
+ This repo uses semantic versions. Please keep this in mind when choosing version numbers.
4
+
5
+ 1. **Alert others you are releasing**
6
+
7
+ There should be no commits made to master while the release is in progress (about 10 minutes). Before you start
8
+ a release, alert others on [gitter](https://gitter.im/openzipkin/zipkin) so that they don't accidentally merge
9
+ anything. If they do, and the build fails because of that, you'll have to recreate the release tag described below.
10
+
11
+ 1. **Push a git tag**
12
+
13
+ The tag should formatted `MAJOR.MINOR.PATCH`, ex `git tag 1.18.1 && git push origin 1.18.1`.
14
+
15
+ 1. **Wait for CI**
16
+
17
+ The `MAJOR.MINOR.PATCH` tag triggers [`build-bin/deploy`](build-bin/deploy), which does the following:
18
+ * https://rubygems.org/gems/zipkin-tracer [`build-bin/gem/gem_push`](build-bin/gem/gem_push)
19
+
20
+ ## Credentials
21
+
22
+ The release process uses various credentials. If you notice something failing due to unauthorized,
23
+ look at the notes in [.github/workflows/deploy.yml] and check the [org secrets](https://github.com/organizations/openzipkin/settings/secrets/actions).
24
+
25
+ ## Manually releasing
26
+
27
+ If for some reason, you lost access to CI or otherwise cannot get automation to work, bear in mind
28
+ this is a normal ruby project, and can be released accordingly.
29
+
30
+ ```bash
31
+ # First, set variable according to your personal credentials. These would normally be assigned as
32
+ # org secrets: https://github.com/organizations/openzipkin/settings/secrets/actions
33
+ export RUBYGEMS_API_KEY=your_api_key
34
+ release_version=xx-version-to-release-xx
35
+
36
+ # now from latest master, create the MAJOR.MINOR.PATCH tag
37
+ git tag ${release_version}
38
+
39
+ # Run the deploy using the version you added as a tag
40
+ ./build-bin/deploy ${release_version}
41
+
42
+ # Finally, push the tag
43
+ git push origin ${release_version}
44
+ ```
@@ -0,0 +1,203 @@
1
+ # Test and Deploy scripts
2
+
3
+ This is a Ruby project, which uses standard conventions for test and deploy.
4
+
5
+ Test is normal, except there's a matrix in [CI setup](../.github/workflows/test.yml).
6
+
7
+ To create a release, push a MAJOR.MINOR.PATCH tag (ex `0.47.2`). Below are details about the deployment process.
8
+
9
+ Notably, the [gem version](../lib/zipkin-tracer/version.rb) is lazy set, defaulting to `0.0.0`. When
10
+ a release MAJOR.MINOR.PATCH tag (ex `0.47.2`) is pushed, this file is overwritten as a side effect of running
11
+ [deploy]. The release version is not written into git history except as a part of [../CHANGELOG.md].
12
+
13
+ [//]: # (Below here should be standard for all projects)
14
+
15
+ ## Build Overview
16
+ `build-bin` holds portable scripts used in CI to test and deploy the project.
17
+
18
+ The scripts here are portable. They do not include any CI provider-specific logic or ENV variables.
19
+ This helps `.travis.yml` and `test.yml` (GitHub Actions) contain nearly the same contents, even if
20
+ certain OpenZipkin projects need slight adjustments here. Portability has proven necessary, as
21
+ OpenZipkin has had to transition CI providers many times due to feature and quota constraints.
22
+
23
+ These scripts serve a second purpose, which is to facilitate manual releases, which has also
24
+ happened many times due usually to service outages of CI providers. While tempting to use
25
+ CI-provider specific tools, doing so can easily create a dependency where no one knows how to
26
+ release anymore. Do not use provider-specific mechanisms to implement release flow. Instead,
27
+ automate triggering of the scripts here.
28
+
29
+ The only scripts that should be modified per project are in the base directory. Those in sub
30
+ directories, such as [docker], should not vary project to project except accident of version drift.
31
+ Intentional changes in sub directories should be relevant and tested on multiple projects to ensure
32
+ they can be blindly copy/pasted.
33
+
34
+ Conversely, the files in the base directory are project specific entry-points for test and deploy
35
+ actions and are entirely appropriate to vary per project. Here's an overview:
36
+
37
+ ## Test
38
+
39
+ Test builds and runs any tests of the project, including integration tests. CI providers should be
40
+ configured to run tests on pull requests or pushes to the master branch, notably when the tag is
41
+ blank. Tests should not run on documentation-only commits. Tests must not depend on authenticated
42
+ resources, as running tests can leak credentials. Git checkouts should include the full history so
43
+ that license headers or other git analysis can take place.
44
+
45
+ * [configure_test] - Sets up build environment for tests.
46
+ * [test] - Builds and runs tests for this project.
47
+
48
+ ### Example GitHub Actions setup
49
+
50
+ A simplest GitHub Actions `test.yml` runs tests after configuring them, but only on relevant event
51
+ conditions. The name `test.yml` and job `test` allows easy references to status badges and parity of
52
+ the scripts it uses.
53
+
54
+ The `on:` section obviates job creation and resource usage for irrelevant events. Notably, GitHub
55
+ Actions includes the ability to skip documentation-only jobs.
56
+
57
+ Combine [configure_test] and [test] into the same `run:` when `configure_test` primes file system
58
+ cache.
59
+
60
+ Here's a partial `test.yml` including only the aspects mentioned above.
61
+ ```yaml
62
+ on:
63
+ push:
64
+ tags: ''
65
+ branches: master
66
+ paths-ignore: '**/*.md'
67
+ pull_request:
68
+ branches: master
69
+ paths-ignore: '**/*.md'
70
+
71
+ jobs:
72
+ test:
73
+ steps:
74
+ - name: Checkout Repository
75
+ uses: actions/checkout@v2
76
+ with:
77
+ fetch-depth: 0 # full git history
78
+ - name: Test
79
+ run: build-bin/configure_test && build-bin/test
80
+ ```
81
+
82
+ ### Example Travis setup
83
+ `.travis.yml` is a monolithic configuration file broken into stages, of which the default is "test".
84
+ A simplest Travis `test` job configures tests in `install` and runs them as `script`, but only on
85
+ relevant event conditions.
86
+
87
+ The `if:` section obviates job creation and resource usage for irrelevant events. Travis does not
88
+ support file conditions. A `before_install` step to skip documentation-only commits will likely
89
+ complete in less than a minute (10 credit cost).
90
+
91
+ Here's a partial `.travis.yml` including only the aspects mentioned above.
92
+ ```yaml
93
+ git:
94
+ depth: false # full git history for license check, and doc-only skipping
95
+
96
+ jobs:
97
+ include:
98
+ - stage: test
99
+ if: branch = master AND tag IS blank AND type IN (push, pull_request)
100
+ name: Run unit and integration tests
101
+ before_install: |
102
+ if [ -n "${TRAVIS_COMMIT_RANGE}" ] && ! git diff --name-only "${TRAVIS_COMMIT_RANGE}" -- | grep -qv '\.md$'; then
103
+ echo "Stopping job as changes only affect documentation (ex. README.md)"
104
+ travis_terminate 0
105
+ fi
106
+ install: ./build-bin/configure_test
107
+ script: ./build-bin/test
108
+ ```
109
+
110
+ ## Deploy
111
+
112
+ Deploy builds and pushes artifacts to a remote repository for master and release commits on it. CI
113
+ providers deploy pushes to master on when the tag is blank, but not on documentation-only commits.
114
+ Releases should deploy on version tags (ex `/^[0-9]+\.[0-9]+\.[0-9]+/`), without consideration of if
115
+ the commit is documentation only or not.
116
+
117
+ * [configure_deploy] - Sets up environment and logs in, assuming [configure_test] was not called.
118
+ * [deploy] - deploys the project, with arg0 being "master" or a release commit like "1.2.3"
119
+
120
+ ### Example GitHub Actions setup
121
+
122
+ A simplest GitHub Actions `deploy.yml` deploys after logging in, but only on relevant event
123
+ conditions. The name `deploy.yml` and job `deploy` allows easy references to status badges and
124
+ parity of the scripts it uses.
125
+
126
+ The `on:` section obviates job creation and resource usage for irrelevant events. GitHub Actions
127
+ cannot implement "master, except documentation only-commits" in the same file. Hence, deployments of
128
+ master will happen even on README change.
129
+
130
+ Combine [configure_deploy] and [deploy] into the same `run:` when `configure_deploy` primes file
131
+ system cache.
132
+
133
+ Here's a partial `deploy.yml` including only the aspects mentioned above. Notice env variables are
134
+ explicitly defined and `on.tags` is a [glob pattern](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet).
135
+ ```yaml
136
+ on:
137
+ push:
138
+ tags: '[0-9]+.[0-9]+.[0-9]+**' # Ex. 8.272.10 or 15.0.1_p9
139
+ branches: master
140
+
141
+ jobs:
142
+ deploy:
143
+ steps:
144
+ - name: Checkout Repository
145
+ uses: actions/checkout@v2
146
+ with:
147
+ fetch-depth: 1 # only needed to get the sha label
148
+ - name: Deploy
149
+ env:
150
+ GH_USER: ${{ secrets.GH_USER }}
151
+ GH_TOKEN: ${{ secrets.GH_TOKEN }}
152
+ run: | # GITHUB_REF will be refs/heads/master or refs/tags/MAJOR.MINOR.PATCH
153
+ build-bin/configure_deploy &&
154
+ build-bin/deploy $(echo ${GITHUB_REF} | cut -d/ -f 3)
155
+ ```
156
+
157
+ ### Example Travis setup
158
+ `.travis.yml` is a monolithic configuration file broken into stages. This means `test` and `deploy`
159
+ are in the same file. A simplest Travis `deploy` stage has two jobs: one for master pushes and
160
+ another for version tags. These jobs are controlled by event conditions.
161
+
162
+ The `if:` section obviates job creation and resource usage for irrelevant events. Travis does not
163
+ support file conditions. A `before_install` step to skip documentation-only commits will likely
164
+ complete in less than a minute (10 credit cost).
165
+
166
+ As billing is by the minute, it is most cost effective to combine test and deploy on master push.
167
+
168
+ Here's a partial `.travis.yml` including only the aspects mentioned above. Notice YAML anchors work
169
+ in Travis and `tag =~` [condition](https://github.com/travis-ci/travis-conditions) is a regular
170
+ expression.
171
+ ```yaml
172
+ git:
173
+ depth: false # full git history for license check, and doc-only skipping
174
+
175
+ _terminate_if_only_docs: &terminate_if_only_docs |
176
+ if [ -n "${TRAVIS_COMMIT_RANGE}" ] && ! git diff --name-only "${TRAVIS_COMMIT_RANGE}" -- | grep -qv '\.md$'; then
177
+ echo "Stopping job as changes only affect documentation (ex. README.md)"
178
+ travis_terminate 0
179
+ fi
180
+
181
+ jobs:
182
+ include:
183
+ - stage: test
184
+ if: branch = master AND tag IS blank AND type IN (push, pull_request)
185
+ before_install: *terminate_if_only_docs
186
+ install: |
187
+ if [ "${TRAVIS_SECURE_ENV_VARS}" = "true" ] && [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
188
+ export SHOULD_DEPLOY=true
189
+ ./build-bin/configure_deploy
190
+ else
191
+ export SHOULD_DEPLOY=false
192
+ ./build-bin/configure_test
193
+ fi
194
+ script:
195
+ - ./build-bin/test || travis_terminate 1
196
+ - if [ "${SHOULD_DEPLOY}" != "true" ]; then travis_terminate 0; fi
197
+ - travis_wait ./build-bin/deploy master
198
+ - stage: deploy
199
+ # Ex. 8.272.10 or 15.0.1_p9
200
+ if: tag =~ /^[0-9]+\.[0-9]+\.[0-9]+/ AND type = push AND env(GH_TOKEN) IS present
201
+ install: ./build-bin/configure_deploy
202
+ script: ./build-bin/deploy ${TRAVIS_TAG}
203
+ ```
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ set -ue
4
+
5
+ # This script sets up anything needed for `./deploy`. Do not assume `configure_test` was called.
6
+ #
7
+ # See [README.md] for an explanation of this and how CI should use it.
8
+ build-bin/gem/configure_gem_credentials
9
+ build-bin/gem/bundle_install
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ set -ue
4
+
5
+ # This script sets up anything needed for `./test`. This should not login to anything, as that
6
+ # should be done in `configure_deploy`.
7
+ #
8
+ # See [README.md] for an explanation of this and how CI should use it.
9
+ build-bin/gem/bundle_install
@@ -0,0 +1,11 @@
1
+ #!/bin/sh
2
+
3
+ set -ue
4
+
5
+ # This script deploys a release version.
6
+ #
7
+ # See [README.md] for an explanation of this and how CI should use it.
8
+ version=${1?version is required. ex 0.2.3}
9
+
10
+ export BUNDLE_GEMFILE=gemfiles/faraday_1.x.gemfile
11
+ build-bin/gem/gem_push zipkin-tracer ZipkinTracer ${version}
@@ -0,0 +1,20 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright 2014-2020 The OpenZipkin Authors
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6
+ # in compliance with the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software distributed under the License
11
+ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12
+ # or implied. See the License for the specific language governing permissions and limitations under
13
+ # the License.
14
+ #
15
+
16
+ set -ue
17
+
18
+ # This script ensures bundler is setup and install is run
19
+ gem install bundler
20
+ bundle install
@@ -0,0 +1,26 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright 2014-2020 The OpenZipkin Authors
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6
+ # in compliance with the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software distributed under the License
11
+ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12
+ # or implied. See the License for the specific language governing permissions and limitations under
13
+ # the License.
14
+ #
15
+
16
+ set -ue
17
+
18
+ # This script configures rubygems_api_key needed to for gem-push
19
+
20
+ credentials_file="${HOME}/.gem/credentials"
21
+ mkdir -p "$(dirname "${credentials_file}")"
22
+ cat > "${credentials_file}" <<-EOF
23
+ ---
24
+ :rubygems_api_key: ${RUBYGEMS_API_KEY}
25
+ EOF
26
+ chmod 0600 "${credentials_file}"
@@ -0,0 +1,39 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright 2014-2020 The OpenZipkin Authors
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6
+ # in compliance with the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software distributed under the License
11
+ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12
+ # or implied. See the License for the specific language governing permissions and limitations under
13
+ # the License.
14
+ #
15
+
16
+ set -ue
17
+
18
+ # This script pushes a gem version, updating version.rb if out-of-date.
19
+ #
20
+ # This assumes `configure_gem_credentials` and `bundle_install` were invoked.
21
+ gem=${1?gem is required. ex zipkin-tracer}
22
+ module=${2?module is required. ex ZipkinTracer}
23
+ version=${3?version is required. ex 0.2.3}
24
+
25
+ current_version=$(ruby -r ./lib/${gem}/version.rb -e "puts ${module}::VERSION")
26
+
27
+ if [ "${current_version}" != "${version}" ]; then
28
+ echo "Updating ${module}::VERSION from ${current_version} to ${version}"
29
+ cat > lib/${gem}/version.rb <<-EOF
30
+ # frozen_string_literal: true
31
+
32
+ module ${module}
33
+ VERSION = '${version}'
34
+ end
35
+ EOF
36
+ fi
37
+
38
+ bundle exec rake build
39
+ gem push pkg/${gem}-${version}.gem
@@ -0,0 +1,8 @@
1
+ #!/bin/sh
2
+
3
+ set -ue
4
+
5
+ # This script runs the tests of the project.
6
+ #
7
+ # See [README.md] for an explanation of this and how CI should use it.
8
+ bundle exec rspec
@@ -5,7 +5,7 @@ require 'zipkin-tracer/rack/zipkin-tracer'
5
5
  module ZipkinTracer
6
6
  # Configuration of this gem. It reads the configuration and provides default values
7
7
  class Config
8
- attr_reader :service_name, :sample_rate, :sampled_as_boolean, :trace_id_128bit, :async, :logger,
8
+ attr_reader :service_name, :sample_rate, :sampled_as_boolean, :check_routes, :trace_id_128bit, :async, :logger,
9
9
  :json_api_host, :zookeeper, :kafka_producer, :kafka_topic, :sqs_queue_name, :sqs_region, :log_tracing,
10
10
  :annotate_plugin, :filter_plugin, :whitelist_plugin, :rabbit_mq_connection, :rabbit_mq_exchange,
11
11
  :rabbit_mq_routing_key, :write_b3_single_format
@@ -47,6 +47,8 @@ module ZipkinTracer
47
47
  if @sampled_as_boolean
48
48
  @logger && @logger.warn("Using a boolean in the Sampled header is deprecated. Consider setting sampled_as_boolean to false")
49
49
  end
50
+ # When set to true, only routable requests are sampled
51
+ @check_routes = config[:check_routes].nil? ? DEFAULTS[:check_routes] : config[:check_routes]
50
52
 
51
53
  # When set to true, high 8-bytes will be prepended to trace_id.
52
54
  # The upper 4-bytes are epoch seconds and the lower 4-bytes are random.
@@ -95,6 +97,7 @@ module ZipkinTracer
95
97
  DEFAULTS = {
96
98
  sample_rate: 0.1,
97
99
  sampled_as_boolean: true,
100
+ check_routes: false,
98
101
  trace_id_128bit: false,
99
102
  write_b3_single_format: false
100
103
  }
@@ -11,15 +11,17 @@ module ZipkinTracer
11
11
 
12
12
  each_endpoint(spans) do |endpoint|
13
13
  hostname = endpoint.ipv4
14
- unless resolved_ip_address?(hostname.to_s)
15
- endpoint.ipv4 = resolved_hosts[hostname]
16
- end
14
+ next unless hostname
15
+ next if resolved_ip_address?(hostname.to_s)
16
+
17
+ endpoint.ipv4 = resolved_hosts[hostname]
17
18
  end
18
19
  end
19
20
 
20
21
  private
22
+
21
23
  LOCALHOST = '127.0.0.1'.freeze
22
- LOCALHOST_I32 = 0x7f000001.freeze
24
+ LOCALHOST_I32 = 0x7f000001
23
25
  MAX_I32 = ((2 ** 31) - 1)
24
26
  MASK = (2 ** 32) - 1
25
27
  IP_FIELD = 3
@@ -49,10 +51,9 @@ module ZipkinTracer
49
51
  end
50
52
 
51
53
  def resolve(hosts, ip_format)
52
- hosts.inject({}) do |host_map, host|
54
+ hosts.each_with_object({}) do |host, host_map|
53
55
  hostname = host.ipv4 # This field has been temporarly used to store the hostname.
54
- host_map[hostname] = host_to_format(hostname, ip_format)
55
- host_map
56
+ host_map[hostname] = host_to_format(hostname, ip_format) if hostname
56
57
  end
57
58
  end
58
59
 
@@ -25,6 +25,7 @@ module ZipkinTracer
25
25
  @app.call(env)
26
26
  else
27
27
  @tracer.with_new_span(trace_id, span_name(env)) do |span|
28
+ span.kind = Trace::Span::Kind::SERVER
28
29
  trace!(span, zipkin_env) { @app.call(env) }
29
30
  end
30
31
  end
@@ -55,7 +56,6 @@ module ZipkinTracer
55
56
  end
56
57
 
57
58
  def trace_server_information(span, zipkin_env, status)
58
- span.kind = Trace::Span::Kind::SERVER
59
59
  span.record_status(status)
60
60
  SERVER_RECV_TAGS.each { |annotation_key, env_key| span.record_tag(annotation_key, zipkin_env.env[env_key]) }
61
61
  end
@@ -71,7 +71,7 @@ module ZipkinTracer
71
71
  if parent_trace_sampled # A service upstream decided this goes in all the way
72
72
  parent_trace_sampled
73
73
  else
74
- new_sampled_header_value(force_sample? || current_trace_sampled? && !filtered? && routable_request?)
74
+ new_sampled_header_value(force_sample? || current_trace_sampled? && !filtered? && traceable_request?)
75
75
  end
76
76
  end
77
77
 
@@ -83,9 +83,10 @@ module ZipkinTracer
83
83
  @config.filter_plugin && !@config.filter_plugin.call(@env)
84
84
  end
85
85
 
86
- def routable_request?
86
+ def traceable_request?
87
+ return true unless @config.check_routes
88
+
87
89
  Application.routable_request?(@env)
88
90
  end
89
-
90
91
  end
91
92
  end
@@ -0,0 +1,4 @@
1
+ require 'aws-sdk-sqs'
2
+ require 'zipkin-tracer/sqs/zipkin-tracer'
3
+
4
+ Aws::SQS::Client.prepend(ZipkinTracer::SqsHandler)
@@ -0,0 +1,57 @@
1
+ module ZipkinTracer
2
+ # This module is designed to prepend to the SQS client to add trace data as message attributes.
3
+ # https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-sqs/lib/aws-sdk-sqs/client.rb
4
+ module SqsHandler
5
+ def send_message(params = {}, options = {})
6
+ zipkin_sqs_trace_wrapper(params, __method__) { |params_with_trace| super(params_with_trace, options) }
7
+ end
8
+
9
+ def send_message_batch(params = {}, options = {})
10
+ zipkin_sqs_trace_wrapper(params, __method__) { |params_with_trace| super(params_with_trace, options) }
11
+ end
12
+
13
+ private
14
+
15
+ ZIPKIN_KEYS = %i[trace_id parent_id span_id sampled].freeze
16
+ ZIPKIN_REMOTE_ENDPOINT_SQS = Trace::Endpoint.remote_endpoint(nil, 'amazon-sqs')
17
+
18
+ def zipkin_sqs_trace_wrapper(params, method_name)
19
+ trace_id = TraceGenerator.new.next_trace_id
20
+ zipkin_set_message_attributes(params, method_name, trace_id)
21
+
22
+ TraceContainer.with_trace_id(trace_id) do
23
+ if Trace.tracer && trace_id.sampled?
24
+ Trace.tracer.with_new_span(trace_id, method_name) do |span|
25
+ span.kind = Trace::Span::Kind::PRODUCER
26
+ span.remote_endpoint = ZIPKIN_REMOTE_ENDPOINT_SQS
27
+ span.record_tag('queue.url', params[:queue_url])
28
+ yield(params)
29
+ end
30
+ else
31
+ yield(params)
32
+ end
33
+ end
34
+ end
35
+
36
+ def zipkin_set_message_attributes(params, method_name, trace_id)
37
+ attributes = zipkin_message_attributes(trace_id)
38
+ case method_name
39
+ when :send_message
40
+ params[:message_attributes] = attributes.merge(params[:message_attributes] || {})
41
+ when :send_message_batch
42
+ params[:entries].each do |entry|
43
+ entry[:message_attributes] = attributes.merge(entry[:message_attributes] || {})
44
+ end
45
+ end
46
+ end
47
+
48
+ def zipkin_message_attributes(trace_id)
49
+ ZIPKIN_KEYS.each_with_object({}) do |zipkin_key, message_attributes|
50
+ zipkin_value = trace_id.send(zipkin_key)
51
+ next unless zipkin_value
52
+
53
+ message_attributes[zipkin_key] = { string_value: zipkin_value.to_s, data_type: 'String' }
54
+ end
55
+ end
56
+ end
57
+ end
@@ -277,8 +277,8 @@ module Trace
277
277
  end
278
278
 
279
279
  def self.remote_endpoint(url, remote_service_name)
280
- service_name = remote_service_name || url.host.split('.').first || UNKNOWN_URL # default to url-derived service name
281
- Endpoint.new(url.host, url.port, service_name)
280
+ service_name = remote_service_name || url&.host&.split('.')&.first || UNKNOWN_URL # default to url-derived service name
281
+ Endpoint.new(url&.host, url&.port, service_name)
282
282
  end
283
283
 
284
284
  def to_h
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZipkinTracer
4
- VERSION = '0.45.0'
4
+ VERSION = '0.47.3'
5
5
  end
@@ -7,8 +7,7 @@ module Trace
7
7
  # Senders dealing with zipkin should inherit from this class and implement the
8
8
  # flush! method which actually sends the information
9
9
  class ZipkinSenderBase
10
-
11
- def initialize(options={})
10
+ def initialize(options = {})
12
11
  @options = options
13
12
  reset
14
13
  end
@@ -39,8 +38,9 @@ module Trace
39
38
  end
40
39
 
41
40
  def skip_flush?(span)
42
- return true if span.kind == Trace::Span::Kind::CLIENT && span.has_parent_span?
43
- return true if span.kind == Trace::Span::Kind::PRODUCER && spans.any? { |s| s.kind == Trace::Span::Kind::SERVER }
41
+ return false if span.kind == Trace::Span::Kind::SERVER || span.kind == Trace::Span::Kind::CONSUMER
42
+
43
+ spans.any? { |s| s.kind == Trace::Span::Kind::SERVER || s.kind == Trace::Span::Kind::CONSUMER }
44
44
  end
45
45
 
46
46
  def flush!
@@ -62,6 +62,5 @@ module Trace
62
62
  def reset
63
63
  Thread.current[THREAD_KEY] = []
64
64
  end
65
-
66
65
  end
67
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipkin-tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.45.0
4
+ version: 0.47.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franklin Hu
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2020-05-22 00:00:00.000000000 Z
17
+ date: 2020-12-04 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: faraday
@@ -217,9 +217,14 @@ executables: []
217
217
  extensions: []
218
218
  extra_rdoc_files: []
219
219
  files:
220
+ - ".github/CONTRIBUTING.md"
221
+ - ".github/ISSUE_TEMPLATE/bug.md"
222
+ - ".github/ISSUE_TEMPLATE/config.yml"
223
+ - ".github/ISSUE_TEMPLATE/feature.md"
224
+ - ".github/workflows/deploy.yml"
225
+ - ".github/workflows/test.yml"
220
226
  - ".gitignore"
221
227
  - ".rspec"
222
- - ".travis.yml"
223
228
  - Appraisals
224
229
  - CHANGELOG.md
225
230
  - Gemfile
@@ -230,6 +235,14 @@ files:
230
235
  - Rakefile
231
236
  - bin/console
232
237
  - bin/setup
238
+ - build-bin/README.md
239
+ - build-bin/configure_deploy
240
+ - build-bin/configure_test
241
+ - build-bin/deploy
242
+ - build-bin/gem/bundle_install
243
+ - build-bin/gem/configure_gem_credentials
244
+ - build-bin/gem/gem_push
245
+ - build-bin/test
233
246
  - gemfiles/faraday_0.x.gemfile
234
247
  - gemfiles/faraday_1.x.gemfile
235
248
  - lib/zipkin-tracer.rb
@@ -241,6 +254,8 @@ files:
241
254
  - lib/zipkin-tracer/rack/zipkin-tracer.rb
242
255
  - lib/zipkin-tracer/rack/zipkin_env.rb
243
256
  - lib/zipkin-tracer/sidekiq/middleware.rb
257
+ - lib/zipkin-tracer/sqs/adapter.rb
258
+ - lib/zipkin-tracer/sqs/zipkin-tracer.rb
244
259
  - lib/zipkin-tracer/trace.rb
245
260
  - lib/zipkin-tracer/trace_client.rb
246
261
  - lib/zipkin-tracer/trace_container.rb
@@ -279,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
294
  - !ruby/object:Gem::Version
280
295
  version: '0'
281
296
  requirements: []
282
- rubygems_version: 3.0.6
297
+ rubygems_version: 3.1.4
283
298
  signing_key:
284
299
  specification_version: 4
285
300
  summary: Ruby tracing via Zipkin
@@ -1,36 +0,0 @@
1
- language: ruby
2
- dist: bionic
3
- jdk: openjdk11
4
-
5
- rvm:
6
- - 2.3
7
- - 2.4
8
- - 2.5
9
- - 2.6
10
- - 2.7
11
- - jruby-9.1
12
- - jruby-9.2
13
-
14
- gemfile:
15
- - gemfiles/faraday_0.x.gemfile
16
- - gemfiles/faraday_1.x.gemfile
17
-
18
- script: bundle exec rspec
19
-
20
- deploy:
21
- provider: rubygems
22
- api_key:
23
- secure: HJquPWOoh9YKHTJrGTBriao4wVDu/tn+JwZphPrS38PNu5FkzyRuhjq2XyBrm8BkuJWdqkVx9rpJTlFkcjIfhpZOJUn5gtTUgp12/voUMWBCWw9AUfbYdYkGhy6Lmq6miJcUFkhdeiMmnliz0Wav1ZYEWkodC25ACKQiGtk9rwr+4wKkluljOnmbyPFRiF61ZjSaz4qy9ZpwWOSPGuEjCQuvhW1hx0VNBjsio59sKUK0v2lFHxSfMjW+QrB5GAV0isv4CtG5V9MKMlRBX8+4RbklO0LHdCmykTDTioyYrfBI0x7RiO/l453/EH4dQEzivZ9AQNtIIshPu1Zht63LHWff4JyytSGxe5WmXaQjxfrZi2LMIXbeg5g2pPDmiMqFVSCgxFKJQW1eyU9pF3w5C4v9P0uLeizGnLReOwwjBDqiWIQ2bR4YWn+fsg/wbhjXHmefEjcJYL59niK8pw1JOcg7fy/P32wbbqILUcIg3of1ih1lyPV4YBY62KJny6e0c83zX2KukVMP9M6crW2NEspMqcQWFzbp3SR9oM0ziMDGUs0s1/PKVtuFTZ2S+ykbawX5P9YqSSx8iXp+Ez5MAMbrjiPXlzpzMvudDaN3kqRT2EomJ4iQjJOxXgUyTspLpZFojh4+RVjgi+sGEA8SeNiqrytThsCwQV1ro8ymL+8=
24
- gem: zipkin-tracer
25
- on:
26
- tags: true
27
- repo: openzipkin/zipkin-ruby
28
- condition: $TRAVIS_RUBY_VERSION == 2.7 && $BUNDLE_GEMFILE == $TRAVIS_BUILD_DIR/gemfiles/faraday_1.x.gemfile
29
-
30
- notifications:
31
- webhooks:
32
- urls:
33
- - https://webhooks.gitter.im/e/ead3c37d57527214e9f2
34
- - https://webhooks.gitter.im/e/e57478303f87ecd7bffc
35
- on_success: change
36
- on_failure: always