Tracing and Metrics

Having observability and telemetry is at the core of any production ready service. GraphJin has built-in support for OpenCensus for tracing requests all the way from HTTP to the database and providing all kinds of metrics.

OpenCensus has a concept called exporters these are external services that can consume this data and make to give you graphs, charts, alerting etc. GraphJin again has built-in support for Zipkin, Prometheus, Google Stackdriver and the AWS X-Ray exporters.

Telemetry config

The telemetry section of the standard config files is where you set values to configure this feature to your needs.

  debug: true
  interval: 5s
    exporter: "prometheus"
    endpoint: ""
    namespace: "web api"
    key: "1234xyz"
    exporter: "zipkin"
    endpoint: "http://zipkin:9411/api/v2/spans"
    sample: 0.2
    include_query: false
    include_params: false
    exclude_health_check: false

debug: Enabling debug enables an embedded web ui to test and debug tracing and metrics. This UI called zPages is provided by OpenCensus and will be made available on the /telemetry path. For more information on using zPages Remeber to disable this in production.

interval: This controls the interval setting for OpenCensus metrics collection. This deafaults to 5 seconds if not set.

metric.exporters Setting this enables metrics collection. The supported values for this field are prometheus and stackdriver. The Prometheus exporter requires metric.namespace to be set. The Sackdriver exporter requires the metric.key to be set to the Google Cloud Project ID.

metric.endpoint Is not currently used by any of the exporters.

tracing.exporter Setting this enables request tracing. The supported values for this field are zipkin, aws and xray. Zipkin requires tracing.endpoint to be set. AWS and Xray are the same and do not require any addiitonal settings.

tracing.sample This controls what percentage of the requests should be traced. By default 0.5 or 50% of the requests are traced, always is also a valid value for this field and it means all requests will be traced.

include_query Include the GraphJin SQL query to the trace. Be careful with this setting in production it will add the entire SQL query to the trace. This can be veru useful to debug slow requests.

include_params Include the GraphJin SQL query parameters to the trace. Be careful with this setting in production it will it can potentially leak sensitive user information into tracing logs.

exclude_health_check Exclude health check data from the trace. Health checking is frequent and traces collected for health endpoints can be noisy and expensive.

Using Zipkin

Zipkin is a really great open source request tracing project. It’s easy to add to your current GraphJin app as a way to test tracing in development. Add the following to the GraphJin generated docker-compose.yml file. Also add zipkin in your current apps depends_on list. Once setup the Zipkin UI is available at http://localhost:9411

      - db
      - zipkin

    image: openzipkin/zipkin-slim
    container_name: zipkin
    # Environment settings are defined here
      - STORAGE_TYPE=mem
      # Uncomment to enable self-tracing
      # Uncomment to enable debug logging
      # - JAVA_OPTS=-Dorg.slf4j.simpleLogger.log.zipkin2=debug
      # Port used for the Zipkin UI and HTTP Api
      - 9411:9411

Zipkin HTTP to DB traces

Zipkin trace details