diff --git a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml
index ea9a06eb9129..154e4abd37d1 100755
--- a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml
+++ b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml
@@ -76,8 +76,9 @@
-
-
+
+
+
@@ -126,8 +127,8 @@
-
-
+
+
diff --git a/pom.client.xml b/pom.client.xml
index 0b5f53afb627..33d80bc2a03d 100644
--- a/pom.client.xml
+++ b/pom.client.xml
@@ -423,7 +423,8 @@
Azure Telemetry
- com.azure.tracing.opentelemetry*
+ Azure Telemetry - OpenCensus
+ com.azure.core.tracing*
@@ -868,6 +869,6 @@
sdk/storage/azure-storage-file-datalakesdk/storage/azure-storage-queuesdk/storage/azure-storage-queue-cryptography
- sdk/tracing/tracing-opentelemetry
+ sdk/tracing/azure-core-tracing-opencensus
diff --git a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/TracerProvider.java b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/TracerProvider.java
index 81695b067341..f21db781778d 100644
--- a/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/TracerProvider.java
+++ b/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/TracerProvider.java
@@ -2,8 +2,6 @@
// Licensed under the MIT License.
package com.azure.core.amqp.implementation;
-import static com.azure.core.util.tracing.Tracer.OPENTELEMETRY_SPAN_KEY;
-
import com.azure.core.amqp.exception.AmqpException;
import com.azure.core.implementation.tracing.ProcessKind;
import com.azure.core.util.Context;
@@ -14,6 +12,8 @@
import java.util.Objects;
import reactor.core.publisher.Signal;
+import static com.azure.core.util.tracing.Tracer.OPENCENSUS_SPAN_KEY;
+
public class TracerProvider {
private final ClientLogger logger = new ClientLogger(TracerProvider.class);
private final List tracers = new ArrayList<>();
@@ -62,7 +62,7 @@ public void endSpan(Context context, Signal signal) {
Objects.requireNonNull(signal, "'signal' cannot be null");
// Get the context that was added to the mono, this will contain the information needed to end the span.
- if (!context.getData(OPENTELEMETRY_SPAN_KEY).isPresent()) {
+ if (!context.getData(OPENCENSUS_SPAN_KEY).isPresent()) {
return;
}
diff --git a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/implementation/TracerProviderTest.java b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/implementation/TracerProviderTest.java
index 188c1530e38a..c9be69a8a9db 100644
--- a/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/implementation/TracerProviderTest.java
+++ b/sdk/core/azure-core-amqp/src/test/java/com/azure/core/amqp/implementation/TracerProviderTest.java
@@ -22,7 +22,7 @@
import java.util.List;
import java.util.Optional;
-import static com.azure.core.util.tracing.Tracer.OPENTELEMETRY_SPAN_KEY;
+import static com.azure.core.util.tracing.Tracer.OPENCENSUS_SPAN_KEY;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
@@ -114,7 +114,7 @@ public void startSpanReturnsUpdatedContext() {
@Test
public void endSpanSuccess() {
// Act
- tracerProvider.endSpan(new Context(OPENTELEMETRY_SPAN_KEY, "value"), Signal.complete());
+ tracerProvider.endSpan(new Context(OPENCENSUS_SPAN_KEY, "value"), Signal.complete());
// Assert
for (Tracer t : tracers) {
@@ -137,7 +137,7 @@ public void endSpanNoKey() {
public void endSpanError() {
// Arrange
Throwable testThrow = new Throwable("testError");
- Context sendContext = new Context(OPENTELEMETRY_SPAN_KEY, "value");
+ Context sendContext = new Context(OPENCENSUS_SPAN_KEY, "value");
// Act
tracerProvider.endSpan(sendContext, Signal.error(testThrow));
@@ -152,7 +152,7 @@ public void endSpanError() {
public void endSpanOnSubscribe() {
// Arrange
Throwable testThrow = new Throwable("testError");
- Context sendContext = new Context(OPENTELEMETRY_SPAN_KEY, "value");
+ Context sendContext = new Context(OPENCENSUS_SPAN_KEY, "value");
// Act
tracerProvider.endSpan(sendContext, Signal.error(testThrow));
@@ -168,7 +168,7 @@ public void endSpanAmqpException() {
// Arrange
final ErrorCondition errorCondition = ErrorCondition.NOT_FOUND;
final Exception exception = new AmqpException(true, errorCondition, "", null);
- Context sendContext = new Context(OPENTELEMETRY_SPAN_KEY, "value");
+ Context sendContext = new Context(OPENCENSUS_SPAN_KEY, "value");
// Act
tracerProvider.endSpan(sendContext, Signal.error(exception));
diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/util/tracing/Tracer.java b/sdk/core/azure-core/src/main/java/com/azure/core/util/tracing/Tracer.java
index eb978487f12e..96e3c19ef41d 100644
--- a/sdk/core/azure-core/src/main/java/com/azure/core/util/tracing/Tracer.java
+++ b/sdk/core/azure-core/src/main/java/com/azure/core/util/tracing/Tracer.java
@@ -11,21 +11,21 @@
*/
public interface Tracer {
/**
- * Key for {@link Context} which indicates that the context contains OpenTelemetry span data. This span will be used
+ * Key for {@link Context} which indicates that the context contains OpenCensus span data. This span will be used
* as the parent span for all spans the SDK creates.
*
* If no span data is listed when the SDK creates its first span it will be used as the parent for all further spans
* it creates.
*/
- String OPENTELEMETRY_SPAN_KEY = "opentelemetry-span";
+ String OPENCENSUS_SPAN_KEY = "opencensus-span";
/**
- * Key for {@link Context} which indicates that the context contains the name for the OpenTelemetry spans that are
+ * Key for {@link Context} which indicates that the context contains the name for the OpenCensus spans that are
* created.
*
* If no span name is listed when the span is created it will default to using the calling method's name.
*/
- String OPENTELEMETRY_SPAN_NAME_KEY = "opentelemetry-span-name";
+ String OPENCENSUS_SPAN_NAME_KEY = "opencensus-span-name";
/**
* Key for {@link Context} which indicates that the context contains the Entity Path, remote endpoint path.
diff --git a/sdk/core/azure-core/src/main/java/module-info.java b/sdk/core/azure-core/src/main/java/module-info.java
index 0b6d1d43f75b..fa29c322ba1d 100644
--- a/sdk/core/azure-core/src/main/java/module-info.java
+++ b/sdk/core/azure-core/src/main/java/module-info.java
@@ -91,9 +91,10 @@
com.azure.storage.file, // FIXME this should not be a long-term solution
com.azure.storage.queue; // FIXME this should not be a long-term solution
exports com.azure.core.implementation.util to
+ com.azure.core.amqp, // FIXME this should not be a long-term solution
com.azure.core.management, // FIXME this should not be a long-term solution
com.azure.core.test, // FIXME this should not be a long-term solution
- com.azure.core.amqp, // FIXME this should not be a long-term solution
+ com.azure.core.tracing.opencensus, // FIXME this should not be a long-term solution
com.azure.data.appconfiguration, // FIXME this should not be a long-term solution
com.azure.http.netty, // FIXME this should not be a long-term solution
com.azure.messaging.eventhubs, // FIXME this should not be a long-term solution
@@ -103,7 +104,6 @@
com.azure.security.keyvault.keys, // FIXME this should not be a long-term solution
com.azure.security.keyvault.secrets, // FIXME this should not be a long-term solution
com.azure.storage.common, // FIXME this should not be a long-term solution
- com.azure.tracing.opentelemetry, // FIXME this should not be a long-term solution
com.azure.storage.blob, // FIXME this should not be a long-term solution
com.azure.storage.file, // FIXME this should not be a long-term solution
com.azure.storage.queue; // FIXME this should not be a long-term solution
@@ -118,7 +118,7 @@
com.azure.security.keyvault.keys, // FIXME this should not be a long-term solution
com.azure.security.keyvault.secrets, // FIXME this should not be a long-term solution
com.azure.storage.common, // FIXME this should not be a long-term solution
- com.azure.tracing.opentelemetry, // FIXME this should not be a long-term solution
+ com.azure.core.tracing.opencensus, // FIXME this should not be a long-term solution
com.azure.storage.blob, // FIXME this should not be a long-term solution
com.azure.storage.file, // FIXME this should not be a long-term solution
com.azure.storage.queue; // FIXME this should not be a long-term solution
@@ -133,7 +133,7 @@
com.azure.security.keyvault.keys, // FIXME this should not be a long-term solution
com.azure.security.keyvault.secrets, // FIXME this should not be a long-term solution
com.azure.storage.common, // FIXME this should not be a long-term solution
- com.azure.tracing.opentelemetry, // FIXME this should not be a long-term solution
+ com.azure.core.tracing.opencensus, // FIXME this should not be a long-term solution
com.azure.storage.blob, // FIXME this should not be a long-term solution
com.azure.storage.file, // FIXME this should not be a long-term solution
com.azure.storage.queue;
diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubAsyncProducerTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubAsyncProducerTest.java
index e061cb6c1488..3e685cc0f5ff 100644
--- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubAsyncProducerTest.java
+++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubAsyncProducerTest.java
@@ -36,7 +36,7 @@
import java.util.List;
import static com.azure.core.util.tracing.Tracer.DIAGNOSTIC_ID_KEY;
-import static com.azure.core.util.tracing.Tracer.OPENTELEMETRY_SPAN_KEY;
+import static com.azure.core.util.tracing.Tracer.OPENCENSUS_SPAN_KEY;
import static com.azure.core.util.tracing.Tracer.SPAN_CONTEXT;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.ArgumentMatchers.any;
@@ -196,14 +196,14 @@ public void sendStartSpanSingleMessage() {
when(tracer1.start(eq("Azure.eventhubs.send"), any(), eq(ProcessKind.SEND))).thenAnswer(
invocation -> {
Context passed = invocation.getArgument(1, Context.class);
- return passed.addData(OPENTELEMETRY_SPAN_KEY, "value");
+ return passed.addData(OPENCENSUS_SPAN_KEY, "value");
}
);
when(tracer1.start(eq("Azure.eventhubs.message"), any(), eq(ProcessKind.RECEIVE))).thenAnswer(
invocation -> {
Context passed = invocation.getArgument(1, Context.class);
- return passed.addData(OPENTELEMETRY_SPAN_KEY, "value").addData(DIAGNOSTIC_ID_KEY, "value2");
+ return passed.addData(OPENCENSUS_SPAN_KEY, "value").addData(DIAGNOSTIC_ID_KEY, "value2");
}
);
@@ -243,7 +243,7 @@ public void sendMessageAddlink() {
when(tracer1.start(eq("Azure.eventhubs.send"), any(), eq(ProcessKind.SEND))).thenAnswer(
invocation -> {
Context passed = invocation.getArgument(1, Context.class);
- return passed.addData(OPENTELEMETRY_SPAN_KEY, "value");
+ return passed.addData(OPENCENSUS_SPAN_KEY, "value");
}
);
diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerTest.java
index e3e7a83b9bc4..6297f34fba7d 100644
--- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerTest.java
+++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerTest.java
@@ -37,7 +37,7 @@
import java.util.List;
import static com.azure.core.util.tracing.Tracer.DIAGNOSTIC_ID_KEY;
-import static com.azure.core.util.tracing.Tracer.OPENTELEMETRY_SPAN_KEY;
+import static com.azure.core.util.tracing.Tracer.OPENCENSUS_SPAN_KEY;
import static com.azure.core.util.tracing.Tracer.SPAN_CONTEXT;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.ArgumentMatchers.any;
@@ -126,14 +126,14 @@ public void sendStartSpanSingleMessage() {
when(tracer1.start(eq("Azure.eventhubs.send"), any(), eq(ProcessKind.SEND))).thenAnswer(
invocation -> {
Context passed = invocation.getArgument(1, Context.class);
- return passed.addData(OPENTELEMETRY_SPAN_KEY, "value");
+ return passed.addData(OPENCENSUS_SPAN_KEY, "value");
}
);
when(tracer1.start(eq("Azure.eventhubs.message"), any(), eq(ProcessKind.RECEIVE))).thenAnswer(
invocation -> {
Context passed = invocation.getArgument(1, Context.class);
- return passed.addData(OPENTELEMETRY_SPAN_KEY, "value").addData(DIAGNOSTIC_ID_KEY, "value2");
+ return passed.addData(OPENCENSUS_SPAN_KEY, "value").addData(DIAGNOSTIC_ID_KEY, "value2");
}
);
//Act
@@ -166,7 +166,7 @@ public void sendMessageAddlink() {
when(tracer1.start(eq("Azure.eventhubs.send"), any(), eq(ProcessKind.SEND))).thenAnswer(
invocation -> {
Context passed = invocation.getArgument(1, Context.class);
- return passed.addData(OPENTELEMETRY_SPAN_KEY, "value");
+ return passed.addData(OPENCENSUS_SPAN_KEY, "value");
}
);
diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventProcessorTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventProcessorTest.java
index 8fc1daa81d7c..576992d7b826 100644
--- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventProcessorTest.java
+++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventProcessorTest.java
@@ -4,7 +4,7 @@
package com.azure.messaging.eventhubs;
import static com.azure.core.util.tracing.Tracer.DIAGNOSTIC_ID_KEY;
-import static com.azure.core.util.tracing.Tracer.OPENTELEMETRY_SPAN_KEY;
+import static com.azure.core.util.tracing.Tracer.OPENCENSUS_SPAN_KEY;
import static com.azure.core.util.tracing.Tracer.SPAN_CONTEXT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -217,7 +217,7 @@ public void testErrorProcessSpans() throws Exception {
return passed.addData(SPAN_CONTEXT, "value1")
.addData("scope", (Closeable) () -> {
})
- .addData(OPENTELEMETRY_SPAN_KEY, "value2");
+ .addData(OPENCENSUS_SPAN_KEY, "value2");
}
);
@@ -274,7 +274,7 @@ public void testProcessSpans() throws Exception {
Context passed = invocation.getArgument(1, Context.class);
return passed.addData(SPAN_CONTEXT, "value1").addData("scope", (Closeable) () -> {
return;
- }).addData(OPENTELEMETRY_SPAN_KEY, "value2");
+ }).addData(OPENCENSUS_SPAN_KEY, "value2");
}
);
diff --git a/sdk/tracing/README.md b/sdk/tracing/README.md
deleted file mode 100644
index 9676eba059f7..000000000000
--- a/sdk/tracing/README.md
+++ /dev/null
@@ -1,21 +0,0 @@
-# Azure Tracing client library for Java
-This package contains the OpenTelemetry tracing plugin for Azure SDK Java libraries.
-
-## Getting started
-
-## Key concepts
-
-## Examples
-
-## Troubleshooting
-
-## Next steps
-
-## Contributing
-This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
-
-When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
-
-This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
-
-
\ No newline at end of file
diff --git a/sdk/tracing/tracing-opentelemetry/CHANGELOG.md b/sdk/tracing/azure-core-tracing-opencensus/CHANGELOG.md
similarity index 100%
rename from sdk/tracing/tracing-opentelemetry/CHANGELOG.md
rename to sdk/tracing/azure-core-tracing-opencensus/CHANGELOG.md
diff --git a/sdk/tracing/azure-core-tracing-opencensus/README.md b/sdk/tracing/azure-core-tracing-opencensus/README.md
new file mode 100644
index 000000000000..cc38f69cd7df
--- /dev/null
+++ b/sdk/tracing/azure-core-tracing-opencensus/README.md
@@ -0,0 +1,228 @@
+# Azure Tracing client library for Java
+This package enables distributed tracing across Azure SDK Java libraries through [Opencensus][opencensus]. OpenCensus is an open source, vendor-agnostic, single distribution of libraries to provide metrics collection and distributed tracing for services.
+The Azure core tracing package provides:
+- Context propagation, in order to correlate activities and requests between services with an initial customer action.
+- Tracing user requests to the system, allowing to pinpoint failures and performance issues.
+
+[Source code][source_code] | [API reference documentation][api_documentation] | [Product
+documentation][api_documentation] | [Samples][samples]
+
+## Getting started
+### Prerequisites
+- Java Development Kit (JDK) with version 8 or above
+- [Maven][maven]
+```xml
+
+ io.opencensus
+ opencensus-api
+ 0.21.0
+
+
+
+ io.opencensus
+ opencensus-impl
+ 0.21.0
+
+```
+
+### Adding the package to your product
+```xml
+
+ com.azure
+ azure-core-tracing-opencensus
+ 1.0.0-preview.3
+
+```
+
+### Default HTTP Client
+All client libraries support a pluggable HTTP transport layer. Users can specify an HTTP client specific for their needs by including the following dependency in the Maven pom.xml file:
+
+```xml
+
+ com.azure
+ azure-core-http-netty
+ 1.0.0-preview.4
+
+```
+
+This will automatically configure all client libraries on the same classpath to make use of Netty for the HTTP client. Netty is the recommended HTTP client for most applications. OkHttp is recommended only when the application being built is deployed to Android devices.
+
+If, instead of Netty it is preferable to use OkHTTP, there is a HTTP client available for that too. Simply include the following dependency instead:
+
+```xml
+
+ com.azure
+ azure-core-http-okhttp
+ 1.0.0-preview.4
+
+```
+
+### Configuring HTTP clients
+When an HTTP client is included on the classpath, as shown above, it is not necessary to specify it in the client library [builders][create-eventhubs-builders], unless you want to customize the HTTP client in some fashion. If this is desired, the `httpClient` builder method is often available to achieve just this, by allowing users to provide a custom (or customized) `com.azure.core.http.HttpClient` instances.
+
+For starters, by having the Netty or OkHTTP dependencies on your classpath, as shown above, you can create new instances of these `HttpClient` types using their builder APIs. For example, here is how you would create a Netty HttpClient instance:
+
+```java
+HttpClient client = new NettyAsyncHttpClientBuilder()
+ .port(8080)
+ .wiretap(true)
+ .build();
+```
+
+## Key concepts
+### Trace
+A trace is a tree of spans showing the path of work through a system. A trace on its own is distinguishable by a unique 16 byte sequence called a TraceID.
+### Span
+A span represents a single operation in a trace. A span could be representative of an HTTP request, a remote procedure call (RPC), a database query, or even the path that a code takes.
+
+## Examples
+The following sections provides examples of using the azure-core-tracing-opencensus plugin with some of the Azure Java SDK libraries:
+### Using the plugin package with HTTP client libraries
+- Sync create a secret using [azure-keyvault-secrets][azure-keyvault-secrets] with tracing enabled.
+
+ Users can additionally pass the value of the current tracing span to the SDKs using key **"opencensus-span"** on the [Context][context] parameter of the calling method:
+ ```java
+ import com.azure.identity.credential.DefaultAzureCredentialBuilder;
+ import com.azure.security.keyvault.secrets.SecretClientBuilder;
+ import com.azure.security.keyvault.secrets.SecretClient;
+ import com.azure.security.keyvault.secrets.models.Secret;
+ import io.opencensus.common.Scope;
+ import io.opencensus.trace.Tracer;
+ import io.opencensus.trace.Tracing;
+ import com.azure.core.util.Context;
+
+ import static com.azure.core.implementation.tracing.Tracer.OPENCENSUS_SPAN_KEY;
+
+ SecretClient client = new SecretClientBuilder()
+ .endpoint("")
+ .credential(new DefaultAzureCredentialBuilder().build())
+ .buildClient();
+
+ Tracer tracer = Tracing.getTracer();
+
+ try (Scope scope = tracer.spanBuilder("tracing-user-span").startScopedSpan()) {
+
+ // Create context with key "opencensus-span" and current tracing span as value
+ Context tracingContext = new Context(OPENCENSUS_SPAN_KEY, tracer.getCurrentSpan());
+
+ // Set secret and pass tracing context to pass the user-span to calling methods
+ Secret secret = secretClient.setSecretWithResponse(new Secret("secret_name", "secret_value", tracingContext));
+ System.out.printf("Secret is created with name %s and value %s %n", secret.getName(), secret.getValue());
+ }
+ ```
+- Async create a secret using [azure-keyvault-secrets][azure-keyvault-secrets] with tracing enabled.
+
+ To enabled tracing in async clients, users can additionally pass the value of the current tracing span to the SDKs using key **"opencensus-span"** on the subscriberContext of the calling method:
+ ```java
+ import com.azure.identity.credential.DefaultAzureCredentialBuilder;
+ import com.azure.security.keyvault.secrets.SecretClientBuilder;
+ import com.azure.security.keyvault.secrets.SecretAsyncClient;
+ import com.azure.security.keyvault.secrets.models.Secret;
+ import io.opencensus.common.Scope;
+ import io.opencensus.trace.Tracer;
+ import io.opencensus.trace.Tracing;
+ import com.azure.core.util.Context;
+
+ import static com.azure.core.implementation.tracing.Tracer.OPENCENSUS_SPAN_KEY;
+
+ SecretAsyncClient secretAsyncClient = new SecretClientBuilder()
+ .endpoint("")
+ .credential(new DefaultAzureCredentialBuilder().build())
+ .buildClient();
+
+ Tracer tracer = Tracing.getTracer();
+
+ Scope scope = tracer.spanBuilder("tracing-user-span").startScopedSpan())
+ // Set secret and pass tracing context with method call
+ secretAsyncClient.setSecret(new Secret("secret_name", "secret_value")
+ .subscriberContext(Context.of(OPENCENSUS_SPAN_KEY, tracer.getCurrentSpan()).doFinally(secret ->
+ System.out.printf("Secret is created with name %s and value %s %n", secret.getName(), secret.getValue()));
+ scope.close();
+ ```
+
+### Using the plugin package with AMQP client libraries
+Async send single event using [azure-messaging-eventhubs][azure-messaging-eventhubs] with tracing.
+
+Users can additionally pass the value of the current tracing span to the EventData object with key **"opencensus-span"** on the [Context][context] object:
+
+```java
+import io.opencensus.common.Scope;
+import io.opencensus.trace.Tracer;
+import io.opencensus.trace.Tracing;
+import com.azure.core.util.Context;
+import com.azure.messaging.eventhubs.EventData;
+import com.azure.messaging.eventhubs.EventHubAsyncClient;
+import com.azure.messaging.eventhubs.EventHubAsyncProducer;
+import com.azure.messaging.eventhubs.EventHubClientBuilder;
+
+EventHubAsyncClient client = new EventHubClientBuilder()
+ .connectionString("<< CONNECTION STRING FOR SPECIFIC EVENT HUB INSTANCE >>")
+ .buildAsyncClient();
+EventHubAsyncProducer producer = client.createProducer();
+
+Scope scope = tracer.spanBuilder("tracing-user-span").startScopedSpan())
+Context tracingContext = new Context(OPENCENSUS_SPAN_KEY, tracer.getCurrentSpan());
+// Create an event to send
+final EventData eventData = new EventData("Hello world!".getBytes(UTF_8));
+// Add tracing context to the event
+eventData.context(tracingContext);
+producer.send(eventData).doFinally((ignored) -> System.out.println("Event sent."));
+scope.close();
+```
+
+## Troubleshooting
+### General
+
+For more information on Opencensus Java support for tracing, see [Opencensus Java Quickstart][opencensus-quickstart].
+
+Please refer to the [Quickstart Zipkin][zipkin-quickstart] for more documentation on using a Zipkin exporter.
+
+## Next steps
+### Samples
+Several Java SDK samples are available to you in the SDKs GitHub repository.
+These following samples provide example code for additional scenarios commonly encountered while working with Tracing:
+
+#### Enqueue and dequeue messages using Storage Queue client
+* [HelloWorld.java][sample_helloWorld] and [HelloWorldAsync.java][sample_helloWorldAsync] - Contains samples for following scenarios with tracing support:
+ * Create a Queue client using [azure-storage-queue][azure-storage-queue] Java SDK.
+ * Enqueue and dequeue messages using the created Queue client.
+#### List Operations for secrets in a Key Vault
+* [ListOperations.java][sample_list] and [ListOperationsAsync.java][sample_list_async] - Contains samples for following scenarios with tracing support:
+ * Create a secret.
+ * List secrets.
+ * Create new version of an existing secret.
+ * List versions of an existing secret.
+#### Publish multiple Events to an Event Hub
+* [PublishEvents.java][sample_publish_events] - Contains sample for publishing multiple events with tracing support.
+
+### Additional Documentation
+For more extensive documentation on OpenCensus, see the [API reference documentation][opencensus].
+
+## Contributing
+This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
+
+When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
+
+This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
+
+
+[api_documentation]: https://azure.github.io/azure-sdk-for-java/track2reports/index.html
+[azure-keyvault-secrets]: ../keyvault/azure-keyvault-secrets
+[azure-messaging-eventhubs]: ../eventhubs/azure-messaging-eventhubs
+[azure-storage-queue]: ../storage/azure-storage-queue
+[context]: ../core/azure-core/src/main/java/com/azure/core/util/Context.java
+[create-eventhubs-builders]: ../eventhubs/azure-messaging-eventhubs#create-an-event-hub-client-using-a-connection-string
+[maven]: https://maven.apache.org/
+[source_code]: src
+[api_documentation]: https://aka.ms/java-docs
+[sample_helloWorld]: ./src/samples/java/com/azure/core/tracing//HelloWorld.java
+[sample_helloWorldAsync]: ./src/samples/java/com/azure/core/tracing/HelloWorldAsync.java
+[sample_list]: ./src/samples/java/com/azure/core/tracing//ListOperationsTracing.java
+[sample_list_async]: ./src/samples/java/com/azure/core/tracing//ListOperationsAsync.java
+[sample_publish_events]: ./src/samples/java/com/azure/core/tracing/PublishEvents.java
+[samples]: ./src/samples/java/com/azure/core/tracing/
+[opencensus]: https://opencensus.io/quickstart/java/tracing/
+[opencensus-quickstart]: https://opencensus.io/quickstart/java/tracing/
+[zipkin-quickstart]: https://zipkin.io/pages/quickstart
+
+
diff --git a/sdk/tracing/azure-core-tracing-opencensus/pom.xml b/sdk/tracing/azure-core-tracing-opencensus/pom.xml
new file mode 100644
index 000000000000..5642787fc404
--- /dev/null
+++ b/sdk/tracing/azure-core-tracing-opencensus/pom.xml
@@ -0,0 +1,76 @@
+
+
+ 4.0.0
+
+ com.azure
+ azure-client-sdk-parent
+ 1.4.0
+ ../../../pom.client.xml
+
+
+ com.azure
+ azure-core-tracing-opencensus
+ 1.0.0-preview.3
+
+ Microsoft Azure OpenCensus tracing plugin
+ This package contains the OpenCensus tracing plugin for Azure client libraries.
+ https://github.com/Azure/azure-sdk-for-java
+
+
+
+ azure-java-build-docs
+ ${site.url}/site/${project.artifactId}
+
+
+
+
+ scm:git:https://github.com/Azure/azure-sdk-for-java
+ scm:git:git@github.com:Azure/azure-sdk-for-java.git
+ HEAD
+
+
+
+
+ com.azure
+ azure-core
+ 1.0.0-preview.5
+
+
+ io.opencensus
+ opencensus-api
+
+
+
+ io.opencensus
+ opencensus-exporter-trace-zipkin
+ 0.20.0
+ test
+
+
+ com.azure
+ azure-storage-queue
+ 12.0.0-preview.4
+ test
+
+
+ com.azure
+ azure-keyvault-secrets
+ 4.0.0-preview.4
+ test
+
+
+ com.azure
+ azure-identity
+ 1.0.0-preview.4
+ test
+
+
+ com.azure
+ azure-messaging-eventhubs
+ 5.0.0-preview.4
+ test
+
+
+
diff --git a/sdk/tracing/tracing-opentelemetry/src/main/java/com/azure/tracing/opentelemetry/OpenTelemetryHttpPolicy.java b/sdk/tracing/azure-core-tracing-opencensus/src/main/java/com/azure/core/tracing/opencensus/OpenCensusHttpPolicy.java
similarity index 89%
rename from sdk/tracing/tracing-opentelemetry/src/main/java/com/azure/tracing/opentelemetry/OpenTelemetryHttpPolicy.java
rename to sdk/tracing/azure-core-tracing-opencensus/src/main/java/com/azure/core/tracing/opencensus/OpenCensusHttpPolicy.java
index 2d2ae1ebf25a..97228999a03e 100644
--- a/sdk/tracing/tracing-opentelemetry/src/main/java/com/azure/tracing/opentelemetry/OpenTelemetryHttpPolicy.java
+++ b/sdk/tracing/azure-core-tracing-opencensus/src/main/java/com/azure/core/tracing/opencensus/OpenCensusHttpPolicy.java
@@ -1,17 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-package com.azure.tracing.opentelemetry;
+package com.azure.core.tracing.opencensus;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.HttpPipelineCallContext;
import com.azure.core.http.HttpPipelineNextPolicy;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
-import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.AfterRetryPolicyProvider;
+import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.implementation.util.ImplUtils;
-import com.azure.tracing.opentelemetry.implementation.HttpTraceUtil;
+import com.azure.core.tracing.opencensus.implementation.HttpTraceUtil;
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.Span;
import io.opencensus.trace.Span.Kind;
@@ -27,22 +27,22 @@
import java.util.Optional;
+import static com.azure.core.util.tracing.Tracer.OPENCENSUS_SPAN_KEY;
+
/**
- * Pipeline policy that creates an OpenTelemetry span which traces the service request.
+ * Pipeline policy that creates an OpenCensus span which traces the service request.
*/
-public class OpenTelemetryHttpPolicy implements AfterRetryPolicyProvider, HttpPipelinePolicy {
+public class OpenCensusHttpPolicy implements AfterRetryPolicyProvider, HttpPipelinePolicy {
/**
- * @return a OpenTelemetry HTTP policy.
+ * @return a OpenCensus HTTP policy.
*/
public HttpPipelinePolicy create() {
return this;
}
- // Singleton OpenTelemetry tracer capable of starting and exporting spans.
+ // Singleton OpenCensus tracer capable of starting and exporting spans.
private static final Tracer TRACER = Tracing.getTracer();
- private static final String OPENTELEMETRY_SPAN_KEY =
- com.azure.core.util.tracing.Tracer.OPENTELEMETRY_SPAN_KEY;
// standard attributes with http call information
private static final String HTTP_USER_AGENT = "http.user_agent";
@@ -57,7 +57,7 @@ public HttpPipelinePolicy create() {
@Override
public Mono process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
- Span parentSpan = (Span) context.getData(OPENTELEMETRY_SPAN_KEY).orElse(TRACER.getCurrentSpan());
+ Span parentSpan = (Span) context.getData(OPENCENSUS_SPAN_KEY).orElse(TRACER.getCurrentSpan());
HttpRequest request = context.getHttpRequest();
// Build new child span representing this outgoing request.
@@ -82,7 +82,7 @@ public Mono process(HttpPipelineCallContext context, HttpPipelineN
// run the next policy and handle success and error
return next.process()
- .doOnEach(OpenTelemetryHttpPolicy::handleResponse)
+ .doOnEach(OpenCensusHttpPolicy::handleResponse)
.subscriberContext(Context.of("TRACING_SPAN", span, "REQUEST", request));
}
@@ -162,7 +162,7 @@ private static void spanEnd(Span span, HttpResponse response, Throwable error) {
private final TextFormat.Setter contextSetter = new TextFormat.Setter() {
@Override
public void put(HttpRequest request, String key, String value) {
- request.setHeader(key, value);
+ request.getHeaders().put(key, value);
}
};
}
diff --git a/sdk/tracing/tracing-opentelemetry/src/main/java/com/azure/tracing/opentelemetry/OpenTelemetryTracer.java b/sdk/tracing/azure-core-tracing-opencensus/src/main/java/com/azure/core/tracing/opencensus/OpenCensusTracer.java
similarity index 80%
rename from sdk/tracing/tracing-opentelemetry/src/main/java/com/azure/tracing/opentelemetry/OpenTelemetryTracer.java
rename to sdk/tracing/azure-core-tracing-opencensus/src/main/java/com/azure/core/tracing/opencensus/OpenCensusTracer.java
index 564499d464fe..63a186ced860 100644
--- a/sdk/tracing/tracing-opentelemetry/src/main/java/com/azure/tracing/opentelemetry/OpenTelemetryTracer.java
+++ b/sdk/tracing/azure-core-tracing-opencensus/src/main/java/com/azure/core/tracing/opencensus/OpenCensusTracer.java
@@ -1,15 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-package com.azure.tracing.opentelemetry;
+package com.azure.core.tracing.opencensus;
import com.azure.core.implementation.tracing.ProcessKind;
import com.azure.core.implementation.util.ImplUtils;
+import com.azure.core.tracing.opencensus.implementation.AmqpPropagationFormatUtil;
+import com.azure.core.tracing.opencensus.implementation.AmqpTraceUtil;
+import com.azure.core.tracing.opencensus.implementation.HttpTraceUtil;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
-import com.azure.tracing.opentelemetry.implementation.AmqpPropagationFormatUtil;
-import com.azure.tracing.opentelemetry.implementation.AmqpTraceUtil;
-import com.azure.tracing.opentelemetry.implementation.HttpTraceUtil;
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.Link;
import io.opencensus.trace.Span;
@@ -19,16 +19,15 @@
import io.opencensus.trace.Tracer;
import io.opencensus.trace.Tracing;
-import java.util.Locale;
import java.util.Optional;
import static io.opencensus.trace.Link.Type.PARENT_LINKED_SPAN;
/**
- * OpenTelemetry span
+ * OpenCensus span
*/
-public class OpenTelemetryTracer implements com.azure.core.util.tracing.Tracer {
- // Singleton OpenTelemetry tracer capable of starting and exporting spans.
+public class OpenCensusTracer implements com.azure.core.util.tracing.Tracer {
+ // Singleton OpenCensus tracer capable of starting and exporting spans.
private static final Tracer TRACER = Tracing.getTracer();
// standard attributes with AMQP call information
@@ -36,17 +35,17 @@ public class OpenTelemetryTracer implements com.azure.core.util.tracing.Tracer {
private static final String MESSAGE_BUS_DESTINATION = "message_bus.destination";
private static final String PEER_ENDPOINT = "peer.address";
- private final ClientLogger logger = new ClientLogger(OpenTelemetryTracer.class);
+ private final ClientLogger logger = new ClientLogger(OpenCensusTracer.class);
@Override
public Context start(String methodName, Context context) {
- Span parentSpan = (Span) context.getData(OPENTELEMETRY_SPAN_KEY).orElse(TRACER.getCurrentSpan());
- String spanName = (String) context.getData(OPENTELEMETRY_SPAN_NAME_KEY).orElse(methodName);
+ Span parentSpan = (Span) context.getData(OPENCENSUS_SPAN_KEY).orElse(TRACER.getCurrentSpan());
+ String spanName = (String) context.getData(OPENCENSUS_SPAN_NAME_KEY).orElse(methodName);
SpanBuilder spanBuilder = TRACER.spanBuilderWithExplicitParent(spanName, parentSpan);
Span span = spanBuilder.startSpan();
- return context.addData(OPENTELEMETRY_SPAN_KEY, span);
+ return context.addData(OPENCENSUS_SPAN_KEY, span);
}
@Override
@@ -61,13 +60,13 @@ public Context start(String spanName, Context context, ProcessKind processKind)
// If span is sampled in, add additional TRACING attributes
addSpanRequestAttributes(span, context, spanName);
}
- return context.addData(OPENTELEMETRY_SPAN_KEY, span);
+ return context.addData(OPENCENSUS_SPAN_KEY, span);
case RECEIVE:
spanBuilder = startSpanWithExplicitParent(spanName, context);
span = spanBuilder.startSpan();
// Add diagnostic Id to Context
context = setContextData(span);
- return context.addData(OPENTELEMETRY_SPAN_KEY, span);
+ return context.addData(OPENCENSUS_SPAN_KEY, span);
case PROCESS:
return startScopedSpan(spanName, context);
default:
@@ -106,7 +105,7 @@ public void setAttribute(String key, String value, Context context) {
@Override
public Context setSpanName(String spanName, Context context) {
- return context.addData(OPENTELEMETRY_SPAN_NAME_KEY, spanName);
+ return context.addData(OPENCENSUS_SPAN_NAME_KEY, spanName);
}
@Override
@@ -163,22 +162,29 @@ private Context startScopedSpan(String spanName, Context context) {
SpanBuilder spanBuilder = startSpanWithExplicitParent(spanName, context);
span = spanBuilder.setSpanKind(Span.Kind.SERVER).startSpan();
}
- return context.addData(OPENTELEMETRY_SPAN_KEY, span).addData("scope", TRACER.withSpan(span));
+ return context.addData(OPENCENSUS_SPAN_KEY, span).addData("scope", TRACER.withSpan(span));
}
private SpanBuilder startSpanWithExplicitParent(String spanName, Context context) {
- Optional