This repository was archived by the owner on Dec 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 12 files changed +174
-8
lines changed
api/src/main/java/io/opencensus/trace/propagation
main/java/io/opencensus/contrib/http/util
test/java/io/opencensus/contrib/http/util
main/java/io/opencensus/implcore/trace/propagation
test/java/io/opencensus/implcore/trace/propagation Expand file tree Collapse file tree 12 files changed +174
-8
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ def subprojects = [
2020 project(' :opencensus-contrib-agent' ),
2121 project(' :opencensus-contrib-grpc-util' ),
2222 project(' :opencensus-contrib-grpc-metrics' ),
23+ project(' :opencensus-contrib-http-util' ),
2324 project(' :opencensus-contrib-zpages' ),
2425 project(' :opencensus-exporter-trace-logging' ),
2526 project(' :opencensus-exporter-trace-stackdriver' ),
@@ -35,6 +36,7 @@ def subprojects_javadoc = [
3536 project(' :opencensus-contrib-agent' ),
3637 project(' :opencensus-contrib-grpc-util' ),
3738 project(' :opencensus-contrib-grpc-metrics' ),
39+ project(' :opencensus-contrib-http-util' ),
3840 project(' :opencensus-contrib-zpages' ),
3941 project(' :opencensus-exporter-trace-logging' ),
4042 project(' :opencensus-exporter-trace-stackdriver' ),
Original file line number Diff line number Diff line change 1818
1919/**
2020 * Container class for all the supported propagation formats. Currently supports only Binary format
21- * see {@link BinaryFormat} but more formats will be added.
21+ * (see {@link BinaryFormat}) and B3 Text format (see {@link TextFormat}) but more formats will be
22+ * added.
2223 */
2324public abstract class PropagationComponent {
2425 private static final PropagationComponent NOOP_PROPAGATION_COMPONENT =
@@ -32,6 +33,16 @@ public abstract class PropagationComponent {
3233 */
3334 public abstract BinaryFormat getBinaryFormat ();
3435
36+ /**
37+ * Returns the B3 {@link TextFormat} with the provided implementations. See <a
38+ * href="https://github.com/openzipkin/b3-propagation">b3-propagation</a> for more information. If
39+ * no implementation is provided then no-op implementation will be used.
40+ *
41+ * @since 0.11.0
42+ * @return the B3 {@code TextFormat} implementation for B3.
43+ */
44+ public abstract TextFormat getB3Format ();
45+
3546 /**
3647 * Returns an instance that contains no-op implementations for all the instances.
3748 *
@@ -46,5 +57,10 @@ private static final class NoopPropagationComponent extends PropagationComponent
4657 public BinaryFormat getBinaryFormat () {
4758 return BinaryFormat .getNoopBinaryFormat ();
4859 }
60+
61+ @ Override
62+ public TextFormat getB3Format () {
63+ return TextFormat .getNoopTextFormat ();
64+ }
4965 }
5066}
Original file line number Diff line number Diff line change @@ -320,6 +320,7 @@ subprojects {
320320 ' opencensus-contrib-agent' ,
321321 ' opencensus-contrib-grpc-metrics' ,
322322 ' opencensus-contrib-grpc-util' ,
323+ ' opencensus-contrib-http-util' ,
323324 ' opencensus-contrib-zpages' ,
324325 ' opencensus-exporter-stats-signalfx' ,
325326 ' opencensus-exporter-stats-stackdriver' ,
Original file line number Diff line number Diff line change 1+ # OpenCensus HTTP Util
2+ [ ![ Build Status] [ travis-image ]] [ travis-url ]
3+ [ ![ Windows Build Status] [ appveyor-image ]] [ appveyor-url ]
4+ [ ![ Maven Central] [ maven-image ]] [ maven-url ]
5+
6+ The * OpenCensus HTTP Util for Java* is a collection of utilities for trace instrumentation when
7+ working with HTTP.
8+
9+ ## Quickstart
10+
11+ ### Add the dependencies to your project
12+
13+ For Maven add to your ` pom.xml ` :
14+ ``` xml
15+ <dependencies >
16+ <dependency >
17+ <groupId >io.opencensus</groupId >
18+ <artifactId >opencensus-api</artifactId >
19+ <version >0.11.0</version >
20+ </dependency >
21+ <dependency >
22+ <groupId >io.opencensus</groupId >
23+ <artifactId >opencensus-contrib-http-util</artifactId >
24+ <version >0.11.0</version >
25+ </dependency >
26+ </dependencies >
27+ ```
28+
29+ For Gradle add to your dependencies:
30+ ``` gradle
31+ compile 'io.opencensus:opencensus-api:0.11.0'
32+ compile 'io.opencensus:opencensus-contrib-http-util:0.11.0'
33+ ```
34+
35+ [ travis-image ] : https://travis-ci.org/census-instrumentation/opencensus-java.svg?branch=master
36+ [ travis-url ] : https://travis-ci.org/census-instrumentation/opencensus-java
37+ [ appveyor-image ] : https://ci.appveyor.com/api/projects/status/hxthmpkxar4jq4be/branch/master?svg=true
38+ [ appveyor-url ] : https://ci.appveyor.com/project/opencensusjavateam/opencensus-java/branch/master
39+ [ maven-image ] : https://maven-badges.herokuapp.com/maven-central/io.opencensus/opencensus-contrib-grpc-util/badge.svg
40+ [ maven-url ] : https://maven-badges.herokuapp.com/maven-central/io.opencensus/opencensus-contrib-grpc-util
41+ [ grpc-url ] : https://github.com/grpc/grpc-java
Original file line number Diff line number Diff line change 1+ description = ' OpenCensus HTTP Util'
2+
3+ apply plugin : ' java'
4+
5+ [compileJava, compileTestJava]. each() {
6+ it. sourceCompatibility = 1.6
7+ it. targetCompatibility = 1.6
8+ }
9+
10+ dependencies {
11+ compile project(' :opencensus-api' ),
12+ libraries. guava
13+
14+ signature " org.codehaus.mojo.signature:java16:+@signature"
15+ }
Original file line number Diff line number Diff line change 1414 * limitations under the License.
1515 */
1616
17- package io .opencensus .implcore . trace . propagation ;
17+ package io .opencensus .contrib . http . util ;
1818
1919import static com .google .common .base .Preconditions .checkArgument ;
2020import static com .google .common .base .Preconditions .checkNotNull ;
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2018, OpenCensus Authors
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package io .opencensus .contrib .http .util ;
18+
19+ import io .opencensus .trace .propagation .TextFormat ;
20+
21+ /**
22+ * Utility class to get all supported {@link TextFormat}.
23+ *
24+ * @since 0.11.0
25+ */
26+ public class HttpPropagationUtil {
27+
28+ private HttpPropagationUtil () {}
29+
30+ /**
31+ * Returns the Stack Driver format implementation. The header specification for this format is
32+ * "X-Cloud-Trace-Context: <TRACE_ID>/<SPAN_ID>[;o=<TRACE_TRUE>]". See this <a
33+ * href="https://cloud.google.com/trace/docs/support">page</a> for more information.
34+ *
35+ * @since 0.11.0
36+ * @return the Stack Driver format.
37+ */
38+ public static TextFormat getCloudTraceFormat () {
39+ return new CloudTraceFormat ();
40+ }
41+ }
Original file line number Diff line number Diff line change 1414 * limitations under the License.
1515 */
1616
17- package io .opencensus .implcore . trace . propagation ;
17+ package io .opencensus .contrib . http . util ;
1818
1919import static com .google .common .truth .Truth .assertThat ;
20- import static io .opencensus .implcore . trace . propagation .CloudTraceFormat .HEADER_NAME ;
21- import static io .opencensus .implcore . trace . propagation .CloudTraceFormat .NOT_SAMPLED ;
22- import static io .opencensus .implcore . trace . propagation .CloudTraceFormat .SAMPLED ;
23- import static io .opencensus .implcore . trace . propagation .CloudTraceFormat .SPAN_ID_DELIMITER ;
24- import static io .opencensus .implcore . trace . propagation .CloudTraceFormat .TRACE_OPTION_DELIMITER ;
20+ import static io .opencensus .contrib . http . util .CloudTraceFormat .HEADER_NAME ;
21+ import static io .opencensus .contrib . http . util .CloudTraceFormat .NOT_SAMPLED ;
22+ import static io .opencensus .contrib . http . util .CloudTraceFormat .SAMPLED ;
23+ import static io .opencensus .contrib . http . util .CloudTraceFormat .SPAN_ID_DELIMITER ;
24+ import static io .opencensus .contrib . http . util .CloudTraceFormat .TRACE_OPTION_DELIMITER ;
2525
2626import com .google .common .primitives .UnsignedLong ;
2727import io .opencensus .trace .SpanContext ;
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2018, OpenCensus Authors
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package io .opencensus .contrib .http .util ;
18+
19+ import static com .google .common .truth .Truth .assertThat ;
20+
21+ import io .opencensus .trace .propagation .TextFormat ;
22+ import org .junit .Test ;
23+ import org .junit .runner .RunWith ;
24+ import org .junit .runners .JUnit4 ;
25+
26+ /** Unit tests for {@link HttpPropagationUtil}. */
27+ @ RunWith (JUnit4 .class )
28+ public class HttpPropagationUtilTest {
29+
30+ @ Test
31+ public void cloudTraceFormatNotNull () {
32+ TextFormat cloudTraceFormat = HttpPropagationUtil .getCloudTraceFormat ();
33+ assertThat (cloudTraceFormat ).isNotNull ();
34+ assertThat (cloudTraceFormat ).isInstanceOf (CloudTraceFormat .class );
35+ }
36+ }
Original file line number Diff line number Diff line change 1818
1919import io .opencensus .trace .propagation .BinaryFormat ;
2020import io .opencensus .trace .propagation .PropagationComponent ;
21+ import io .opencensus .trace .propagation .TextFormat ;
2122
2223/** Implementation of the {@link PropagationComponent}. */
2324public class PropagationComponentImpl extends PropagationComponent {
2425 private final BinaryFormat binaryFormat = new BinaryFormatImpl ();
26+ private final B3Format b3Format = new B3Format ();
2527
2628 @ Override
2729 public BinaryFormat getBinaryFormat () {
2830 return binaryFormat ;
2931 }
32+
33+ @ Override
34+ public TextFormat getB3Format () {
35+ return b3Format ;
36+ }
3037}
You can’t perform that action at this time.
0 commit comments