LogDrop
Backend TracingJava

Custom Spans

Add spans for business operations with the optional LogDrop API library.

Most services need no code: the agent traces incoming requests and calls to databases, caches, brokers and other services on its own. For business operations you want to see as their own step in a trace, add the optional io.logdrop:logdrop-api library.

Add the library

The library is published in LogDrop's Maven repository. Use io.logdrop:logdrop-api-coroutines as well for Kotlin coroutines.

build.gradle.kts
repositories { maven("https://artifactory.logdrop.io/repository/logdrop-java/") }
dependencies { implementation("io.logdrop:logdrop-api:0.1.0-alpha5") }
pom.xml
<repository><id>logdrop</id><url>https://artifactory.logdrop.io/repository/logdrop-java/</url></repository>
<dependency><groupId>io.logdrop</groupId><artifactId>logdrop-api</artifactId><version>0.1.0-alpha5</version></dependency>

The library runs on Java 8 and later. Every file is signed; see Verify what you install.

Add a span

A custom span is a span your own code starts and ends, around an operation the agent cannot see on its own. Wrap the operation in inSpan and give the span a name:

String total = LogDrop.tracing().inSpan("checkout.price", span -> {
    span.attribute("order.type", "delivery");   // custom keys need LOGDROP_ALLOWED_ATTRIBUTE_KEYS=order.type
    return pricing.total(order);
});

inSpan makes the span current while your code runs, so the calls inside it (database, HTTP, messaging) appear under it in the same trace. It always ends the span, and records the exception class when your code throws. withSpan does the same for work without a result.

With Kotlin coroutines, use inSpanSuspend from logdrop-api-coroutines; it keeps the span current across suspension and ends it on success, failure or cancellation:

import io.logdrop.api.coroutines.inSpanSuspend

val total = LogDrop.tracing().inSpanSuspend("checkout.price") { span ->
    span.attribute("order.type", "delivery")
    pricing.total(order)
}

Attributes and events

Attributes are key-value details that you add to a span, such as order.type. Events mark something that happened while the span ran.

  • A custom attribute is sent only when its key is listed in LOGDROP_ALLOWED_ATTRIBUTE_KEYS (comma-separated, at most 128 keys). A key starts with a letter and has at most 128 letters, digits, _, . or -.
  • Keys that contain authorization, cookie, token, secret, password, credential, api_key, apikey or api-key are always dropped, even when listed.
  • Values are strings, whole numbers, decimals or booleans. Text is cut to LOGDROP_MAX_STRING_LENGTH characters (256 by default).
  • Use constant event names, without request or user data.
  • recordException records only the exception class, never its message, stack trace or cause.

Other calls

Besides spans, the library has calls that work with the running agent: send pending spans now, read the export counters, switch the ingest key, or check that the agent is attached.

CallWhat it does
LogDrop.flush(Duration)Sends the spans that ended before the call, for example before a batch job exits. false when it did not finish in time, an export failed, or no agent is attached. The timeout is at most 60 seconds
LogDrop.exportStatus()Counts of exported, failed, rejected (refused as invalid, or dropped before sending because LogDrop would refuse them), pending, refused (over the active-span limit) and active spans, and whether the agent is attached
LogDrop.updateIngestCredential(String)Uses this key for later requests, without a restart, until the key file changes again
LogDrop.isAgentAttached()Whether the LogDrop Java agent runs in this JVM

Without the agent

The library sends nothing to LogDrop by itself. Without the agent, flush returns false, exportStatus() reports that no agent is attached, and updateIngestCredential throws IllegalStateException. Spans you start are not sent to LogDrop.

On this page