xref: /aosp_15_r20/external/opencensus-java/exporters/trace/elasticsearch/README.md (revision a24ffb47c3166327784aa05b149974e82e8f71b8)
1# OpenCensus Elasticsearch Exporter
2
3The *OpenCensus Elasticsearch trace exporter* is a trace exporter that exports
4data to [Elasticsearch](https://www.elastic.co/products/elasticsearch).
5
6Elasticsearch is a distributed, RESTful search and analytics engine.
7It centrally stores your data so you can discover the expected and uncover the unexpected.
8Using [Kibana](https://www.elastic.co/products/kibana) we can visualize our trace metrics
9with self designed dashboards and easily search as well.
10
11Once the trace is exported to Elasticsearch, you can search traces to find more data on trace.
12
13
14
15## Quickstart
16
17
18### Prerequisites
19
20#### Add the dependencies to your project
21
22For Maven add to your `pom.xml`:
23
24```xml
25<dependencies>
26  <dependency>
27    <groupId>io.opencensus</groupId>
28    <artifactId>opencensus-api</artifactId>
29    <version>0.28.3</version>
30  </dependency>
31  <dependency>
32    <groupId>io.opencensus</groupId>
33    <artifactId>opencensus-exporter-trace-elasticsearch</artifactId>
34    <version>0.28.3</version>
35  </dependency>
36  <dependency>
37    <groupId>io.opencensus</groupId>
38    <artifactId>opencensus-impl</artifactId>
39    <version>0.28.3</version>
40    <scope>runtime</scope>
41  </dependency>
42</dependencies>
43```
44
45For Gradle add to your dependencies:
46
47```groovy
48compile 'io.opencensus:opencensus-api:0.28.3'
49compile 'io.opencensus:opencensus-exporter-trace-elasticsearch:0.28.3'
50runtime 'io.opencensus:opencensus-impl:0.28.3'
51```
52
53#### Register the exporter
54
55The ElasticsearchConfig is the configurations required by the exporter.
56
57```java
58private final static String ELASTIC_SEARCH_URL= "http://localhost:9200";
59private final static String INDEX_FOR_TRACE= "opencensus";
60private final static String TYPE_FOR_TRACE= "trace";
61private final static String APP_NAME= "sample-opencensus";
62
63public static void main(String[] args) throws Exception{
64
65  ElasticsearchTraceConfiguration elasticsearchTraceConfiguration = ElasticsearchTraceConfiguration.builder()
66  .setAppName(MICROSERVICE)
67  .setElasticsearchUrl(ELASTIC_SEARCH_URL)
68  .setElasticsearchIndex(INDEX_FOR_TRACE)
69  .setElasticsearchType(TYPE_FOR_TRACE).build();
70  ElasticsearchTraceExporter.createAndRegister(elasticsearchTraceConfiguration);
71
72}
73```
74
75
76![Sample Traces exported to Elasticsearch](https://raw.githubusercontent.com/malike/distributed-tracing/master/opencensus/distributed_tracing_elk_discover.png?raw=true)
77
78
79#### Java Versions
80
81Java 6 or above is required for using this exporter.
82
83
84