Skip to content

Commit

Permalink
feat(sdk): expose span.cancel method
Browse files Browse the repository at this point in the history
Customer code can already call span.end() (for example, after calling
span.disableAutoEnd() earlier), but so far could not cancel the span in
progress. We should expose for consistency and completeness sake.
  • Loading branch information
basti1302 committed Apr 28, 2022
1 parent 9d576c5 commit d60571f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/core/src/tracing/cls.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function init(config, _processIdentityProvider) {
* @property {Function} [freezePathTemplate]
* @property {Function} [disableAutoEnd]
* @property {Function} [transmitManual]
* @property {Function} [cancel]
*/

class InstanaSpan {
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/tracing/spanHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ SpanHandle.prototype.disableAutoEnd = function disableAutoEnd() {
};

/**
* Finishes as span that has been switched to manual-end-mode before.
* Finishes a span that has been switched to manual-end-mode before.
* @param {boolean | number} errorCount
*/
SpanHandle.prototype.end = function end(errorCount) {
Expand All @@ -181,6 +181,13 @@ SpanHandle.prototype.end = function end(errorCount) {
this.span.transmitManual();
};

/**
* Cancels as span that has been switched to manual-end-mode before.
*/
SpanHandle.prototype.cancel = function cancel() {
this.span.cancel();
};

/**
* TODO: make it as a class
* Provides noop operation for the SpanHandle API when automatic tracing is not enabled or no span is currently active.
Expand Down Expand Up @@ -249,6 +256,10 @@ NoopSpanHandle.prototype.end = function end() {
// provide dummy operation when automatic tracing is not enabled
};

NoopSpanHandle.prototype.cancel = function cancel() {
// provide dummy operation when automatic tracing is not enabled
};

/**
* @param {import ('./cls')} cls
* @returns {SpanHandle | NoopSpanHandle}
Expand Down

0 comments on commit d60571f

Please sign in to comment.