Skip to content

Commit

Permalink
ThreadContextSpan
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldraper committed Mar 6, 2017
1 parent 1bec3ac commit 9fa2b5a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
after_success: |
if [ "$TRAVIS_SECURE_ENV_VARS" == true ]; then
echo "$PGP_SECRET" | base64 --decode | gpg --import
if [ -z "$TRAVIS_TAG" ]; then
sbt publishSigned
else
sbt publishSigned sonatypeRelease
fi
fi
cache:
directories:
- $HOME/.ivy2
- $HOME/.sbt
deploy:
api_key: $GITHUB_AUTH
file: '*/target/**/*.jar'
file_glob: true
on:
tags: true
provider: releases
skip_cleanup: true
git:
depth: 1
jdk: oraclejdk8
language: scala
script:
- '[ "$TRAVIS_PULL_REQUEST" != false ] || export SBT_OPTS=-Dbuild.version=${TRAVIS_TAG:-$TRAVIS_BRANCH-SNAPSHOT}'
- sbt package
26 changes: 26 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
lazy val `thread-context` = project

inScope(Global)(Seq(
autoScalaLibrary := false,
credentials += Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
sys.env.getOrElse("SONATYPE_USERNAME", ""),
sys.env.getOrElse("SONATYPE_PASSWORD", "")
),
crossPaths := false,
developers += Developer("pauldraper", "Paul Draper", "[email protected]", url("https://github.com/pauldraper")),
homepage := Some(url("https://git.lucidchart.com/lucidsoftware/opentracing-thread-context")),
licenses += "Apache 2.0 License" -> url("https://www.apache.org/licenses/LICENSE-2.0"),
organization := "com.lucidchart",
organizationHomepage := Some(url("https://github.com/lucidsoftware")),
organizationName := "Lucid Software",
PgpKeys.pgpPassphrase := Some(Array.emptyCharArray),
resolvers += Resolver.typesafeRepo("releases"),
scmInfo := Some(ScmInfo(
url("https://github.com/lucidsoftware/opentracing-thread-context"),
"scm:git:[email protected]:lucidsoftware/opentracing-thread-context"
)),
startYear := Some(2017),
version := sys.props.getOrElse("build.version", "0-SNAPSHOT")
))
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.13
3 changes: 3 additions & 0 deletions project/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
7 changes: 7 additions & 0 deletions thread-context/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
libraryDependencies ++= Seq(
"com.lucidchart" % "thread-context" % "0.4",
"io.opentracing" % "opentracing-api" % "0.20.7",
"io.opentracing" % "opentracing-noop" % "0.20.7"
)

name := s"opentracing-${name.value}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.opentracing.threadcontext;

import com.github.threadcontext.ThreadContext;
import com.github.threadcontext.ThreadLocalSaver;
import io.opentracing.NoopSpan;
import io.opentracing.Span;
import java.util.function.Supplier;

public final class ThreadContextSpan {

private static final ThreadLocal<Span> span = new ThreadLocal<Span>() {
protected Span initialValue() {
return defaultSpan.get();
}
};
static {
ThreadContext.savers.add(new ThreadLocalSaver<>(span));
}

public static Supplier<Span> defaultSpan = () -> NoopSpan.INSTANCE;

private ThreadContextSpan() {
}

public static Span get() {
return span.get();
}

public static void set(Span span) {
ThreadContextSpan.span.set(span);
}

public static void clear() {
span.remove();
}

}

0 comments on commit 9fa2b5a

Please sign in to comment.