Skip to content
Opencensus trace exporter for AWS X-Ray
Branch: master
Clone or download
Latest commit 2b6005c Apr 20, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.

OpenCensus AWS X-Ray Trace Exporter

The OpenCensus X-Ray Trace Exporter is a trace exporter that exports data to AWS X-Ray.


Hello X-Ray

Add the dependencies to your project

For Gradle add to your dependencies:

buildscript {
    repositories {
        maven { url '' }
    dependencies {

repositories {
    maven { url '' }

dependencies {
    compile 'io.opencensus:opencensus-api:0.19.2'
    compile 'io.opencensus:opencensus-impl:0.19.2'

    compile 'io.opencensus:opencensus-exporter-trace-xray:0.0.3'

Register the exporter

This will export traces to the X-Ray thrift format to the X-Ray instance started previously:

import info.tdoc.exporter.trace.xray.XRayTraceExporter;

public class MyMainClass {
  public static void main(String[] args) throws Exception {
    // ...

HTTP Attribute key

If span has these attribute key and value, this library add AWS X-Ray HTTP Request/Response to generated segment.

  • http.method
  • http.user_agent
  • http.url
  • http.status_code

These are same as this. But some of them can not be converted to AWS X-Ray HTTP Specification. so just dropped.

SQL Attribute key

If span has an attribute with key sql.query, this library automatically create subsegment which has SQL sanitized_query attribute. Then, you can get SQL query with AWS X-Ray web console.

Note: this name is sanitized_query but actually, not sanitized. plese be very careful because anyone who can access to X-Ray web console can read the SQL query.

    tracer.getCurrentSpan().putAttribute("sql.query", AttributeValue.stringAttributeValue(sql));

Java Versions

Java 8 or above is required for using this exporter.


This exporter round down one AWS X-Ray TraceID time part per one minutes in order to create traceable AWS X-Ray TraceID from OpenCensus TraceID among distirbuited nodes. If does not round down, X-Ray TraceIDs are different so X-Ray can not trace requests.

Round down to minutes, a trace will be separeted multiple trace if the requests continues over 59-00 sec. And X-Ray console uses the time part in X-Ray TraceID to show, a trace will not be displayed 1 minutes. This exporter does not chang estart time, so users can know exactily when the trace happend.


Src opensensus span data to X-Ray data.

  • OpenCensus Attribute -> X-Ray annocations
  • Status -> error, exceptions


  • Report errors / exceptions
  • Support http
  • Support SQL
  • Subsegments



Apache License

You can’t perform that action at this time.