From c6a59fbdd201894719979fec218977ec7bf8e8c0 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Tue, 28 Mar 2017 10:57:34 -0700 Subject: Add build rule for examples to generate executable binaries. Fix javadoc errors in examples. (#175) --- .../examples/stats/StatsRunner.java | 91 ++++++++++++++++++++++ .../examples/trace/BasicContextTracing.java | 41 ++++++++++ .../examples/trace/BasicScopedTracing.java | 40 ++++++++++ .../examples/trace/BasicTracing.java | 34 ++++++++ .../examples/trace/MultiSpansContextTracing.java | 55 +++++++++++++ .../examples/trace/MultiSpansScopedTracing.java | 52 +++++++++++++ .../examples/trace/MultiSpansTracing.java | 38 +++++++++ .../google/instrumentation/stats/StatsRunner.java | 85 -------------------- .../instrumentation/trace/BasicContextTracing.java | 39 ---------- .../instrumentation/trace/BasicScopedTracing.java | 38 --------- .../google/instrumentation/trace/BasicTracing.java | 31 -------- .../trace/MultiSpansContextTracing.java | 53 ------------- .../trace/MultiSpansScopedTracing.java | 50 ------------ .../instrumentation/trace/MultiSpansTracing.java | 35 --------- 14 files changed, 351 insertions(+), 331 deletions(-) create mode 100644 examples/src/main/java/com/google/instrumentation/examples/stats/StatsRunner.java create mode 100644 examples/src/main/java/com/google/instrumentation/examples/trace/BasicContextTracing.java create mode 100644 examples/src/main/java/com/google/instrumentation/examples/trace/BasicScopedTracing.java create mode 100644 examples/src/main/java/com/google/instrumentation/examples/trace/BasicTracing.java create mode 100644 examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansContextTracing.java create mode 100644 examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansScopedTracing.java create mode 100644 examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansTracing.java delete mode 100644 examples/src/main/java/com/google/instrumentation/stats/StatsRunner.java delete mode 100644 examples/src/main/java/com/google/instrumentation/trace/BasicContextTracing.java delete mode 100644 examples/src/main/java/com/google/instrumentation/trace/BasicScopedTracing.java delete mode 100644 examples/src/main/java/com/google/instrumentation/trace/BasicTracing.java delete mode 100644 examples/src/main/java/com/google/instrumentation/trace/MultiSpansContextTracing.java delete mode 100644 examples/src/main/java/com/google/instrumentation/trace/MultiSpansScopedTracing.java delete mode 100644 examples/src/main/java/com/google/instrumentation/trace/MultiSpansTracing.java (limited to 'examples/src/main/java') diff --git a/examples/src/main/java/com/google/instrumentation/examples/stats/StatsRunner.java b/examples/src/main/java/com/google/instrumentation/examples/stats/StatsRunner.java new file mode 100644 index 00000000..0641b842 --- /dev/null +++ b/examples/src/main/java/com/google/instrumentation/examples/stats/StatsRunner.java @@ -0,0 +1,91 @@ +/* + * Copyright 2016, Google Inc. + * 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 com.google.instrumentation.examples.stats; + +import com.google.instrumentation.stats.MeasurementDescriptor; +import com.google.instrumentation.stats.MeasurementDescriptor.BasicUnit; +import com.google.instrumentation.stats.MeasurementDescriptor.MeasurementUnit; +import com.google.instrumentation.stats.MeasurementMap; +import com.google.instrumentation.stats.Stats; +import com.google.instrumentation.stats.StatsContext; +import com.google.instrumentation.stats.TagKey; +import com.google.instrumentation.stats.TagValue; +import io.grpc.Context; +import java.util.Arrays; + +/** Simple program that uses Stats contexts. */ +public class StatsRunner { + private static final TagKey K1 = TagKey.create("k1"); + private static final TagKey K2 = TagKey.create("k2"); + private static final TagKey K3 = TagKey.create("k3"); + private static final TagKey K4 = TagKey.create("k4"); + + private static final TagValue V1 = TagValue.create("v1"); + private static final TagValue V2 = TagValue.create("v2"); + private static final TagValue V3 = TagValue.create("v3"); + private static final TagValue V4 = TagValue.create("v4"); + + private static final MeasurementUnit simpleMeasurementUnit = + MeasurementUnit.create(1, Arrays.asList(BasicUnit.SCALAR)); + private static final MeasurementDescriptor M1 = + MeasurementDescriptor.create("m1", "1st test metric", simpleMeasurementUnit); + private static final MeasurementDescriptor M2 = + MeasurementDescriptor.create("m2", "2nd test metric", simpleMeasurementUnit); + + /** Main method. */ + public static void main(String[] args) { + System.out.println("Hello Stats World"); + System.out.println("Default Tags: " + DEFAULT); + System.out.println("Current Tags: " + getCurrentStatsContext()); + Context context1 = withCurrent(DEFAULT.with(K1, V1, K2, V2)); + Context original = context1.attach(); + try { + System.out.println(" Current Tags: " + getCurrentStatsContext()); + System.out.println( + " Current == Default + tags1: " + + getCurrentStatsContext().equals(getStatsContext(context1))); + Context context2 = withCurrent(getCurrentStatsContext().with(K3, V3, K4, V4)); + context2.attach(); + try { + System.out.println(" Current Tags: " + getCurrentStatsContext()); + System.out.println( + " Current == Default + tags1 + tags2: " + + getCurrentStatsContext().equals(getStatsContext(context2))); + getCurrentStatsContext().record(MeasurementMap.of(M1, 0.2, M2, 0.4)); + } finally { + context2.detach(context1); + } + } finally { + context1.detach(original); + } + System.out.println("Current == Default: " + getCurrentStatsContext().equals(DEFAULT)); + } + + private static final StatsContext DEFAULT = Stats.getStatsContextFactory().getDefault(); + + private static final Context.Key STATS_CONTEXT_KEY = + Context.keyWithDefault("StatsContextKey", DEFAULT); + + private static final StatsContext getCurrentStatsContext() { + return getStatsContext(Context.current()); + } + + private static final StatsContext getStatsContext(Context context) { + return STATS_CONTEXT_KEY.get(context); + } + + private static final Context withCurrent(StatsContext context) { + return Context.current().withValue(STATS_CONTEXT_KEY, context); + } +} diff --git a/examples/src/main/java/com/google/instrumentation/examples/trace/BasicContextTracing.java b/examples/src/main/java/com/google/instrumentation/examples/trace/BasicContextTracing.java new file mode 100644 index 00000000..33cdfcc7 --- /dev/null +++ b/examples/src/main/java/com/google/instrumentation/examples/trace/BasicContextTracing.java @@ -0,0 +1,41 @@ +/* + * Copyright 2017, Google Inc. + * 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 com.google.instrumentation.examples.trace; + +import com.google.instrumentation.common.NonThrowingCloseable; +import com.google.instrumentation.trace.Span; +import com.google.instrumentation.trace.Tracer; + +/** + * Example showing how to create a {@link Span}, install it to the current context and add + * annotations. + */ +public final class BasicContextTracing { + // Per class Tracer. + private static final Tracer tracer = Tracer.getTracer(); + + private static void doWork() { + // Add an annotation to the current Span. + tracer.getCurrentSpan().addAnnotation("This is a doWork() annotation."); + } + + /** Main method. */ + public static void main(String[] args) { + Span span = tracer.spanBuilder("MyRootSpan").becomeRoot().startSpan(); + try (NonThrowingCloseable ws = tracer.withSpan(span)) { + doWork(); + } + span.end(); + } +} diff --git a/examples/src/main/java/com/google/instrumentation/examples/trace/BasicScopedTracing.java b/examples/src/main/java/com/google/instrumentation/examples/trace/BasicScopedTracing.java new file mode 100644 index 00000000..ced5a962 --- /dev/null +++ b/examples/src/main/java/com/google/instrumentation/examples/trace/BasicScopedTracing.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017, Google Inc. + * 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 com.google.instrumentation.examples.trace; + +import com.google.instrumentation.common.NonThrowingCloseable; +import com.google.instrumentation.trace.Span; +import com.google.instrumentation.trace.Tracer; + +/** + * Example showing how to create a {@link Span} using scoped Span, install it in the current + * context, and add annotations. + */ +public final class BasicScopedTracing { + // Per class Tracer. + private static final Tracer tracer = Tracer.getTracer(); + + private static void doWork() { + // Add an annotation to the current Span. + tracer.getCurrentSpan().addAnnotation("This is a doWork() annotation."); + } + + /** Main method. */ + public static void main(String[] args) { + try (NonThrowingCloseable ss = + tracer.spanBuilder("MyRootSpan").becomeRoot().startScopedSpan()) { + doWork(); + } + } +} diff --git a/examples/src/main/java/com/google/instrumentation/examples/trace/BasicTracing.java b/examples/src/main/java/com/google/instrumentation/examples/trace/BasicTracing.java new file mode 100644 index 00000000..ef05affa --- /dev/null +++ b/examples/src/main/java/com/google/instrumentation/examples/trace/BasicTracing.java @@ -0,0 +1,34 @@ +/* + * Copyright 2017, Google Inc. + * 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 com.google.instrumentation.examples.trace; + +import com.google.instrumentation.trace.Span; +import com.google.instrumentation.trace.Tracer; + +/** Example showing how to create a {@link Span} and add annotations. */ +public final class BasicTracing { + // Per class Tracer. + private static final Tracer tracer = Tracer.getTracer(); + + private static void doWork() { + Span span = tracer.spanBuilder(null, "MyRootSpan").startSpan(); + span.addAnnotation("This annotation is added directly to the span."); + span.end(); + } + + /** Main method. */ + public static void main(String[] args) { + doWork(); + } +} diff --git a/examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansContextTracing.java b/examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansContextTracing.java new file mode 100644 index 00000000..c68a2e74 --- /dev/null +++ b/examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansContextTracing.java @@ -0,0 +1,55 @@ +/* + * Copyright 2017, Google Inc. + * 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 com.google.instrumentation.examples.trace; + +import com.google.instrumentation.common.NonThrowingCloseable; +import com.google.instrumentation.trace.Span; +import com.google.instrumentation.trace.Tracer; + +/** + * Example showing how to create a child {@link Span}, install it to the current context and add + * annotations. + */ +public final class MultiSpansContextTracing { + // Per class Tracer. + private static final Tracer tracer = Tracer.getTracer(); + + private static void doSomeOtherWork() { + tracer.getCurrentSpan().addAnnotation("Annotation to the child Span"); + } + + private static void doSomeMoreWork() { + // Create a child Span of the current Span. + Span span = tracer.spanBuilder("MyChildSpan").startSpan(); + try (NonThrowingCloseable ws = tracer.withSpan(span)) { + doSomeOtherWork(); + } + span.end(); + } + + private static void doWork() { + tracer.getCurrentSpan().addAnnotation("Annotation to the root Span before child is created."); + doSomeMoreWork(); + tracer.getCurrentSpan().addAnnotation("Annotation to the root Span after child is ended."); + } + + /** Main method. */ + public static void main(String[] args) { + Span span = tracer.spanBuilder("MyRootSpan").becomeRoot().startSpan(); + try (NonThrowingCloseable ws = tracer.withSpan(span)) { + doWork(); + } + span.end(); + } +} diff --git a/examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansScopedTracing.java b/examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansScopedTracing.java new file mode 100644 index 00000000..72ca0feb --- /dev/null +++ b/examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansScopedTracing.java @@ -0,0 +1,52 @@ +/* + * Copyright 2017, Google Inc. + * 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 com.google.instrumentation.examples.trace; + +import com.google.instrumentation.common.NonThrowingCloseable; +import com.google.instrumentation.trace.Span; +import com.google.instrumentation.trace.Tracer; + +/** + * Example showing how to create a child {@link Span} using scoped Spans, install it in the + * current context, and add annotations. + */ +public final class MultiSpansScopedTracing { + // Per class Tracer. + private static final Tracer tracer = Tracer.getTracer(); + + private static void doSomeOtherWork() { + tracer.getCurrentSpan().addAnnotation("Annotation to the child Span"); + } + + private static void doSomeMoreWork() { + // Create a child Span of the current Span. + try (NonThrowingCloseable ss = tracer.spanBuilder("MyChildSpan").startScopedSpan()) { + doSomeOtherWork(); + } + } + + private static void doWork() { + tracer.getCurrentSpan().addAnnotation("Annotation to the root Span before child is created."); + doSomeMoreWork(); + tracer.getCurrentSpan().addAnnotation("Annotation to the root Span after child is ended."); + } + + /** Main method. */ + public static void main(String[] args) { + try (NonThrowingCloseable ss = + tracer.spanBuilder("MyRootSpan").becomeRoot().startScopedSpan()) { + doWork(); + } + } +} diff --git a/examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansTracing.java b/examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansTracing.java new file mode 100644 index 00000000..80d5ba28 --- /dev/null +++ b/examples/src/main/java/com/google/instrumentation/examples/trace/MultiSpansTracing.java @@ -0,0 +1,38 @@ +/* + * Copyright 2017, Google Inc. + * 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 com.google.instrumentation.examples.trace; + +import com.google.instrumentation.trace.Span; +import com.google.instrumentation.trace.Tracer; + +/** Example showing how to directly create a child {@link Span} and add annotations. */ +public final class MultiSpansTracing { + // Per class Tracer. + private static final Tracer tracer = Tracer.getTracer(); + + private static void doWork() { + Span rootSpan = tracer.spanBuilder(null, "MyRootSpan").startSpan(); + rootSpan.addAnnotation("Annotation to the root Span before child is created."); + Span childSpan = tracer.spanBuilder(rootSpan, "MyChildSpan").startSpan(); + childSpan.addAnnotation("Annotation to the child Span"); + childSpan.end(); + rootSpan.addAnnotation("Annotation to the root Span after child is ended."); + rootSpan.end(); + } + + /** Main method. */ + public static void main(String[] args) { + doWork(); + } +} diff --git a/examples/src/main/java/com/google/instrumentation/stats/StatsRunner.java b/examples/src/main/java/com/google/instrumentation/stats/StatsRunner.java deleted file mode 100644 index 0e1e0c2f..00000000 --- a/examples/src/main/java/com/google/instrumentation/stats/StatsRunner.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * 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 com.google.instrumentation.stats; - -import com.google.instrumentation.stats.MeasurementDescriptor.BasicUnit; -import com.google.instrumentation.stats.MeasurementDescriptor.MeasurementUnit; -import io.grpc.Context; -import java.util.Arrays; - -/** Simple program that uses Stats contexts. */ -public class StatsRunner { - private static final TagKey K1 = TagKey.create("k1"); - private static final TagKey K2 = TagKey.create("k2"); - private static final TagKey K3 = TagKey.create("k3"); - private static final TagKey K4 = TagKey.create("k4"); - - private static final TagValue V1 = TagValue.create("v1"); - private static final TagValue V2 = TagValue.create("v2"); - private static final TagValue V3 = TagValue.create("v3"); - private static final TagValue V4 = TagValue.create("v4"); - - private static final MeasurementUnit simpleMeasurementUnit = - MeasurementUnit.create(1, Arrays.asList(BasicUnit.SCALAR)); - private static final MeasurementDescriptor M1 = - MeasurementDescriptor.create("m1", "1st test metric", simpleMeasurementUnit); - private static final MeasurementDescriptor M2 = - MeasurementDescriptor.create("m2", "2nd test metric", simpleMeasurementUnit); - - /** Main method. */ - public static void main(String[] args) { - System.out.println("Hello Stats World"); - System.out.println("Default Tags: " + DEFAULT); - System.out.println("Current Tags: " + getCurrentStatsContext()); - Context context1 = withCurrent(DEFAULT.with(K1, V1, K2, V2)); - Context original = context1.attach(); - try { - System.out.println(" Current Tags: " + getCurrentStatsContext()); - System.out.println( - " Current == Default + tags1: " - + getCurrentStatsContext().equals(getStatsContext(context1))); - Context context2 = withCurrent(getCurrentStatsContext().with(K3, V3, K4, V4)); - context2.attach(); - try { - System.out.println(" Current Tags: " + getCurrentStatsContext()); - System.out.println( - " Current == Default + tags1 + tags2: " - + getCurrentStatsContext().equals(getStatsContext(context2))); - getCurrentStatsContext().record(MeasurementMap.of(M1, 0.2, M2, 0.4)); - } finally { - context2.detach(context1); - } - } finally { - context1.detach(original); - } - System.out.println("Current == Default: " + getCurrentStatsContext().equals(DEFAULT)); - } - - private static final StatsContext DEFAULT = Stats.getStatsContextFactory().getDefault(); - - private static final Context.Key STATS_CONTEXT_KEY = - Context.keyWithDefault("StatsContextKey", DEFAULT); - - private static final StatsContext getCurrentStatsContext() { - return getStatsContext(Context.current()); - } - - private static final StatsContext getStatsContext(Context context) { - return STATS_CONTEXT_KEY.get(context); - } - - private static final Context withCurrent(StatsContext context) { - return Context.current().withValue(STATS_CONTEXT_KEY, context); - } -} diff --git a/examples/src/main/java/com/google/instrumentation/trace/BasicContextTracing.java b/examples/src/main/java/com/google/instrumentation/trace/BasicContextTracing.java deleted file mode 100644 index 1b8b9951..00000000 --- a/examples/src/main/java/com/google/instrumentation/trace/BasicContextTracing.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2017, Google Inc. - * 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 com.google.instrumentation.trace; - -import com.google.instrumentation.common.NonThrowingCloseable; - -/** - * Example showing how to create a {@link Span}, install it to the current context and add - * annotations. - */ -public final class BasicContextTracing { - // Per class Tracer. - private static final Tracer tracer = Tracer.getTracer(); - - private static void doWork() { - // Add an annotation to the current Span. - tracer.getCurrentSpan().addAnnotation("This is a doWork() annotation."); - } - - /** Main method. */ - public static void main(String[] args) { - Span span = tracer.spanBuilder("MyRootSpan").becomeRoot().startSpan(); - try (NonThrowingCloseable ws = tracer.withSpan(span)) { - doWork(); - } - span.end(); - } -} diff --git a/examples/src/main/java/com/google/instrumentation/trace/BasicScopedTracing.java b/examples/src/main/java/com/google/instrumentation/trace/BasicScopedTracing.java deleted file mode 100644 index 17879825..00000000 --- a/examples/src/main/java/com/google/instrumentation/trace/BasicScopedTracing.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2017, Google Inc. - * 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 com.google.instrumentation.trace; - -import com.google.instrumentation.common.NonThrowingCloseable; - -/** - * Example showing how to create a {@link Span} using {@link ScopedSpan}, install it in the current - * context, and add annotations. - */ -public final class BasicScopedTracing { - // Per class Tracer. - private static final Tracer tracer = Tracer.getTracer(); - - private static void doWork() { - // Add an annotation to the current Span. - tracer.getCurrentSpan().addAnnotation("This is a doWork() annotation."); - } - - /** Main method. */ - public static void main(String[] args) { - try (NonThrowingCloseable ss = - tracer.spanBuilder("MyRootSpan").becomeRoot().startScopedSpan()) { - doWork(); - } - } -} diff --git a/examples/src/main/java/com/google/instrumentation/trace/BasicTracing.java b/examples/src/main/java/com/google/instrumentation/trace/BasicTracing.java deleted file mode 100644 index daaf911d..00000000 --- a/examples/src/main/java/com/google/instrumentation/trace/BasicTracing.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2017, Google Inc. - * 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 com.google.instrumentation.trace; - -/** Example showing how to create a {@link Span} and add annotations. */ -public final class BasicTracing { - // Per class Tracer. - private static final Tracer tracer = Tracer.getTracer(); - - private static void doWork() { - Span span = tracer.spanBuilder(null, "MyRootSpan").startSpan(); - span.addAnnotation("This annotation is added directly to the span."); - span.end(); - } - - /** Main method. */ - public static void main(String[] args) { - doWork(); - } -} diff --git a/examples/src/main/java/com/google/instrumentation/trace/MultiSpansContextTracing.java b/examples/src/main/java/com/google/instrumentation/trace/MultiSpansContextTracing.java deleted file mode 100644 index 8b849de3..00000000 --- a/examples/src/main/java/com/google/instrumentation/trace/MultiSpansContextTracing.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2017, Google Inc. - * 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 com.google.instrumentation.trace; - -import com.google.instrumentation.common.NonThrowingCloseable; - -/** - * Example showing how to create a child {@link Span}, install it to the current context and add - * annotations. - */ -public final class MultiSpansContextTracing { - // Per class Tracer. - private static final Tracer tracer = Tracer.getTracer(); - - private static void doSomeOtherWork() { - tracer.getCurrentSpan().addAnnotation("Annotation to the child Span"); - } - - private static void doSomeMoreWork() { - // Create a child Span of the current Span. - Span span = tracer.spanBuilder("MyChildSpan").startSpan(); - try (NonThrowingCloseable ws = tracer.withSpan(span)) { - doSomeOtherWork(); - } - span.end(); - } - - private static void doWork() { - tracer.getCurrentSpan().addAnnotation("Annotation to the root Span before child is created."); - doSomeMoreWork(); - tracer.getCurrentSpan().addAnnotation("Annotation to the root Span after child is ended."); - } - - /** Main method. */ - public static void main(String[] args) { - Span span = tracer.spanBuilder("MyRootSpan").becomeRoot().startSpan(); - try (NonThrowingCloseable ws = tracer.withSpan(span)) { - doWork(); - } - span.end(); - } -} diff --git a/examples/src/main/java/com/google/instrumentation/trace/MultiSpansScopedTracing.java b/examples/src/main/java/com/google/instrumentation/trace/MultiSpansScopedTracing.java deleted file mode 100644 index 457f4a16..00000000 --- a/examples/src/main/java/com/google/instrumentation/trace/MultiSpansScopedTracing.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2017, Google Inc. - * 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 com.google.instrumentation.trace; - -import com.google.instrumentation.common.NonThrowingCloseable; - -/** - * Example showing how to create a child {@link Span} using {@link ScopedSpan}, install it in the - * current context, and add annotations. - */ -public final class MultiSpansScopedTracing { - // Per class Tracer. - private static final Tracer tracer = Tracer.getTracer(); - - private static void doSomeOtherWork() { - tracer.getCurrentSpan().addAnnotation("Annotation to the child Span"); - } - - private static void doSomeMoreWork() { - // Create a child Span of the current Span. - try (NonThrowingCloseable ss = tracer.spanBuilder("MyChildSpan").startScopedSpan()) { - doSomeOtherWork(); - } - } - - private static void doWork() { - tracer.getCurrentSpan().addAnnotation("Annotation to the root Span before child is created."); - doSomeMoreWork(); - tracer.getCurrentSpan().addAnnotation("Annotation to the root Span after child is ended."); - } - - /** Main method. */ - public static void main(String[] args) { - try (NonThrowingCloseable ss = - tracer.spanBuilder("MyRootSpan").becomeRoot().startScopedSpan()) { - doWork(); - } - } -} diff --git a/examples/src/main/java/com/google/instrumentation/trace/MultiSpansTracing.java b/examples/src/main/java/com/google/instrumentation/trace/MultiSpansTracing.java deleted file mode 100644 index fcc74125..00000000 --- a/examples/src/main/java/com/google/instrumentation/trace/MultiSpansTracing.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2017, Google Inc. - * 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 com.google.instrumentation.trace; - -/** Example showing how to directly create a child {@link Span} and add annotations. */ -public final class MultiSpansTracing { - // Per class Tracer. - private static final Tracer tracer = Tracer.getTracer(); - - private static void doWork() { - Span rootSpan = tracer.spanBuilder(null, "MyRootSpan").startSpan(); - rootSpan.addAnnotation("Annotation to the root Span before child is created."); - Span childSpan = tracer.spanBuilder(rootSpan, "MyChildSpan").startSpan(); - childSpan.addAnnotation("Annotation to the child Span"); - childSpan.end(); - rootSpan.addAnnotation("Annotation to the root Span after child is ended."); - rootSpan.end(); - } - - /** Main method. */ - public static void main(String[] args) { - doWork(); - } -} -- cgit v1.2.3