aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/spring/README.md
blob: 4e2ad8f27536dd478a153b8116184788f09525e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# spring
[![Build Status][travis-image]][travis-url]
[![Windows Build Status][appveyor-image]][appveyor-url]
[![Maven Central][maven-image]][maven-url]

Provides annotation support for projects that use Spring.  

## Quickstart

### Add the dependencies to your project.

For Maven add to your `pom.xml`:
```xml
<dependencies>
  <!-- census -->
  <dependency>
    <groupId>io.opencensus</groupId>
    <artifactId>opencensus-api</artifactId>
    <version>0.15.0</version>
  </dependency>
  <dependency>
    <groupId>io.opencensus</groupId>
    <artifactId>opencensus-contrib-spring</artifactId>
    <version>0.15.0</version>
  </dependency>
  <dependency>
    <groupId>io.opencensus</groupId>
    <artifactId>opencensus-impl</artifactId>
    <version>0.15.0</version>
    <scope>runtime</scope>
  </dependency>
  
  <!-- spring aspects -->
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>SPRING_VERSION</version>
    <scope>runtime</scope>
  </dependency>
  
</dependencies>
```

For Gradle add to your dependencies:
```gradle
compile 'io.opencensus:opencensus-api:0.15.0'
compile 'io.opencensus:opencensus-contrib-spring:0.15.0'
runtime 'io.opencensus:opencensus-impl:0.15.0'
runtime 'org.springframework:spring-aspects:SPRING_VERSION'
```

### Configure Spring

To configure annotation support within Spring, include the following with your
spring xml configuration.

```xml
  <!-- Enable @AspectJ annotation support  -->
  <aop:aspectj-autoproxy/>

  <!-- traces explicit calls to @Traced -->
  <bean id="censusAspect" class="io.opencensus.contrib.spring.aop.CensusSpringAspect"/>

  <!-- traces all SQL calls -->
  <bean id="censusSQLAspect" class="io.opencensus.contrib.spring.aop.CensusSpringSQLAspect"/>
```

### Usage 

Once configured, you can use the `@Traced` annotation to indicate that a method should be traces.

```java
  @Traced()
  void example1() {
    // do work
  }
  
  // a custom span name can also be provided to @Traced
  @Traced(name = "custom-span-name")
  void example2() {
    // do moar work
  }
```

#### Notes

Spring support only enables annotations.  You'll still need to configure opencensus and register exporters / views.

[travis-image]: https://travis-ci.org/census-instrumentation/opencensus-java.svg?branch=master
[travis-url]: https://travis-ci.org/census-instrumentation/opencensus-java
[appveyor-image]: https://ci.appveyor.com/api/projects/status/hxthmpkxar4jq4be/branch/master?svg=true
[appveyor-url]: https://ci.appveyor.com/project/opencensusjavateam/opencensus-java/branch/master
[maven-image]: https://maven-badges.herokuapp.com/maven-central/io.opencensus/opencensus-contrib-spring/badge.svg
[maven-url]: https://maven-badges.herokuapp.com/maven-central/io.opencensus/opencensus-contrib-spring