-
Notifications
You must be signed in to change notification settings - Fork 835
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
feature(trace): adds named tracer factory #420
Changes from 1 commit
09835be
7f9d1bb
0f2f443
bbe8767
5b01c76
b3e5508
4d30e58
191eb4a
2930934
527f0be
d8524db
868a88e
1e7f7f8
0324f3e
8695501
b74e44a
8beea48
05abd69
9150295
4528fab
af4e624
6c1e42d
8e9428a
27f16b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…that
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*! | ||
* Copyright 2019, OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as types from '@opentelemetry/types'; | ||
import { BasicTracer } from './BasicTracer'; | ||
import { SpanProcessor } from './SpanProcessor'; | ||
|
||
export abstract class AbstractBasicTracerFactory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the abstract factory specific to basic tracer? Why not just
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's due to this line specifically, since span processors is not an API level concept. /~https://github.com/open-telemetry/opentelemetry-js/pull/420/files#diff-7de0ceee2be4a0e5c9c8ba090fcc1ce4R28 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the base class they inherit from should be more general. class AbstractTracerFactory {
protected abstract _newTracer(): types.Tracer;
}
class BasicTracerFactory {
protected _newTracer(): BasicTracer {
return new BasicTracer();
}
}
class WebTracerFactory {
protected _newTracer(): WebTracer {
return new WebTracer();
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, updated the abstract factory to be more general. |
||
implements types.TracerFactory { | ||
protected readonly _tracers: Map<string, BasicTracer> = new Map(); | ||
protected _spanProcessors: SpanProcessor[] = []; | ||
|
||
addSpanProcessor(spanProcessor: SpanProcessor): void { | ||
this._spanProcessors.push(spanProcessor); | ||
for (const tracer of this._tracers.values()) { | ||
tracer.addSpanProcessor(spanProcessor); | ||
} | ||
} | ||
|
||
getTracer(name: string = '', version?: string): types.Tracer { | ||
const key = name + (version != undefined ? version : ''); | ||
if (this._tracers.has(key)) return this._tracers.get(key)!; | ||
|
||
const tracer = this._newTracer(); | ||
for (const processor of this._spanProcessors) { | ||
tracer.addSpanProcessor(processor); | ||
} | ||
this._tracers.set(key, tracer); | ||
return tracer; | ||
} | ||
|
||
protected abstract _newTracer(): BasicTracer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,36 +14,19 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import * as types from '@opentelemetry/types'; | ||
import { BasicTracerConfig } from './types'; | ||
import { BasicTracer } from './BasicTracer'; | ||
import { SpanProcessor } from './SpanProcessor'; | ||
import { AbstractBasicTracerFactory } from './AbstractBasicTracerFactory'; | ||
|
||
export class BasicTracerFactory implements types.TracerFactory { | ||
private readonly _tracers: Map<string, BasicTracer> = new Map(); | ||
private _spanProcessors: SpanProcessor[] = []; | ||
export class BasicTracerFactory extends AbstractBasicTracerFactory { | ||
private _config?: BasicTracerConfig; | ||
|
||
constructor(config?: BasicTracerConfig) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. constructor could be private, forcing users to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just commented below but check this out: /~https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/api-tracing.md#runtimes-with-multiple-deploymentsapplications There definitely is a case for multiple factories. |
||
super(); | ||
this._config = config; | ||
} | ||
|
||
addSpanProcessor(spanProcessor: SpanProcessor): void { | ||
this._spanProcessors.push(spanProcessor); | ||
for (const tracer of this._tracers.values()) { | ||
tracer.addSpanProcessor(spanProcessor); | ||
} | ||
} | ||
|
||
getTracer(name: string = '', version?: string): types.Tracer { | ||
const key = name + (version != undefined ? version : ''); | ||
if (this._tracers.has(key)) return this._tracers.get(key)!; | ||
|
||
const tracer = new BasicTracer(this._config); | ||
for (const processor of this._spanProcessors) { | ||
tracer.addSpanProcessor(processor); | ||
} | ||
this._tracers.set(key, tracer); | ||
return tracer; | ||
_newTracer(): BasicTracer { | ||
return new BasicTracer(this._config); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*! | ||
* Copyright 2019, OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { WebTracer } from './WebTracer'; | ||
import { | ||
BasicTracer, | ||
AbstractBasicTracerFactory, | ||
BasicTracerConfig, | ||
} from '@opentelemetry/tracing'; | ||
|
||
export class WebTracerFactory extends AbstractBasicTracerFactory { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, I think it should just inherit from a more general |
||
private readonly _config?: BasicTracerConfig; | ||
bg451 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
constructor(config?: BasicTracerConfig) { | ||
super(); | ||
this._config = config; | ||
} | ||
|
||
protected _newTracer(): BasicTracer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this |
||
return new WebTracer(this._config); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems weird to me the
NodeTracerFactory
extendsAbstractBasicTracerFactory
whenNodeTracer
andBasicTracer
are different