Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

feat!: allow users to specify a trace policy impl#1027

Merged
kjin merged 11 commits intogoogleapis:masterfrom
kjin:new-trace-policy
May 16, 2019
Merged

feat!: allow users to specify a trace policy impl#1027
kjin merged 11 commits intogoogleapis:masterfrom
kjin:new-trace-policy

Conversation

@kjin
Copy link
Copy Markdown
Contributor

@kjin kjin commented May 13, 2019

Fixes #994

This PR allows users to override the built-in TracePolicy object with their own implementation. Such an implementation has the following interface:

interface TracePolicy {
  shouldTrace: (
    requestDetails: {
      timestamp: number;
      url: string;
      method: string;
      traceContext: {traceId: string; spanId: string; options: number;}|null;
      options: {};
    }
  ) => boolean;
}

It also makes a breaking change to the config option:

  • contextHeaderBehavior now only affects sampling.
  • propagateTraceContextFromHeader has been added to allow users to ignore trace context when creating new trace and span IDs.
  • ignoreContextHeader has been removed. It was already deprecated. (propagateTraceContextFromHeader) is meant to represent the semantic opposite of it.

Internally, a TracePolicy object is now instantiated outside of StackdriverTracer and passed in (it used to be instantiated by the StackdriverTracer instance).

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 13, 2019
@kjin kjin force-pushed the new-trace-policy branch 2 times, most recently from ac42747 to a78929b Compare May 13, 2019 23:18
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2019

Codecov Report

Merging #1027 into master will decrease coverage by 0.07%.
The diff coverage is 93.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1027      +/-   ##
==========================================
- Coverage   94.81%   94.73%   -0.08%     
==========================================
  Files          96       96              
  Lines        6186     6226      +40     
  Branches      481      486       +5     
==========================================
+ Hits         5865     5898      +33     
- Misses        166      172       +6     
- Partials      155      156       +1
Impacted Files Coverage Δ
src/config.ts 100% <ø> (ø) ⬆️
src/trace-plugin-loader.ts 92.56% <100%> (+0.05%) ⬆️
src/index.ts 89.36% <100%> (-0.44%) ⬇️
test/utils.ts 89.39% <100%> (+0.5%) ⬆️
test/plugins/common.ts 95.58% <100%> (+0.06%) ⬆️
test/test-config-plugins.ts 100% <100%> (ø) ⬆️
src/tracing.ts 89.09% <100%> (+0.41%) ⬆️
test/test-plugin-loader.ts 98.66% <100%> (+0.66%) ⬆️
src/trace-api.ts 93.63% <100%> (-0.33%) ⬇️
test/test-trace-api.ts 100% <100%> (ø) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e956d45...a78929b. Read the comment docs.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2019

Codecov Report

Merging #1027 into master will increase coverage by 0.08%.
The diff coverage is 95.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1027      +/-   ##
==========================================
+ Coverage   94.81%   94.89%   +0.08%     
==========================================
  Files          96       96              
  Lines        6186     6226      +40     
  Branches      481      484       +3     
==========================================
+ Hits         5865     5908      +43     
+ Misses        166      161       -5     
- Partials      155      157       +2
Impacted Files Coverage Δ
test/nocks.ts 52.38% <ø> (+12.38%) ⬆️
src/config.ts 100% <ø> (ø) ⬆️
src/trace-plugin-loader.ts 92.56% <100%> (+0.05%) ⬆️
test/plugins/test-trace-grpc.ts 97.68% <100%> (ø) ⬆️
test/plugins/common.ts 95.58% <100%> (+0.06%) ⬆️
test/utils.ts 89.39% <100%> (+0.5%) ⬆️
src/tracing.ts 89.09% <100%> (+0.41%) ⬆️
test/test-plugin-loader.ts 98.66% <100%> (+0.66%) ⬆️
src/trace-api.ts 93.51% <100%> (-0.45%) ⬇️
test/test-config-plugins.ts 100% <100%> (ø) ⬆️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e956d45...35d7d20. Read the comment docs.

kjin added 2 commits May 13, 2019 16:30
BREAKING CHANGE: contextHeaderBehavior and ignoreContextHeader now
act independently of one another. The former controls how a sampling
decision is made based on incoming context header, and the latter
controls whether trace context is propagated to the current
request.
@kjin kjin force-pushed the new-trace-policy branch from a78929b to a99da51 Compare May 13, 2019 23:30
Comment thread src/config.ts Outdated
* For advanced usage only.
* If specified, overrides the built-in trace policy object. Note that
* ignoreUrls, ignoreMethods, samplingRate, and contextHeaderBehavior will be
* ignored if this field is specified.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a throw if any of ignored fields are provided along with tracePolicy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made it a warning... AFAICT we try not to throw, right?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clearly indicates user error. This is a good example for when one should throw.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, makes sense. I've changed it to throw instead.

Comment thread src/config.ts Outdated
Comment thread src/trace-api.ts Outdated
Comment thread src/tracing-policy.ts Outdated
@kjin kjin force-pushed the new-trace-policy branch from 6977350 to 3893059 Compare May 14, 2019 18:34
@kjin kjin force-pushed the new-trace-policy branch from 3b450e6 to bcf48db Compare May 14, 2019 21:53
Comment thread src/config.ts
}

export interface TracePolicy {
shouldTrace: (requestDetails: RequestDetails) => boolean;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like boilerplate to pass in an object wrapping a funciton. Could you just accept a function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather we accept the object. With propagation we would have another overriding class Propagation where it makes more sense to have an object, because there are three fields. This would also allow users to easily implement a class and pass in an instance of a class.

Comment thread src/config.ts Outdated
@kjin kjin merged commit b37aa3d into googleapis:master May 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracer periodically forgets configuration and traces every request (badly)

3 participants