Skip to content

Commit 206c46b

Browse files
HazATkamilogorek
authored andcommitted
fix: Span changes
1 parent 2e993b3 commit 206c46b

File tree

4 files changed

+10
-25
lines changed

4 files changed

+10
-25
lines changed

packages/hub/src/hub.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export class Hub implements HubInterface {
404404
const span = top.scope.getSpan();
405405

406406
if (span) {
407-
return span.newSpan(spanContext);
407+
return span.makeChild(spanContext);
408408
}
409409
}
410410

packages/hub/src/span.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const TRACEPARENT_REGEXP = /^[ \t]*([0-9a-f]{32})?-?([0-9a-f]{16})?-?([01
1010
*/
1111
export class Span implements SpanInterface, SpanContext {
1212
/**
13-
* @inheritDoc
13+
* The reference to the current hub.
1414
*/
1515
private readonly _hub: Hub = getCurrentHub();
1616

@@ -116,7 +116,7 @@ export class Span implements SpanInterface, SpanContext {
116116
* Creates a new `Span` while setting the current `Span.id` as `parentSpanId`.
117117
* Also the `sampled` decision will be inherited.
118118
*/
119-
public newSpan(spanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'spanId'>>): Span {
119+
public makeChild(spanContext?: Pick<SpanContext, Exclude<keyof SpanContext, 'spanId'>>): Span {
120120
const span = new Span({
121121
...spanContext,
122122
parentSpanId: this._spanId,

packages/hub/test/span.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ describe('Span', () => {
1212
describe('newSpan', () => {
1313
test('simple', () => {
1414
const span = new Span({ sampled: true });
15-
const span2 = span.newSpan();
15+
const span2 = span.makeChild();
1616
expect((span2 as any)._parentSpanId).toBe((span as any)._spanId);
1717
expect((span2 as any)._traceId).toBe((span as any)._traceId);
1818
expect((span2 as any).sampled).toBe((span as any).sampled);
1919
});
2020

2121
test('gets currentHub', () => {
2222
const span = new Span({});
23-
const span2 = span.newSpan();
23+
const span2 = span.makeChild();
2424
expect((span as any)._hub).toBeInstanceOf(Hub);
2525
expect((span2 as any)._hub).toBeInstanceOf(Hub);
2626
});
@@ -74,15 +74,15 @@ describe('Span', () => {
7474
describe('newSpan', () => {
7575
test('simple', () => {
7676
const span = new Span({ sampled: true });
77-
const span2 = span.newSpan();
77+
const span2 = span.makeChild();
7878
expect((span2 as any)._parentSpanId).toBe((span as any)._spanId);
7979
expect((span2 as any)._traceId).toBe((span as any)._traceId);
8080
expect((span2 as any).sampled).toBe((span as any).sampled);
8181
});
8282

8383
test('gets currentHub', () => {
8484
const span = new Span({});
85-
const span2 = span.newSpan();
85+
const span2 = span.makeChild();
8686
expect((span as any)._hub).toBeInstanceOf(Hub);
8787
expect((span2 as any)._hub).toBeInstanceOf(Hub);
8888
});
@@ -178,7 +178,7 @@ describe('Span', () => {
178178
test('finish a scope span with transaction + child span', () => {
179179
const spy = jest.spyOn(hub as any, 'captureEvent') as any;
180180
const parentSpan = new Span({ transaction: 'test' }, hub);
181-
const childSpan = parentSpan.newSpan();
181+
const childSpan = parentSpan.makeChild();
182182
childSpan.finish();
183183
parentSpan.finish();
184184
expect(spy).toHaveBeenCalled();

packages/minimal/src/index.ts

+2-17
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,9 @@ export function _callOnClient(method: string, ...args: any[]): void {
171171
/**
172172
* This functions starts a span. If just a `SpanContext` is passed and there is already a Span
173173
* on the Scope, the created Span will have a reference to the one on the Scope.
174-
* If a Span is on the current Scope it is considered a `transaction`.
175-
* When using the second parameter it will set the created Span on the Scope (replacing whats there).
176-
* This can be used as a shortcut to not set it manually on the Scope.
177174
*
178175
* @param spanContext Properties with which the span should be created
179-
* @param bindOnScope Determines if the started span will be set on the Scope
180176
*/
181-
export function startSpan(spanContext?: SpanContext, bindOnScope?: boolean): Span {
182-
return callOnHub<Span>('startSpan', spanContext, bindOnScope);
183-
}
184-
185-
/**
186-
* This finishes the passed `Span`. If the `Span` has the property `transaction` set and it's bound on the
187-
* current Scope, an `transaction` Event will be sent to Sentry containing all finished Spans inbetween.
188-
* Returns either an `event.id` or `undefined` in case event wasn't sent.
189-
*
190-
* @param span `Span` instance that was created by {@link startSpan}
191-
*/
192-
export function finishSpan(span?: Span): string | undefined {
193-
return callOnHub<string | undefined>('finishSpan', span);
177+
export function startSpan(spanContext?: SpanContext): Span {
178+
return callOnHub<Span>('startSpan', spanContext);
194179
}

0 commit comments

Comments
 (0)