This repository has been archived by the owner on Jul 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 232
After finish, disallow setTag. #467
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,10 @@ public Map<String, Object> getTags() { | |
@Override | ||
public JaegerSpan setOperationName(String operationName) { | ||
synchronized (this) { | ||
if (spanAlreadyFinished("set operation name")) { | ||
return this; | ||
} | ||
|
||
this.operationName = operationName; | ||
} | ||
return this; | ||
|
@@ -132,6 +136,10 @@ public JaegerSpan setBaggageItem(String key, String value) { | |
return this; | ||
} | ||
synchronized (this) { | ||
if (spanAlreadyFinished("set baggage item")) { | ||
return this; | ||
} | ||
|
||
context = tracer.setBaggage(this, key, value); | ||
return this; | ||
} | ||
|
@@ -176,10 +184,10 @@ public void finish(long finishMicros) { | |
|
||
private void finishWithDuration(long durationMicros) { | ||
synchronized (this) { | ||
if (finished) { | ||
log.warn("Span has already been finished; will not be reported again."); | ||
if (spanAlreadyFinished("finish")) { | ||
return; | ||
} | ||
|
||
finished = true; | ||
|
||
this.durationMicroseconds = durationMicros; | ||
|
@@ -206,6 +214,10 @@ public synchronized JaegerSpan setTag(String key, Number value) { | |
} | ||
|
||
private JaegerSpan setTagAsObject(String key, Object value) { | ||
if (spanAlreadyFinished("set tag")) { | ||
return this; | ||
} | ||
|
||
if (key.equals(Tags.SAMPLING_PRIORITY.getKey()) && (value instanceof Number)) { | ||
int priority = ((Number) value).intValue(); | ||
byte newFlags; | ||
|
@@ -233,6 +245,10 @@ public JaegerSpan log(Map<String, ?> fields) { | |
@Override | ||
public JaegerSpan log(long timestampMicroseconds, Map<String, ?> fields) { | ||
synchronized (this) { | ||
if (spanAlreadyFinished("log")) { | ||
return this; | ||
} | ||
|
||
if (fields == null) { | ||
return this; | ||
} | ||
|
@@ -257,6 +273,10 @@ public JaegerSpan log(String event) { | |
@Override | ||
public JaegerSpan log(long timestampMicroseconds, String event) { | ||
synchronized (this) { | ||
if (spanAlreadyFinished("log")) { | ||
return this; | ||
} | ||
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. I suggest to DRY it by moving this to a method
|
||
|
||
if (event == null) { | ||
return this; | ||
} | ||
|
@@ -270,6 +290,18 @@ public JaegerSpan log(long timestampMicroseconds, String event) { | |
} | ||
} | ||
|
||
private boolean spanAlreadyFinished(String methodName) { | ||
if (finished) { | ||
log.warn("Span has already been finished; cannot {}.", methodName); | ||
if (log.isDebugEnabled()) { | ||
log.debug("Generating stack trace because we cannot {}.", methodName, new RuntimeException("Called from:")); | ||
} | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Creates logs related to logged exception | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
strictly speaking setting baggage would work even after the span is finished
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 unlikely that the user would intend to do this, but do you want me to remove it?