Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add OpenTracing shim #212

Merged
merged 35 commits into from
Sep 20, 2019
Merged

feat: Add OpenTracing shim #212

merged 35 commits into from
Sep 20, 2019

Conversation

bg451
Copy link
Member

@bg451 bg451 commented Aug 22, 2019

Resolves #181

In order to make the transition to OpenTelemetry easy for existing OpenCensus and Opentracing users, we'd like to allow folks to keep using their existing instrumentation and have it report to an OpenTelemetry backend. The shim wraps opentelem span types and implements the OpenTracing API.

Open Questions

I don't have a good answer here so I'd like to ask for some help here.

  • Baggage: What do we do with it? We can add a field to the SpanContextShim to hold baggage and propagate it in band and attach baggage to the span as attributes, however we can't exactly propagate across the wire. Additionally, @rochdev mentioned a while ago that datadog attaches vendor specific metadata to their OT context objects. How do we represent that here?
  • Binary Format: This is more about the limits of my knowledge of typescript type assertions and typed arrays. OpenTracing defines the carrier for binary format as an [Array-like object](https://github.com/opentracing/opentracing-javascript/blob/master/src/constants.ts#L5, but I guess how do we go from that to a Uint8Array? Would love some help with this.

TODOs

  • inject/extract for binary format.
  • comprehensive testing

@bg451 bg451 marked this pull request as ready for review August 26, 2019 18:09
Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

Great work! Added a few comments, will review tests in the second round.

@@ -0,0 +1,11 @@
# OpenTracing shim
[![Gitter chat][gitter-image]][gitter-url]
Copy link
Member

Choose a reason for hiding this comment

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

All the links are missing...

Copy link
Member

Choose a reason for hiding this comment

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

You should include these reference-style links at the bottom.

[gitter-image]: https://badges.gitter.im/open-telemetry/opentelemetry-js.svg
[gitter-url]: https://gitter.im/open-telemetry/opentelemetry-node?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
[license-url]: https://github.com/open-telemetry/opentelemetry-js/blob/master/LICENSE
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
[dependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js/status.svg?path=packages/opentelemetry-shim-opentracing
[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-shim-opentracing
[devDependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js/dev-status.svg?path=packages/opentelemetry-shim-opentracing
[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-shim-opentracing&type=dev

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah will add them shortly, finally have the build working :)

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is still missing.

packages/opentelemetry-shim-opentracing/src/shim.ts Outdated Show resolved Hide resolved
packages/opentelemetry-shim-opentracing/src/shim.ts Outdated Show resolved Hide resolved
packages/opentelemetry-shim-opentracing/src/shim.ts Outdated Show resolved Hide resolved
}

setTag(key: string, value: unknown): this {
this._span.setAttribute(key, value);
Copy link
Member

Choose a reason for hiding this comment

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

If key === opentracing.Tags.ERROR, we should report them as this._span.setStatus (CanonicalCode.OK or CanonicalCode.UNKNOWN). Also, If key === opentracing.Tags.SPAN_KIND, we should ignore that tag, see open-telemetry/opentelemetry-java#42.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we should ignore tags since that might break existing instrumentation and dashboards if the user relies on span.kind. For example, within LightStep you can define an arbitrary search and collect traces+latency metrics for that search. A common example is operation_name:my-rpc-call tag:span.kind=client and operation_name:my-rpc-call tag:span.kind=server to differentiate latency between clients and servers.

@mayurkale22
Copy link
Member

Strangely, CircleCI jobs are not running for this PR. Any idea?

@bg451 bg451 changed the title Add OpenTracing shim feat: Add OpenTracing shim Aug 27, 2019
@bg451
Copy link
Member Author

bg451 commented Aug 27, 2019

Oh interesting... so when I created a PR for this in my forked repo, the circleCI jobs kicked off.


/**
* TracerShim wraps a {@link types.Tracer} and implements the
* OpenTracing span context API.
Copy link
Member

Choose a reason for hiding this comment

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

typo: s/span context API/Tracer API?

Copy link
Member

Choose a reason for hiding this comment

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

Any update here?

packages/opentelemetry-shim-opentracing/src/shim.ts Outdated Show resolved Hide resolved
packages/opentelemetry-shim-opentracing/src/shim.ts Outdated Show resolved Hide resolved
}

getBaggageItem(key: string): string | undefined {
// TODO: should this go into the context?
Copy link
Member

Choose a reason for hiding this comment

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

For now, return undefined?

Copy link
Member

Choose a reason for hiding this comment

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

Could you please issues on baggage and binaryFormat (mentioned in the Open questions)? Probably we can merge this one and handle these issues separately.

packages/opentelemetry-shim-opentracing/src/shim.ts Outdated Show resolved Hide resolved
packages/opentelemetry-shim-opentracing/src/shim.ts Outdated Show resolved Hide resolved
packages/opentelemetry-shim-opentracing/src/shim.ts Outdated Show resolved Hide resolved
packages/opentelemetry-shim-opentracing/src/shim.ts Outdated Show resolved Hide resolved
* @param finishTime An optional timestamp to explicitly set the span's end time.
*/
finish(finishTime?: number): void {
this._span.end(finishTime);
Copy link
Contributor

Choose a reason for hiding this comment

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

If I recall correctly, OpenTracing uses epoch times, but we are using performance.now timestamps in OpenTelemetry for higher accuracy. Do we need to reverse translate this?

Alternatively, we could also make OpenTelemetry accept either type of timestamp - you can deterministically tell what type of timestamp it is based on its size (this is true because no Node processes or browser tabs were open in 1970...)

Copy link
Contributor

Choose a reason for hiding this comment

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

Per conversation in the SIG, we will make the API accept either peformance.now timestamps or epoch timestamps so that this code can be left as-is

Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@draffensperger draffensperger left a comment

Choose a reason for hiding this comment

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

LGTM pending final comment about adding a tslint.json based on the base one and the tslint-microsoft-contrib package (that change happened since this PR was started ...)

"access": "public"
},
"devDependencies": {
"@types/mocha": "^5.2.7",
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a tslint.json file that matches https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-core/tslint.json ? And then also add the tslint-microsoft-contrib package? That will enable this package to pick up new TSLint goodies such as the license header checks, and anything else we add in later

Copy link
Member

Choose a reason for hiding this comment

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

also please add "tslint-consistent-codestyle":"^1.15.1",

@mayurkale22
Copy link
Member

@OlivierAlbertini @danielkhan @vmarchaud @hekike @rochdev ping, for reviews.

Copy link
Contributor

@danielkhan danielkhan left a comment

Choose a reason for hiding this comment

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

LGTM but I'm no OpenTracing expert. I think it's still safe to go ahead and try some end-to-end tests to discover possible issues.

@bg451
Copy link
Member Author

bg451 commented Sep 18, 2019

@mayurkale22 I think we have enough approvals to merge

packages/opentelemetry-shim-opentracing/LICENSE Outdated Show resolved Hide resolved
packages/opentelemetry-shim-opentracing/package.json Outdated Show resolved Hide resolved
"access": "public"
},
"devDependencies": {
"@types/mocha": "^5.2.7",
Copy link
Member

Choose a reason for hiding this comment

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

also please add "tslint-consistent-codestyle":"^1.15.1",

@@ -0,0 +1,4 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

should be

{
  "rulesDirectory": ["node_modules/tslint-microsoft-contrib"],
  "extends": ["../../tslint.base.js", "./node_modules/tslint-consistent-codestyle"]
}
``` 

case opentracing.FORMAT_BINARY:
// @todo: Implement binary format
return;
default:
Copy link
Member

@OlivierAlbertini OlivierAlbertini Sep 18, 2019

Choose a reason for hiding this comment

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

default should have logger.warning(${format} is unsupported) or never (https://basarat.gitbooks.io/typescript/docs/types/never.html)

Copy link
Member Author

Choose a reason for hiding this comment

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

went with logger

switch (format) {
// tslint:disable-next-line:no-switch-case-fall-through
case opentracing.FORMAT_HTTP_HEADERS:
case opentracing.FORMAT_TEXT_MAP:
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that opentracing.FORMAT_HTTP_HEADERS is the same as opentracing.FORMAT_TEXT_MAP

Copy link
Member Author

Choose a reason for hiding this comment

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

since opentelemetry doesn't support a text map format, http is the closest we get. fwiw both http and text have the same carrier type in opentracing and http is a stricter subset of text map so I think they're basically equivalent, plus it's going to the same inject/extract implementation

Copy link
Member

@OlivierAlbertini OlivierAlbertini left a comment

Choose a reason for hiding this comment

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

LGTM. added few comments. Good job!

Brandon Gonzalez added 2 commits September 19, 2019 12:03
@mayurkale22
Copy link
Member

@bg451 Once Olivier's comments fixed, feel free to merge 👍

@bg451 bg451 merged commit ede7886 into open-telemetry:master Sep 20, 2019
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
Signed-off-by: Naseem <naseem@transit.app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

util: Add OpenTracing to OpenTelemetry shim
5 participants