PageRenderTime 36ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/sdk/monitor/azure-monitor-opentelemetry-exporter/README.md

http://github.com/WindowsAzure/azure-sdk-for-java
Markdown | 171 lines | 130 code | 41 blank | 0 comment | 0 complexity | 94d336e71c016dc85e214aac21340a02 MD5 | raw file
Possible License(s): MIT
  1. # Azure Monitor OpenTelemetry Exporter client library for Java
  2. This client library provides support for exporting OpenTelemetry data to Azure Monitor. This package assumes your
  3. application is already instrumented with the [OpenTelemetry SDK][opentelemetry_sdk] following the [OpenTelemetry
  4. Specification][opentelemetry_specification].
  5. [Source code][source_code] | [Package (Maven)][package_mvn] | [API reference documentation][api_reference_doc] | [Product Documentation][product_documentation] | [Samples][sample_readme]
  6. ## Getting started
  7. ### Prerequisites
  8. - [Java Development Kit (JDK) with version 8 or above][jdk]
  9. - [Azure Subscription][azure_subscription]
  10. - [Application Insights resource][application_insights_resource]
  11. For more information, please read [introduction to Application Insights][application_insights_intro].
  12. ### Include the Package
  13. [//]: # ({x-version-update-start;com.azure:azure-monitor-opentelemetry-exporter;current})
  14. ```xml
  15. <dependency>
  16. <groupId>com.azure</groupId>
  17. <artifactId>azure-monitor-opentelemetry-exporter</artifactId>
  18. <version>1.0.0-beta.5</version>
  19. </dependency>
  20. ```
  21. [//]: # ({x-version-update-end})
  22. ### Authentication
  23. #### Get the instrumentation key from the portal
  24. In order to export telemetry data to Azure Monitor, you will need the instrumentation key to your [Application
  25. Insights resource][application_insights_resource]. To get your instrumentation key, go to [Azure Portal][azure_portal],
  26. search for your resource. On the overview page of your resource, you will find the instrumentation key in the top
  27. right corner.
  28. ### Creating exporter for Azure Monitor
  29. ```java readme-sample-createExporter
  30. AzureMonitorTraceExporter azureMonitorTraceExporter = new AzureMonitorExporterBuilder()
  31. .connectionString("{connection-string}")
  32. .buildTraceExporter();
  33. ```
  34. #### Exporting span data
  35. The following example shows how to export a trace data to Azure Monitor through the
  36. `AzureMonitorTraceExporter`
  37. ##### Setup OpenTelemetry Tracer to work with Azure Monitor exporter
  38. ```java readme-sample-setupExporter
  39. // Create Azure Monitor exporter and configure OpenTelemetry tracer to use this exporter
  40. // This should be done just once when application starts up
  41. AzureMonitorTraceExporter exporter = new AzureMonitorExporterBuilder()
  42. .connectionString("{connection-string}")
  43. .buildTraceExporter();
  44. SdkTracerProvider tracerProvider = SdkTracerProvider.builder()
  45. .addSpanProcessor(SimpleSpanProcessor.create(exporter))
  46. .build();
  47. OpenTelemetrySdk openTelemetrySdk = OpenTelemetrySdk.builder()
  48. .setTracerProvider(tracerProvider)
  49. .buildAndRegisterGlobal();
  50. Tracer tracer = openTelemetrySdk.getTracer("Sample");
  51. ```
  52. ##### Create spans
  53. ```java readme-sample-createSpans
  54. // Make service calls by adding new parent spans
  55. ConfigurationClient client = new ConfigurationClientBuilder()
  56. .connectionString("{app-config-connection-string}")
  57. .buildClient();
  58. Span span = tracer.spanBuilder("user-parent-span").startSpan();
  59. final Scope scope = span.makeCurrent();
  60. try {
  61. // Thread bound (sync) calls will automatically pick up the parent span and you don't need to pass it explicitly.
  62. client.setConfigurationSetting("hello", "text", "World");
  63. } finally {
  64. span.end();
  65. scope.close();
  66. }
  67. ```
  68. ## Key concepts
  69. Some key concepts for the Azure Monitor exporter include:
  70. * [OpenTelemetry][opentelemetry_spec]: OpenTelemetry is a set of libraries used to collect and export telemetry data
  71. (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior.
  72. * [Instrumentation][instrumentation_library]: The ability to call the OpenTelemetry API directly by any application is
  73. facilitated by instrumentation. A library that enables OpenTelemetry observability for another library is called an Instrumentation Library.
  74. * [Trace][trace_concept]: Trace refers to distributed tracing. It can be thought of as a directed acyclic graph (DAG) of Spans, where the edges between Spans are defined as parent/child relationship.
  75. * [Tracer Provider][tracer_provider]: Provides a `Tracer` for use by the given instrumentation library.
  76. * [Span Processor][span_processor]: A span processor allows hooks for SDK's `Span` start and end method invocations. Follow the link for more information.
  77. * [Sampling][sampler_ref]: Sampling is a mechanism to control the noise and overhead introduced by OpenTelemetry by reducing the number of samples of traces collected and sent to the backend.
  78. For more information on the OpenTelemetry project, please review the [OpenTelemetry Specifications][opentelemetry_specification].
  79. ## Examples
  80. More examples can be found in [samples][samples_code].
  81. ## Troubleshooting
  82. ### Enabling Logging
  83. Azure SDKs for Java offer a consistent logging story to help aid in troubleshooting application errors and expedite
  84. their resolution. The logs produced will capture the flow of an application before reaching the terminal state to help
  85. locate the root issue. View the [logging][logging] wiki for guidance about enabling logging.
  86. ## Next steps
  87. Learn more about [Open Telemetry][opentelemetry_io]
  88. ## Contributing
  89. This project welcomes contributions and suggestions. Most contributions require you to agree to a
  90. [Contributor License Agreement (CLA)][cla] declaring that you have the right to, and actually do, grant us the rights
  91. to use your contribution.
  92. When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate
  93. the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to
  94. do this once across all repos using our CLA.
  95. This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information see the
  96. [Code of Conduct FAQ][coc_faq] or contact [opencode@microsoft.com][coc_contact] with any additional questions or comments.
  97. <!-- LINKS -->
  98. [jdk]: https://docs.microsoft.com/java/azure/jdk/?view=azure-java-stable
  99. [samples]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor
  100. [source_code]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor
  101. [azure_subscription]: https://azure.microsoft.com/free/
  102. [api_reference_doc]: https://docs.microsoft.com/azure/azure-monitor/overview
  103. [package_mvn]: https://mvnrepository.com/artifact/com.azure/opentelemetry-exporters-azuremonitor
  104. [product_documentation]: https://docs.microsoft.com/azure/azure-monitor/overview
  105. [azure_cli]: https://docs.microsoft.com/cli/azure
  106. [azure_portal]: https://portal.azure.com
  107. [azure_identity]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/identity/azure-identity
  108. [DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity/README.md#defaultazurecredential
  109. [custom_subdomain]: https://docs.microsoft.com/azure/cognitive-services/authentication#create-a-resource-with-a-custom-subdomain
  110. [logging]: https://github.com/Azure/azure-sdk-for-java/wiki/Logging-with-Azure-SDK
  111. [opentelemetry_sdk]: https://github.com/open-telemetry/opentelemetry-java/blob/master/QUICKSTART.md
  112. [opentelemetry_specification]: https://github.com/open-telemetry/opentelemetry-specification
  113. [application_insights_resource]: https://docs.microsoft.com/azure/azure-monitor/app/create-new-resource
  114. [application_insights_intro]: https://docs.microsoft.com/azure/azure-monitor/app/app-insights-overview
  115. [azure_portal]: https://ms.portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/microsoft.insights%2Fcomponents
  116. [opentelemetry_io]: https://opentelemetry.io/
  117. [span_data]: https://opentelemetry.lightstep.com/spans
  118. [sample_readme]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/monitor
  119. [opentelemetry_spec]: https://opentelemetry.io/
  120. [instrumentation_library]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#instrumentation-libraries
  121. [tracer_provider]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#tracer-provider
  122. [span_processor]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#span-processor
  123. [sampler_ref]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#sampling
  124. [trace_concept]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/overview.md#trace
  125. [samples_code]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/monitor/azure-monitor-opentelemetry-exporter/src/samples
  126. [cla]: https://cla.microsoft.com
  127. [coc]: https://opensource.microsoft.com/codeofconduct/
  128. [coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
  129. [coc_contact]: mailto:opencode@microsoft.com
  130. ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%monitor%2Fazure-monitor-opentelemetry-exporter%2FREADME.png)