forked from opentracing/opentracing-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in-process propagation resolves opentracing/specification#23
- Loading branch information
1 parent
bc1983e
commit ff879fb
Showing
10 changed files
with
237 additions
and
18 deletions.
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
41 changes: 41 additions & 0 deletions
41
opentracing-api/src/main/java/io/opentracing/SpanManager.java
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright 2016-2017 The OpenTracing 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 | ||
* | ||
* http://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. | ||
*/ | ||
package io.opentracing; | ||
|
||
/** | ||
* @author Pavol Loffay | ||
*/ | ||
public interface SpanManager { | ||
|
||
/** | ||
* @param span span to bundle into visibility | ||
* @return visibility | ||
*/ | ||
Visibility bundle(Span span); | ||
|
||
/** | ||
* @return not finished active span or null | ||
*/ | ||
Visibility active(); | ||
|
||
interface Visibility { | ||
void activate(); | ||
void deactivate(); | ||
|
||
Span span(); | ||
SpanContext context(); | ||
// should be called by span#finish(); | ||
void markAsFinished(); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
opentracing-api/src/main/java/io/opentracing/ThreadLocalSpanManager.java
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Copyright 2016-2017 The OpenTracing 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 | ||
* | ||
* http://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. | ||
*/ | ||
package io.opentracing; | ||
|
||
/** | ||
* @author Pavol Loffay | ||
*/ | ||
public class ThreadLocalSpanManager implements SpanManager { | ||
|
||
private final ThreadLocal<ThreadLocalVisibility> activeContext = new ThreadLocal<ThreadLocalVisibility>(); | ||
|
||
public ThreadLocalSpanManager() {} | ||
|
||
@Override | ||
public Visibility bundle(Span span) { | ||
return span.visibility() == null ? new ThreadLocalVisibility(span) : span.visibility(); | ||
} | ||
|
||
@Override | ||
public Visibility active() { | ||
return activeContext.get() == null ? null : activeContext.get(); | ||
} | ||
|
||
class ThreadLocalVisibility implements Visibility { | ||
private final Span span; | ||
private ThreadLocalVisibility previous; | ||
private boolean finished; | ||
|
||
public ThreadLocalVisibility(Span span) { | ||
this.span = span; | ||
} | ||
|
||
@Override | ||
public Span span() { | ||
return finished ? null : span; | ||
} | ||
|
||
@Override | ||
public SpanContext context() { | ||
return span.context(); | ||
} | ||
|
||
@Override | ||
public void activate() { | ||
previous = activeContext.get(); | ||
activeContext.set(this); | ||
} | ||
|
||
@Override | ||
public void deactivate() { | ||
if (this != activeContext.get()) { | ||
// should not happen | ||
return; | ||
} | ||
activeContext.set(previous); | ||
} | ||
|
||
@Override | ||
public void markAsFinished() { | ||
this.finished = true; | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.