Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capture code stacktrace #184

Merged
merged 22 commits into from
Jan 11, 2024
Merged

capture code stacktrace #184

merged 22 commits into from
Jan 11, 2024

Conversation

SylvainJuge
Copy link
Member

@SylvainJuge SylvainJuge commented Nov 20, 2023

Fixes #22
Fixes #177

Tested manually when combined with:

Sample JSON span document captured when testing manually
{
  "_index": ".ds-traces-apm-default-2023.11.23-000001",
  "_id": "Beec_IsBlEx8DpqSNsdT",
  "_version": 1,
  "_score": 0,
  "_source": {
    "parent": {
      "id": "999b27462a952621"
    },
    "agent": {
      "name": "opentelemetry/java",
      "version": "1.30.1"
    },
    "process": {
      "pid": 1071606,
      "executable": "/home/sylvain/.sdkman/candidates/java/17.0.8-tem/bin/java"
    },
    "code": {
      "stacktrace": "java.lang.Throwable\n\tat co.elastic.otel.ElasticSpanProcessor.captureStackTrace(ElasticSpanProcessor.java:81)\n\tat co.elastic.otel.ElasticSpanProcessor.onEnd(ElasticSpanProcessor.java:56)\n\tat io.opentelemetry.sdk.trace.MultiSpanProcessor.onEnd(MultiSpanProcessor.java:52)\n\tat io.opentelemetry.sdk.trace.SdkSpan.endInternal(SdkSpan.java:451)\n\tat io.opentelemetry.sdk.trace.SdkSpan.end(SdkSpan.java:431)\n\tat io.opentelemetry.javaagent.instrumentation.opentelemetryapi.trace.ApplicationSpan.end(ApplicationSpan.java:140)\n\tat co.elastic.apm.opbeans.controllers.APIRestController.orders(APIRestController.java:140)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:568)\n\tat org.springframework.web.method.support.InvocableHandlerM"
    },
    "processor": {
      "event": "span"
    },
    "labels": {
      "process_runtime_description": "Eclipse Adoptium OpenJDK 64-Bit Server VM 17.0.8+7",
      "elastic_span_local_root_id": "8e80b8c8b8a749f6",
      "agentdev_worktree": "span-stack",
      "elastic_span_is_local_root": "false",
      "thread_name": "http-nio-8080-exec-3",
      "agentdev_agent_type": "elastic-otel",
      "telemetry_auto_version": "elastic-0.0.1-SNAPSHOT-otel-1.30.0",
      "process_command_args": [
        "/home/sylvain/.sdkman/candidates/java/17.0.8-tem/bin/java",
        "-javaagent:/home/sylvain/dev/elastic-otel-java_span-stack/agent/build/libs/elastic-otel-javaagent-0.0.1-SNAPSHOT.jar",
        "-jar",
        "./target/opbeans-0.0.1-SNAPSHOT.jar"
      ]
    },
    "observer": {
      "hostname": "apm-server-apm-server-5bccdfb694-5qsg2",
      "type": "apm-server",
      "version": "8.12.0"
    },
    "trace": {
      "id": "a323e1ee1efb4b792b96d37f6960fcf0"
    },
    "@timestamp": "2023-11-23T14:36:11.772Z",
    "data_stream": {
      "namespace": "default",
      "type": "traces",
      "dataset": "apm"
    },
    "numeric_labels": {
      "thread_id": 50,
      "elastic_span_self_time": 4026320
    },
    "service": {
      "node": {
        "name": "sylvain-elastic"
      },
      "environment": "sylvain-test",
      "name": "opbeans-elastic-otel",
      "runtime": {
        "name": "OpenJDK Runtime Environment",
        "version": "17.0.8+7"
      },
      "language": {
        "name": "java"
      },
      "version": "1.0"
    },
    "host": {
      "hostname": "sylvain-elastic",
      "os": {
        "type": "linux",
        "platform": "linux",
        "full": "Linux 6.5.0-13-generic"
      },
      "name": "sylvain-elastic",
      "architecture": "amd64"
    },
    "event": {
      "agent_id_status": "missing",
      "ingested": "2023-11-23T14:36:17Z",
      "outcome": "unknown"
    },
    "span": {
      "duration": {
        "us": 191140
      },
      "representative_count": 1,
      "subtype": "internal",
      "name": "OpenTelemetry orders",
      "id": "8450ed499aeb1204",
      "type": "app"
    },
    "timestamp": {
      "us": 1700750171772963
    }
  },
  "fields": {
    "labels.process_command_args": [
      "/home/sylvain/.sdkman/candidates/java/17.0.8-tem/bin/java",
      "-javaagent:/home/sylvain/dev/elastic-otel-java_span-stack/agent/build/libs/elastic-otel-javaagent-0.0.1-SNAPSHOT.jar",
      "-jar",
      "./target/opbeans-0.0.1-SNAPSHOT.jar"
    ],
    "host.os.full.text": [
      "Linux 6.5.0-13-generic"
    ],
    "labels.process_runtime_description": [
      "Eclipse Adoptium OpenJDK 64-Bit Server VM 17.0.8+7"
    ],
    "host.os.full": [
      "Linux 6.5.0-13-generic"
    ],
    "labels.elastic_span_is_local_root": [
      "false"
    ],
    "host.hostname": [
      "sylvain-elastic"
    ],
    "process.pid": [
      1071606
    ],
    "service.language.name": [
      "java"
    ],
    "labels.thread_name": [
      "http-nio-8080-exec-3"
    ],
    "labels.telemetry_auto_version": [
      "elastic-0.0.1-SNAPSHOT-otel-1.30.0"
    ],
    "processor.event": [
      "span"
    ],
    "agent.name": [
      "opentelemetry/java"
    ],
    "host.name": [
      "sylvain-elastic"
    ],
    "event.agent_id_status": [
      "missing"
    ],
    "event.outcome": [
      "unknown"
    ],
    "labels.agentdev_agent_type": [
      "elastic-otel"
    ],
    "labels.agentdev_worktree": [
      "span-stack"
    ],
    "host.os.type": [
      "linux"
    ],
    "service.runtime.version": [
      "17.0.8+7"
    ],
    "span.id": [
      "8450ed499aeb1204"
    ],
    "data_stream.type": [
      "traces"
    ],
    "span.type": [
      "app"
    ],
    "host.architecture": [
      "amd64"
    ],
    "timestamp.us": [
      1700750171772963
    ],
    "code.stacktrace": [
      "java.lang.Throwable\n\tat co.elastic.otel.ElasticSpanProcessor.captureStackTrace(ElasticSpanProcessor.java:81)\n\tat co.elastic.otel.ElasticSpanProcessor.onEnd(ElasticSpanProcessor.java:56)\n\tat io.opentelemetry.sdk.trace.MultiSpanProcessor.onEnd(MultiSpanProcessor.java:52)\n\tat io.opentelemetry.sdk.trace.SdkSpan.endInternal(SdkSpan.java:451)\n\tat io.opentelemetry.sdk.trace.SdkSpan.end(SdkSpan.java:431)\n\tat io.opentelemetry.javaagent.instrumentation.opentelemetryapi.trace.ApplicationSpan.end(ApplicationSpan.java:140)\n\tat co.elastic.apm.opbeans.controllers.APIRestController.orders(APIRestController.java:140)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)\n\tat java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.base/java.lang.reflect.Method.invoke(Method.java:568)\n\tat org.springframework.web.method.support.InvocableHandlerM"
    ],
    "observer.type": [
      "apm-server"
    ],
    "observer.version": [
      "8.12.0"
    ],
    "agent.version": [
      "1.30.1"
    ],
    "parent.id": [
      "999b27462a952621"
    ],
    "numeric_labels.thread_id": [
      50
    ],
    "span.representative_count": [
      1
    ],
    "span.name": [
      "OpenTelemetry orders"
    ],
    "labels.elastic_span_local_root_id": [
      "8e80b8c8b8a749f6"
    ],
    "numeric_labels.elastic_span_self_time": [
      4026320
    ],
    "service.node.name": [
      "sylvain-elastic"
    ],
    "trace.id": [
      "a323e1ee1efb4b792b96d37f6960fcf0"
    ],
    "span.duration.us": [
      191140
    ],
    "process.executable": [
      "/home/sylvain/.sdkman/candidates/java/17.0.8-tem/bin/java"
    ],
    "service.environment": [
      "sylvain-test"
    ],
    "service.name": [
      "opbeans-elastic-otel"
    ],
    "data_stream.namespace": [
      "default"
    ],
    "service.runtime.name": [
      "OpenJDK Runtime Environment"
    ],
    "span.subtype": [
      "internal"
    ],
    "observer.hostname": [
      "apm-server-apm-server-5bccdfb694-5qsg2"
    ],
    "event.ingested": [
      "2023-11-23T14:36:17.000Z"
    ],
    "@timestamp": [
      "2023-11-23T14:36:11.772Z"
    ],
    "service.version": [
      "1.0"
    ],
    "host.os.platform": [
      "linux"
    ],
    "data_stream.dataset": [
      "apm"
    ]
  }
}

Makefile Show resolved Hide resolved
@SylvainJuge
Copy link
Member Author

Hi @axw, I think it's ready for review, do you think you can take a look at it ?
I have only tested it manually on my side when combined with elastic/apm-server#12096

@axw axw merged commit 1bb8a93 into elastic:main Jan 11, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants