diff --git a/.buildkite/hooks/prepare-benchmark.sh b/.buildkite/hooks/prepare-benchmark.sh index 7dd44d5bca..056042566a 100644 --- a/.buildkite/hooks/prepare-benchmark.sh +++ b/.buildkite/hooks/prepare-benchmark.sh @@ -7,13 +7,6 @@ ES_USER_SECRET=$(vault read -field=es_user secret/ci/elastic-apm-agent-java/open ES_PASS_SECRET=$(vault read -field=es_pass secret/ci/elastic-apm-agent-java/opentelemetry-benchmark) export ES_URL_SECRET ES_USER_SECRET ES_PASS_SECRET -echo "--- Prepare github secrets :vault:" -GITHUB_SECRET=$(vault kv get -field token "kv/ci-shared/observability-ci/github-apmmachine") -GH_TOKEN=$GITHUB_SECRET -export GITHUB_SECRET GH_TOKEN -GITHUB_USERNAME=apmmachine -export GITHUB_USERNAME - echo "--- Install gh :github:" GH_URL=https://github.com/cli/cli/releases/download/v2.37.0/gh_2.37.0_linux_amd64.tar.gz GH_HOME=$(pwd)/.gh diff --git a/.buildkite/hooks/prepare-common.sh b/.buildkite/hooks/prepare-common.sh index 7697908c6f..37d793ab1b 100644 --- a/.buildkite/hooks/prepare-common.sh +++ b/.buildkite/hooks/prepare-common.sh @@ -35,3 +35,10 @@ fi # Validate java is available in the runner. java -version +echo "--- Prepare github secrets :vault:" +VAULT_SECRET_PATH=kv/ci-shared/observability-ci/github-bot-user +GITHUB_SECRET=$(vault kv get -field token "${VAULT_SECRET_PATH}") +GIT_USER=$(vault kv get -field username "${VAULT_SECRET_PATH}") +GIT_EMAIL=$(vault kv get -field email "${VAULT_SECRET_PATH}") +GH_TOKEN=$GITHUB_SECRET +export GITHUB_SECRET GH_TOKEN GIT_USER GIT_EMAIL diff --git a/.buildkite/hooks/prepare-release.sh b/.buildkite/hooks/prepare-release.sh index def869b9d2..70175af39c 100644 --- a/.buildkite/hooks/prepare-release.sh +++ b/.buildkite/hooks/prepare-release.sh @@ -35,5 +35,5 @@ echo "$KEYPASS_SECRET" | gpg --batch --import "$KEY_FILE" echo "--- Configure git context :git:" # Configure the committer since the maven release requires to push changes to GitHub # This will help with the SLSA requirements. -git config --global user.email "infra-root+apmmachine@elastic.co" -git config --global user.name "apmmachine" +git config --global user.email "${GIT_EMAIL}" +git config --global user.name "${GIT_USER}" diff --git a/.buildkite/scripts/opentelemetry-benchmark.sh b/.buildkite/scripts/opentelemetry-benchmark.sh index c33395301a..c1a35bf6cc 100755 --- a/.buildkite/scripts/opentelemetry-benchmark.sh +++ b/.buildkite/scripts/opentelemetry-benchmark.sh @@ -26,6 +26,14 @@ BENCHMARKS_JAR=$(ls -1 benchmarks*.jar) BENCHMARKS_JAR_FILE="$(pwd)/$BENCHMARKS_JAR" echo "$BENCHMARKS_JAR_FILE has been downloaded." +echo "--- Download the latest elastic-otel-agent artifact" +distro_run_id=$(gh run list --repo elastic/elastic-otel-java --branch main --status success --workflow build.yml -L 1 --json databaseId --jq '.[].databaseId') +gh run download "$distro_run_id" --repo elastic/elastic-otel-java -n elastic-otel-javaagent +ELASTIC_OTEL_DISTRO_SNAPSHOT_JAR=$(ls -1 elastic-otel-javaagent-*SNAPSHOT.jar) +ELASTIC_OTEL_DISTRO_SNAPSHOT_JAR_FILE="$(pwd)/$ELASTIC_OTEL_DISTRO_SNAPSHOT_JAR" +echo "$ELASTIC_OTEL_DISTRO_SNAPSHOT_JAR_FILE has been downloaded." + + echo "--- Start APM Server mock" git clone https://github.com/elastic/apm-k8s-attacher.git pushd apm-k8s-attacher/test/mock @@ -41,11 +49,37 @@ pushd opentelemetry-java-instrumentation/ echo "--- Customise the elastic opentelemetry java instrumentation" pushd benchmark-overhead cp "$ELASTIC_SNAPSHOT_JAR_FILE" . -ELASTIC_SNAPSHOT_ENTRY="new Agent(\\\"elastic-snapshot\\\",\\\"latest available snapshot version from elastic main\\\",\\\"file://$PWD/$ELASTIC_SNAPSHOT_JAR\\\", java.util.List.of(\\\"-Delastic.apm.server_url=http://host.docker.internal:8027/\\\"))" +cp "$ELASTIC_OTEL_DISTRO_SNAPSHOT_JAR_FILE" . ELASTIC_LATEST_VERSION=$(curl -s https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/ | perl -ne 's/<.*?>//g; if(s/^([\d\.]+).*$/$1/){print}' | sort -V | tail -1) +ELASTIC_OTEL_DISTRO_LATEST_VERSION=$(curl -s https://repo1.maven.org/maven2/co/elastic/otel/elastic-otel-javaagent/ | perl -ne 's/<.*?>//g; if(s/^([\d\.]+).*$/$1/){print}' | sort -V | tail -1) +ELASTIC_SNAPSHOT_ENTRY="new Agent(\\\"elastic-snapshot\\\",\\\"latest available snapshot version from elastic main\\\",\\\"file://$PWD/$ELASTIC_SNAPSHOT_JAR\\\", java.util.List.of(\\\"-Delastic.apm.server_url=http://host.docker.internal:8027/\\\"))" ELASTIC_LATEST_ENTRY="new Agent(\\\"elastic-latest\\\",\\\"latest available released version from elastic main\\\",\\\"https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/$ELASTIC_LATEST_VERSION/elastic-apm-agent-$ELASTIC_LATEST_VERSION.jar\\\", java.util.List.of(\\\"-Delastic.apm.server_url=http://host.docker.internal:8027/\\\"))" ELASTIC_LATEST_ENTRY2="new Agent(\\\"elastic-async\\\",\\\"latest available released version from elastic main\\\",\\\"https://repo1.maven.org/maven2/co/elastic/apm/elastic-apm-agent/$ELASTIC_LATEST_VERSION/elastic-apm-agent-$ELASTIC_LATEST_VERSION.jar\\\", java.util.List.of(\\\"-Delastic.apm.delay_agent_premain_ms=15000\\\",\\\"-Delastic.apm.server_url=http://host.docker.internal:8027/\\\"))" -NEW_LINE=" .withAgents(Agent.NONE, Agent.LATEST_RELEASE, Agent.LATEST_SNAPSHOT, $ELASTIC_LATEST_ENTRY, $ELASTIC_LATEST_ENTRY2, $ELASTIC_SNAPSHOT_ENTRY)" +ELASTIC_OTEL_DISTRO_SNAPSHOT_ENTRY="new Agent(\\\"distro-snapshot\\\",\\\"latest available snapshot version from elastic-otel-java main\\\",\\\"file://$PWD/$ELASTIC_OTEL_DISTRO_SNAPSHOT_JAR\\\")" +ELASTIC_OTEL_DISTRO_LATEST_ENTRY="new Agent(\\\"distro-latest\\\",\\\"latest available released version from elastic-otel-java\\\",\\\"https://repo1.maven.org/maven2/co/elastic/otel/elastic-otel-javaagent/$ELASTIC_OTEL_DISTRO_LATEST_VERSION/elastic-otel-javaagent-$ELASTIC_OTEL_DISTRO_LATEST_VERSION.jar\\\")" +ELASTIC_OTEL_DISTRO_FEATURE_ENTRIES="" +for FEATURE in "infspan" "cloudres" "up-integ" "spanstack" ; do + FEATURE_ARGS="" + if [ "$FEATURE" = "infspan" ]; then + FEATURE_ARGS="$FEATURE_ARGS, \\\"-Delastic.otel.inferred.spans.enabled=true\\\"" + fi + if [ "$FEATURE" != "cloudres" ]; then + FEATURE_ARGS="$FEATURE_ARGS, \\\"-Dotel.resource.providers.aws.enabled=false\\\", \\\"-Dotel.resource.providers.gcp.enabled=false\\\"" + fi + + if [ "$FEATURE" = "up-integ" ]; then + FEATURE_ARGS="$FEATURE_ARGS, \\\"-Delastic.otel.universal.profiling.integration.enabled=true\\\"" + else + FEATURE_ARGS="$FEATURE_ARGS, \\\"-Delastic.otel.universal.profiling.integration.enabled=false\\\"" + fi + if [ "$FEATURE" != "spanstack" ]; then + FEATURE_ARGS="$FEATURE_ARGS, \\\"-Delastic.otel.span.stack.trace.min.duration=-1\\\"" + fi + # Remove leading ", " + FEATURE_ARGS="${FEATURE_ARGS:2}" + ELASTIC_OTEL_DISTRO_FEATURE_ENTRIES="$ELASTIC_OTEL_DISTRO_FEATURE_ENTRIES, new Agent(\\\"distro-$FEATURE\\\",\\\"latest available snapshot version from elastic-otel-java main with only feature $FEATURE enabled\\\",\\\"file://$PWD/$ELASTIC_OTEL_DISTRO_SNAPSHOT_JAR\\\", java.util.List.of($FEATURE_ARGS))" +done +NEW_LINE=" .withAgents(Agent.NONE, Agent.LATEST_RELEASE, Agent.LATEST_SNAPSHOT, $ELASTIC_LATEST_ENTRY, $ELASTIC_LATEST_ENTRY2, $ELASTIC_SNAPSHOT_ENTRY, $ELASTIC_OTEL_DISTRO_SNAPSHOT_ENTRY, $ELASTIC_OTEL_DISTRO_LATEST_ENTRY $ELASTIC_OTEL_DISTRO_FEATURE_ENTRIES)" echo $NEW_LINE perl -i -ne "if (/withAgents/) {print \"$NEW_LINE\n\"}else{print}" src/test/java/io/opentelemetry/config/Configs.java diff --git a/.ci/release/update-major-branch.sh b/.ci/release/update-major-branch.sh index 146364f498..31f6ebe80e 100755 --- a/.ci/release/update-major-branch.sh +++ b/.ci/release/update-major-branch.sh @@ -68,4 +68,8 @@ git checkout -b "update-major-${v}" git push origin "update-major-${v}" echo -e "\n--- create PR to update major branch" -gh pr create --title="post release v${v}: update major branch" --base "${major_branch}" --head "update-major-${v}" -b "post release v${v}" +gh pr create \ + --title="[release] release-step-4 ${v}" \ + --base "${major_branch}" \ + --head "update-major-${v}" \ + -b "Step 4 of the release process for version ${v}: review & merge with merge commit WITHOUT SQUASH to prevent conflicts" diff --git a/.ci/snapshoty.yml b/.ci/snapshoty.yml deleted file mode 100644 index e83c94de7b..0000000000 --- a/.ci/snapshoty.yml +++ /dev/null @@ -1,55 +0,0 @@ ---- - -# Version of configuration to use -version: '1.0' - -# You can define a Google Cloud Account to use -account: - # Project id of the service account - project: '${GCS_PROJECT}' - # Private key id of the service account - private_key_id: '${GCS_PRIVATE_KEY_ID}' - # Private key of the service account - private_key: '${GCS_PRIVATE_KEY}' - # Email of the service account - client_email: '${GCS_CLIENT_EMAIL}' - # URI token - token_uri: 'https://oauth2.googleapis.com/token' - -x-metadata: &metadata - # Define static custom metadata - - name: 'custom' - data: - project: 'apm-agent-java' - # Add git metadata - - name: 'git' - # Add github_actions metadata - - name: 'github_actions' - - -# List of artifacts -artifacts: - # Path to use for artifacts discovery - - path: './elastic-apm-agent/target' - # Files pattern to match - files_pattern: 'elastic-apm-agent-(?P\d+\.\d+\.\d+(-\S+)?)\.jar' - # File layout on GCS bucket - output_pattern: '{project}/{github_branch_name}/elastic-apm-java-{app_version}-{github_sha_short}.jar' - # List of metadata processors to use. - metadata: *metadata - - path: './elastic-apm-agent/target' - files_pattern: 'elastic-apm-java-aws-lambda-layer-(?P\d+\.\d+\.\d+(-\S+)?)\.zip' - output_pattern: '{project}/{github_branch_name}/elastic-apm-java-aws-lambda-layer-{app_version}-{github_sha_short}.zip' - metadata: *metadata - - path: './apm-agent-attach/target' - files_pattern: 'apm-agent-attach-(?P\d+\.\d+\.\d+(-\S+)?)\.jar' - output_pattern: '{project}/{github_branch_name}/elastic-apm-java-attach-{app_version}-{github_sha_short}.jar' - metadata: *metadata - - path: './apm-agent-attach-cli/target' - files_pattern: 'apm-agent-attach-cli-(?P\d+\.\d+\.\d+(-\S+)?)\.jar' - output_pattern: '{project}/{github_branch_name}/elastic-apm-java-attach-{app_version}-{github_sha_short}.jar' - metadata: *metadata - - path: './apm-agent-api/target' - files_pattern: 'apm-agent-api-(?P\d+\.\d+\.\d+(-\S+)?)\.jar' - output_pattern: '{project}/{github_branch_name}/elastic-apm-java-api-{app_version}-{github_sha_short}.jar' - metadata: *metadata diff --git a/.ci/updatecli/updatecli.d/update-gherkin-specs.yml b/.ci/updatecli/updatecli.d/update-gherkin-specs.yml deleted file mode 100644 index 4515026c32..0000000000 --- a/.ci/updatecli/updatecli.d/update-gherkin-specs.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: update-gherkin-specs -pipelineid: update-gherkin-specs - -scms: - default: - kind: github - spec: - user: '{{ requiredEnv "GIT_USER" }}' - email: '{{ requiredEnv "GIT_EMAIL" }}' - owner: "{{ .github.owner }}" - repository: "{{ .github.repository }}" - token: '{{ requiredEnv "GITHUB_TOKEN" }}' - username: '{{ requiredEnv "GIT_USER" }}' - branch: "{{ .github.branch }}" - apm: - kind: github - spec: - user: '{{ requiredEnv "GIT_USER" }}' - email: '{{ requiredEnv "GIT_EMAIL" }}' - owner: "{{ .github.owner }}" - repository: "{{ .github.apm_repository }}" - token: '{{ requiredEnv "GITHUB_TOKEN" }}' - username: '{{ requiredEnv "GIT_USER" }}' - branch: "{{ .github.branch }}" - -sources: - sha: - kind: file - spec: - file: 'https://github.com/{{ .github.owner }}/{{ .github.apm_repository }}/commit/{{ .github.branch }}.patch' - matchpattern: "^From\\s([0-9a-f]{40})\\s" - transformers: - - findsubmatch: - pattern: "[0-9a-f]{40}" - pull_request: - kind: shell - dependson: - - sha - spec: - command: gh api /repos/{{ .github.owner }}/{{ .github.apm_repository }}/commits/{{ source "sha" }}/pulls --jq '.[].html_url' - environments: - - name: GITHUB_TOKEN - - name: PATH - agents-gherkin-specs-tarball: - kind: shell - scmid: apm - dependson: - - sha - spec: - command: tar cvzf {{ requiredEnv "GITHUB_WORKSPACE" }}/gherkin-specs.tgz . - environments: - - name: PATH - workdir: "{{ .specs.apm_gherkin_path }}" - -actions: - pr: - kind: "github/pullrequest" - scmid: default - spec: - automerge: false - draft: false - labels: - - "automation" - description: |- - ### What - APM agent Gherkin specs automatic sync - - ### Why - *Changeset* - * {{ source "pull_request" }} - * https://github.com/elastic/apm/commit/{{ source "sha" }} - title: '[Automation] Update Gherkin specs' - -targets: - agent-gherkin-specs: - name: APM agent gherkin specs {{ source "sha" }} - scmid: default - disablesourceinput: true - kind: shell - spec: - command: 'tar -xzf {{ requiredEnv "GITHUB_WORKSPACE" }}/gherkin-specs.tgz && git --no-pager diff' - workdir: "{{ .apm_agent.gherkin_specs_path }}" diff --git a/.ci/updatecli/updatecli.d/update-json-specs.yml b/.ci/updatecli/updatecli.d/update-json-specs.yml deleted file mode 100644 index 0856990f96..0000000000 --- a/.ci/updatecli/updatecli.d/update-json-specs.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: update-json-specs -pipelineid: update-json-specs - -scms: - default: - kind: github - spec: - user: '{{ requiredEnv "GIT_USER" }}' - email: '{{ requiredEnv "GIT_EMAIL" }}' - owner: "{{ .github.owner }}" - repository: "{{ .github.repository }}" - token: '{{ requiredEnv "GITHUB_TOKEN" }}' - username: '{{ requiredEnv "GIT_USER" }}' - branch: "{{ .github.branch }}" - apm: - kind: github - spec: - user: '{{ requiredEnv "GIT_USER" }}' - email: '{{ requiredEnv "GIT_EMAIL" }}' - owner: "{{ .github.owner }}" - repository: "{{ .github.apm_repository }}" - token: '{{ requiredEnv "GITHUB_TOKEN" }}' - username: '{{ requiredEnv "GIT_USER" }}' - branch: "{{ .github.branch }}" - -sources: - sha: - kind: file - spec: - file: 'https://github.com/{{ .github.owner }}/{{ .github.apm_repository }}/commit/{{ .github.branch }}.patch' - matchpattern: "^From\\s([0-9a-f]{40})\\s" - transformers: - - findsubmatch: - pattern: "[0-9a-f]{40}" - pull_request: - kind: shell - dependson: - - sha - spec: - command: gh api /repos/{{ .github.owner }}/{{ .github.apm_repository }}/commits/{{ source "sha" }}/pulls --jq '.[].html_url' - environments: - - name: GITHUB_TOKEN - - name: PATH - agents-json-specs-tarball: - kind: shell - scmid: apm - dependson: - - sha - spec: - command: tar cvzf {{ requiredEnv "GITHUB_WORKSPACE" }}/json-specs.tgz . - environments: - - name: PATH - workdir: "{{ .specs.apm_json_path }}" - -actions: - pr: - kind: "github/pullrequest" - scmid: default - spec: - automerge: false - draft: false - labels: - - "automation" - description: |- - ### What - APM agent specs automatic sync - - ### Why - *Changeset* - * {{ source "pull_request" }} - * https://github.com/{{ .github.owner }}/{{ .github.apm_repository }}/commit/{{ source "sha" }} - title: '[Automation] Update JSON specs' - -targets: - agent-json-specs: - name: APM agent json specs {{ source "sha" }} - scmid: default - disablesourceinput: true - kind: shell - spec: - command: 'tar -xzf {{ requiredEnv "GITHUB_WORKSPACE" }}/json-specs.tgz && git --no-pager diff' - workdir: "{{ .apm_agent.json_specs_path }}" diff --git a/.ci/updatecli/updatecli.d/update-specs.yml b/.ci/updatecli/updatecli.d/update-specs.yml deleted file mode 100644 index 2b3f34ef80..0000000000 --- a/.ci/updatecli/updatecli.d/update-specs.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: update-specs -pipelineid: update-schema-specs - -scms: - default: - kind: github - spec: - user: '{{ requiredEnv "GIT_USER" }}' - email: '{{ requiredEnv "GIT_EMAIL" }}' - owner: "{{ .github.owner }}" - repository: "{{ .github.repository }}" - token: '{{ requiredEnv "GITHUB_TOKEN" }}' - username: '{{ requiredEnv "GIT_USER" }}' - branch: "{{ .github.branch }}" - - apm-data: - kind: github - spec: - user: '{{ requiredEnv "GIT_USER" }}' - email: '{{ requiredEnv "GIT_EMAIL" }}' - owner: "{{ .github.owner }}" - repository: "{{ .github.apm_data_repository }}" - token: '{{ requiredEnv "GITHUB_TOKEN" }}' - username: '{{ requiredEnv "GIT_USER" }}' - branch: "{{ .github.branch }}" - -sources: - sha: - kind: file - spec: - file: 'https://github.com/{{ .github.owner }}/{{ .github.apm_data_repository }}/commit/{{ .github.branch }}.patch' - matchpattern: "^From\\s([0-9a-f]{40})\\s" - transformers: - - findsubmatch: - pattern: "[0-9a-f]{40}" - pull_request: - kind: shell - dependson: - - sha - spec: - command: gh api /repos/{{ .github.owner }}/{{ .github.apm_data_repository }}/commits/{{ source "sha" }}/pulls --jq '.[].html_url' - environments: - - name: GITHUB_TOKEN - - name: PATH - agent-specs-tarball: - kind: shell - scmid: apm-data - dependson: - - sha - spec: - command: tar cvzf {{ requiredEnv "GITHUB_WORKSPACE" }}/json-schema.tgz . - environments: - - name: PATH - workdir: "{{ .specs.apm_data_path }}" - -actions: - pr: - kind: "github/pullrequest" - scmid: default - sourceid: sha - spec: - automerge: false - draft: false - labels: - - "automation" - description: |- - ### What - APM agent json server schema automatic sync - - ### Why - *Changeset* - * {{ source "pull_request" }} - * https://github.com/{{ .github.owner }}/{{ .github.apm_data_repository }}/commit/{{ source "sha" }} - title: '[Automation] Update JSON server schema specs' - -targets: - agent-json-schema: - name: APM agent json server schema {{ source "sha" }} - scmid: default - disablesourceinput: true - kind: shell - spec: - command: 'tar -xzf {{ requiredEnv "GITHUB_WORKSPACE" }}/json-schema.tgz && git --no-pager diff' - workdir: "{{ .apm_agent.server_schema_specs_path }}" diff --git a/.ci/updatecli/values.d/apm-data-spec.yml b/.ci/updatecli/values.d/apm-data-spec.yml new file mode 100644 index 0000000000..fd8c9e37f7 --- /dev/null +++ b/.ci/updatecli/values.d/apm-data-spec.yml @@ -0,0 +1,2 @@ +apm_schema_specs_path: apm-agent-core/src/test/resources/apm-server-schema/current +signedcommit: true \ No newline at end of file diff --git a/.ci/updatecli/values.d/apm-gherkin.yml b/.ci/updatecli/values.d/apm-gherkin.yml new file mode 100644 index 0000000000..d676b58b2a --- /dev/null +++ b/.ci/updatecli/values.d/apm-gherkin.yml @@ -0,0 +1,2 @@ +apm_gherkin_specs_path: apm-agent-core/src/test/resources/specs +signedcommit: true \ No newline at end of file diff --git a/.ci/updatecli/values.d/apm-json-specs.yml b/.ci/updatecli/values.d/apm-json-specs.yml new file mode 100644 index 0000000000..b1b70a8e69 --- /dev/null +++ b/.ci/updatecli/values.d/apm-json-specs.yml @@ -0,0 +1,2 @@ +apm_json_specs_path: apm-agent-core/src/test/resources/json-specs +signedcommit: true \ No newline at end of file diff --git a/.ci/updatecli/values.d/scm.yml b/.ci/updatecli/values.d/scm.yml new file mode 100644 index 0000000000..5cfcec7d2a --- /dev/null +++ b/.ci/updatecli/values.d/scm.yml @@ -0,0 +1,10 @@ +scm: + enabled: true + owner: elastic + repository: apm-agent-java + apm_repository: apm + branch: main + # begin update-compose policy values + user: obltmachine + email: obltmachine@users.noreply.github.com + # end update-compose policy values diff --git a/.ci/updatecli/values.d/update-compose.yml b/.ci/updatecli/values.d/update-compose.yml new file mode 100644 index 0000000000..8804f96618 --- /dev/null +++ b/.ci/updatecli/values.d/update-compose.yml @@ -0,0 +1,3 @@ +spec: + files: + - "update-compose.yaml" \ No newline at end of file diff --git a/.ci/updatecli/values.yml b/.ci/updatecli/values.yml deleted file mode 100644 index 5d1e74685f..0000000000 --- a/.ci/updatecli/values.yml +++ /dev/null @@ -1,14 +0,0 @@ -github: - owner: "elastic" - repository: "apm-agent-java" - apm_repository: "apm" - apm_data_repository: "apm-data" - branch: "main" -specs: - apm_data_path: "input/elasticapm/docs/spec/v2" - apm_json_path: "tests/agents/json-specs" - apm_gherkin_path: "tests/agents/gherkin-specs" -apm_agent: - gherkin_specs_path: "apm-agent-core/src/test/resources/specs" - json_specs_path: "apm-agent-core/src/test/resources/json-specs" - server_schema_specs_path: "apm-agent-core/src/test/resources/apm-server-schema/current" \ No newline at end of file diff --git a/.github/workflows/README.md b/.github/workflows/README.md index cbc0140d24..c22d4fabd9 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -10,7 +10,6 @@ There are 4 main stages that run on GitHub actions: There are some other stages that run for every push on the main branches: * [Microbenchmark](./microbenchmark.yml) -* [Snapshoty](./snapshoty.yml) * [Sync-branches](./sync-branches.yml) ### Scenarios @@ -36,17 +35,23 @@ Every time there is a merge to main or any branches the whole workflow will comp ### Release process To release a new version of apm-agent-java, you must use the two GitHub Workflows. -Trigger the `Pre Release` workflow targeting the release version. -After merging the PRs created by the first workflow, you can trigger the `Release` workflow targeting the release version. -It runs then a Buildkite pipeline in charge of generating and publishing the artifacts, -for further details please go to [the buildkite folder](../../.buildkite/README.md). -Finally, merge the PRs created to bump version for the next iteration. +- Trigger the `release-step-1` GH workflow + - parameters: version to release + - will open `release-step-2` PR +- Review and merge the `release-step-2` PR to `main` (version bump to release + changelog update) +- Trigger the `release-step-3` GH workflow + - parameters: version to release and the `main` branch (or merge commit/ref of `release-step-2` PR merge). + - will generate and publish release artifact through [buildkite](../../.buildkite/README.md). + - will open two PRs: `release-step-4` and `release-step-5` + - will wait on the `release-step-4` PR to be merged and published (documentation update) +- Review and merge the `release-step-4` PR to the "major branch", which is currently `1.x`, the documentation effective build and publication can take a while. +- Review and merge the `release-step-5` PR to `main` (version bump from release to next snapshot version) The tag release follows the naming convention: `v...`, where ``, `` and ``. ### OpenTelemetry -There is a GitHub workflow in charge to populate what the workflow run in terms of jobs and steps. Those details can be seen in [here](https://ela.st/oblt-ci-cd-stats) (**NOTE**: only available for Elasticians). +Every workflow and its logs are exported to OpenTelemetry traces/logs/metrics. Those details can be seen [here](https://ela.st/oblt-ci-cd-stats) (**NOTE**: only available for Elasticians). ## Bump automation diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d69d0d610e..4691fb2baa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -338,13 +338,14 @@ jobs: if: github.event_name != 'pull_request' || ( github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false && github.actor != 'dependabot[bot]' ) steps: - uses: actions/checkout@v4 - - uses: elastic/apm-pipeline-library/.github/actions/docker-login@current + + - name: Log in to the Elastic Container registry + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 with: - registry: docker.elastic.co - secret: secret/observability-team/ci/docker-registry/prod - url: ${{ secrets.VAULT_ADDR }} - roleId: ${{ secrets.VAULT_ROLE_ID }} - secretId: ${{ secrets.VAULT_SECRET_ID }} + registry: ${{ secrets.ELASTIC_DOCKER_REGISTRY }} + username: ${{ secrets.ELASTIC_DOCKER_USERNAME }} + password: ${{ secrets.ELASTIC_DOCKER_PASSWORD }} + - uses: ./.github/workflows/unstash with: name: build diff --git a/.github/workflows/microbenchmark.yml b/.github/workflows/microbenchmark.yml index c576f067dc..f1814b2e4b 100644 --- a/.github/workflows/microbenchmark.yml +++ b/.github/workflows/microbenchmark.yml @@ -21,36 +21,19 @@ permissions: jobs: microbenchmark: runs-on: ubuntu-latest - # wait up to 1 hour - timeout-minutes: 60 + timeout-minutes: 5 steps: - - id: buildkite - name: Run buildkite pipeline - uses: elastic/apm-pipeline-library/.github/actions/buildkite@current + - name: Run microbenchmark + uses: elastic/oblt-actions/buildkite/run@v1.5.0 env: JAVA_VERSION: ${{ inputs.java_version || 'openjdk-17+35-linux' }} with: - vaultUrl: ${{ secrets.VAULT_ADDR }} - vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} - vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} - pipeline: apm-agent-microbenchmark - triggerMessage: "${{ github.repository }}@${{ github.ref_name }}" - waitFor: true - printBuildLogs: true - buildEnvVars: | + pipeline: "apm-agent-microbenchmark" + token: ${{ secrets.BUILDKITE_TOKEN }} + wait-for: false + env-vars: | script=.ci/scripts/bench.sh repo=apm-agent-java sha=${{ github.sha }} JAVA_VERSION=${{ env.JAVA_VERSION }} BRANCH_NAME=${{ github.ref_name }} - - - if: ${{ failure() }} - uses: elastic/apm-pipeline-library/.github/actions/slack-message@current - with: - url: ${{ secrets.VAULT_ADDR }} - roleId: ${{ secrets.VAULT_ROLE_ID }} - secretId: ${{ secrets.VAULT_SECRET_ID }} - channel: "#apm-agent-java" - message: | - :ghost: [${{ github.repository }}] microbenchmark *${{ github.ref_name }}* failed to run in Buildkite. - Build: (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>) diff --git a/.github/workflows/pre-post-release.yml b/.github/workflows/pre-post-release.yml index e34026ebd4..e0cb6ceecd 100644 --- a/.github/workflows/pre-post-release.yml +++ b/.github/workflows/pre-post-release.yml @@ -18,6 +18,14 @@ on: description: 'Pre or post release phase' type: string # valid values are 'pre' or 'post' required: true + pr_title: + description: 'pull-request title' + type: string + required: true + pr_body: + description: 'pull-request body' + type: string + required: true env: RELEASE_VERSION: ${{ inputs.version }} @@ -47,24 +55,15 @@ jobs: - validate-tag permissions: contents: write + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} steps: - - uses: elastic/apm-pipeline-library/.github/actions/github-token@current - with: - url: ${{ secrets.VAULT_ADDR }} - roleId: ${{ secrets.VAULT_ROLE_ID }} - secretId: ${{ secrets.VAULT_SECRET_ID }} - - - uses: elastic/apm-pipeline-library/.github/actions/setup-git@current - with: - username: ${{ env.GIT_USER }} - email: ${{ env.GIT_EMAIL }} - token: ${{ env.GITHUB_TOKEN }} - - uses: actions/checkout@v4 with: ref: ${{ inputs.ref }} token: ${{ env.GITHUB_TOKEN }} + - uses: elastic/oblt-actions/git/setup@v1 - name: Create the release tag (post phase) if: inputs.phase == 'post' run: | @@ -91,8 +90,7 @@ jobs: git add --all git commit -m "${{ inputs.phase }} release: elastic-apm-agent ${{ env.RELEASE_VERSION_TAG }}" git push origin ${{ env.BRANCH_NAME }} - - name: Create the ${{ inputs.phase }} release PR - run: gh pr create --title="${{ inputs.phase }} release ${{ env.RELEASE_VERSION_TAG }}" --base main --head ${{ env.BRANCH_NAME }} -b "${{ inputs.phase }} release ${{ env.RELEASE_VERSION_TAG }}" + run: gh pr create --title="${{ inputs.pr_title }}" --base main --head ${{ env.BRANCH_NAME }} -b "${{ inputs.pr_body }}" env: GH_TOKEN: ${{ env.GITHUB_TOKEN }} diff --git a/.github/workflows/release-step-1.yml b/.github/workflows/release-step-1.yml new file mode 100644 index 0000000000..c0b5a1a365 --- /dev/null +++ b/.github/workflows/release-step-1.yml @@ -0,0 +1,34 @@ +--- + +name: 'release-step-1' + +on: + workflow_dispatch: + inputs: + ref: + description: 'Branch or tag ref to run the workflow on' + required: true + default: "main" + version: + description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required version bumps' + required: true + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }} + +jobs: + pre-release: + name: "Bump versions and create PR" + uses: ./.github/workflows/pre-post-release.yml + permissions: + contents: write + with: + ref: ${{ inputs.ref }} + version: ${{ inputs.version }} + phase: 'pre' + pr_title: "[release] release-step-2 ${{ inputs.version }}" + pr_body: "Step 2 of the release process for version ${{ inputs.version }}: review & merge, then execute 'release-step-3' GH workflow" + secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release-step-3.yml similarity index 75% rename from .github/workflows/release.yml rename to .github/workflows/release-step-3.yml index 6641ac0fca..b7dd6d3ac5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release-step-3.yml @@ -1,6 +1,8 @@ --- # Releases the agent -name: release +# Renaming this file will break the AWS authentication. +# Contact the observablt-robots team if you need to rename this file. +name: 'release-step-3' on: workflow_dispatch: @@ -10,7 +12,7 @@ on: required: true default: "main" version: - description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required version bumps' + description: 'The version to release (e.g. 1.2.3). This workflow will automatically perform the required post-release version bumps' required: true skip_preparation: description: | @@ -55,7 +57,7 @@ jobs: uses: ./.github/workflows/validate-tag with: tag: ${{ env.RELEASE_VERSION_TAG }} - - name: Validate tag match current version + - name: Validate tag match current maven project version run: | if [ "$(./mvnw -q help:evaluate -Dexpression=project.version -DforceStdout)" != "${{ env.RELEASE_VERSION }}" ]; then echo "Tag should match pom.xml project.version" @@ -81,32 +83,29 @@ jobs: env: TARBALL_FILE: artifacts.tar steps: - - id: buildkite + - id: buildkite-run continue-on-error: true - name: Run Deploy - uses: elastic/apm-pipeline-library/.github/actions/buildkite@current + uses: elastic/oblt-actions/buildkite/run@v1 with: - vaultUrl: ${{ secrets.VAULT_ADDR }} - vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} - vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} - pipeline: apm-agent-java-release - waitFor: true - printBuildLogs: false - artifactName: releases - artifactPath: ${{ env.TARBALL_FILE }} - buildEnvVars: | + pipeline: "apm-agent-java-release" + token: ${{ secrets.BUILDKITE_TOKEN }} + wait-for: true + env-vars: | dry_run=${{ inputs.dry_run || 'false' }} TARBALL_FILE=${{ env.TARBALL_FILE }} - - uses: actions/download-artifact@v3 + - uses: elastic/oblt-actions/buildkite/download-artifact@v1 with: - name: releases + build-number: ${{ steps.buildkite-run.outputs.number }} + path: "${{ env.TARBALL_FILE }}" + pipeline: ${{ steps.buildkite-run.outputs.pipeline }} + token: ${{ secrets.BUILDKITE_TOKEN }} - name: untar the buildkite tarball run: tar xvf ${{ env.TARBALL_FILE }} - name: generate build provenance - uses: actions/attest-build-provenance@173725a1209d09b31f9d30a3890cf2757ebbff0d # v1.1.2 + uses: actions/attest-build-provenance@5e9cb68e95676991667494a6a4e59b8a2f13e1d0 # v1.3.3 with: subject-path: "${{ github.workspace }}/**/target/*.jar" @@ -135,13 +134,14 @@ jobs: with: ref: ${{ inputs.ref }} fetch-depth: 0 # Load entire history as it is required for the push-script - - uses: elastic/apm-pipeline-library/.github/actions/docker-login@current + + - name: Log in to the Elastic Container registry + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 with: - registry: docker.elastic.co - secret: secret/apm-team/ci/docker-registry/prod - url: ${{ secrets.VAULT_ADDR }} - roleId: ${{ secrets.VAULT_ROLE_ID }} - secretId: ${{ secrets.VAULT_SECRET_ID }} + registry: ${{ secrets.ELASTIC_DOCKER_REGISTRY }} + username: ${{ secrets.ELASTIC_DOCKER_USERNAME }} + password: ${{ secrets.ELASTIC_DOCKER_PASSWORD }} + - name: "Build docker image" shell: bash run: ./scripts/docker-release/build_docker.sh "${{ env.RELEASE_VERSION }}" @@ -152,15 +152,14 @@ jobs: publish-aws-lambda: name: "Publish AWS Lambda" + permissions: + contents: read + id-token: write runs-on: ubuntu-latest needs: - await-maven-central-artifact outputs: arn_content: ${{ steps.arn_output.outputs.arn_content }} - env: - # Random region. This needs to be set in GH Actions or the usage of aws-cli will fail. - # The default region does not matter, since we are publishing in all regions. - AWS_DEFAULT_REGION: eu-west-1 steps: - uses: actions/checkout@v4 with: @@ -169,15 +168,9 @@ jobs: uses: ./.github/workflows/maven-goal with: command: ./mvnw dependency:purge-local-repository package -pl apm-agent-lambda-layer - - uses: hashicorp/vault-action@v3.0.0 + - uses: elastic/oblt-actions/aws/auth@v1.10.0 with: - url: ${{ secrets.VAULT_ADDR }} - method: approle - roleId: ${{ secrets.VAULT_ROLE_ID }} - secretId: ${{ secrets.VAULT_SECRET_ID }} - secrets: | - secret/observability-team/ci/service-account/apm-aws-lambda access_key_id | AWS_ACCESS_KEY_ID ; - secret/observability-team/ci/service-account/apm-aws-lambda secret_access_key | AWS_SECRET_ACCESS_KEY + aws-account-id: '267093732750' - name: Publish if: ${{ ! inputs.dry_run }} run: | @@ -211,6 +204,8 @@ jobs: ref: ${{ inputs.ref }} version: ${{ inputs.version }} phase: 'post' + pr_title: "[release] release-step-5 ${{ inputs.version }}" + pr_body: "Step 5 of the release process for version ${{ inputs.version }}: review & merge" secrets: inherit update-major-branch: @@ -220,21 +215,16 @@ jobs: - post-release permissions: contents: write + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} steps: - - uses: elastic/apm-pipeline-library/.github/actions/github-token@current - with: - url: ${{ secrets.VAULT_ADDR }} - roleId: ${{ secrets.VAULT_ROLE_ID }} - secretId: ${{ secrets.VAULT_SECRET_ID }} - - uses: elastic/apm-pipeline-library/.github/actions/setup-git@current - with: - username: ${{ env.GIT_USER }} - email: ${{ env.GIT_EMAIL }} - token: ${{ env.GITHUB_TOKEN }} - uses: actions/checkout@v4 with: ref: ${{ inputs.ref }} token: ${{ env.GITHUB_TOKEN }} + + - uses: elastic/oblt-actions/git/setup@v1 + - name: Update major branch if: ${{ ! inputs.dry_run }} run: .ci/release/update-major-branch.sh ${{ env.RELEASE_VERSION }} @@ -289,10 +279,8 @@ jobs: uses: elastic/apm-pipeline-library/.github/actions/check-dependent-jobs@current with: needs: ${{ toJSON(needs) }} - - uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current + - uses: elastic/oblt-actions/slack/notify-result@v1 with: + bot-token: ${{ secrets.SLACK_BOT_TOKEN }} + channel-id: "#apm-agent-java" status: ${{ steps.check.outputs.status }} - vaultUrl: ${{ secrets.VAULT_ADDR }} - vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} - vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} - slackChannel: "#apm-agent-java" diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index a0e5139be1..1b58ce6f6f 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -46,32 +46,30 @@ jobs: TARBALL_FILE: artifacts.tar if: ${{ contains(needs.validate.outputs.is-snapshot, 'true') }} steps: - - id: buildkite - name: Run Deploy - uses: elastic/apm-pipeline-library/.github/actions/buildkite@current + - id: buildkite-run + continue-on-error: true + uses: elastic/oblt-actions/buildkite/run@v1 with: - vaultUrl: ${{ secrets.VAULT_ADDR }} - vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} - vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} - pipeline: apm-agent-java-snapshot - pipelineBranch: ${{ github.ref_name }} - artifactName: snapshots - artifactPath: ${{ env.TARBALL_FILE }} - waitFor: true - printBuildLogs: false - buildEnvVars: | + branch: ${{ github.ref_name }} + pipeline: "apm-agent-java-snapshot" + token: ${{ secrets.BUILDKITE_TOKEN }} + wait-for: true + env-vars: | dry_run=${{ inputs.dry_run || 'false' }} TARBALL_FILE=${{ env.TARBALL_FILE }} - - uses: actions/download-artifact@v3 + - uses: elastic/oblt-actions/buildkite/download-artifact@v1 with: - name: snapshots + build-number: ${{ steps.buildkite-run.outputs.number }} + path: "${{ env.TARBALL_FILE }}" + pipeline: ${{ steps.buildkite-run.outputs.pipeline }} + token: ${{ secrets.BUILDKITE_TOKEN }} - name: untar the buildkite tarball run: tar xvf ${{ env.TARBALL_FILE }} - name: generate build provenance - uses: actions/attest-build-provenance@173725a1209d09b31f9d30a3890cf2757ebbff0d # v1.1.2 + uses: actions/attest-build-provenance@5e9cb68e95676991667494a6a4e59b8a2f13e1d0 # v1.3.3 with: subject-path: "${{ github.workspace }}/**/target/*.jar" @@ -80,13 +78,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: elastic/apm-pipeline-library/.github/actions/docker-login@current + + - name: Log in to the Elastic Container registry + uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 with: - registry: docker.elastic.co - secret: secret/apm-team/ci/docker-registry/prod - url: ${{ secrets.VAULT_ADDR }} - roleId: ${{ secrets.VAULT_ROLE_ID }} - secretId: ${{ secrets.VAULT_SECRET_ID }} + registry: ${{ secrets.ELASTIC_DOCKER_REGISTRY }} + username: ${{ secrets.ELASTIC_DOCKER_USERNAME }} + password: ${{ secrets.ELASTIC_DOCKER_PASSWORD }} + - name: prepare context for testing docker build run: | mkdir -p elastic-apm-agent/target @@ -107,12 +106,10 @@ jobs: with: needs: ${{ toJSON(needs) }} - if: ${{ failure() && ! inputs.dry_run }} - uses: elastic/apm-pipeline-library/.github/actions/slack-message@current + uses: elastic/oblt-actions/slack/send@v1 with: - url: ${{ secrets.VAULT_ADDR }} - roleId: ${{ secrets.VAULT_ROLE_ID }} - secretId: ${{ secrets.VAULT_SECRET_ID }} - channel: "#apm-agent-java" + bot-token: ${{ secrets.SLACK_BOT_TOKEN }} + channel-id: "#apm-agent-java" message: | :ghost: [${{ github.repository }}] Snapshot *${{ github.ref_name }}* didn't get triggered in Buildkite. Build: (<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|here>) diff --git a/.github/workflows/snapshoty.yml b/.github/workflows/snapshoty.yml deleted file mode 100644 index 875804ed99..0000000000 --- a/.github/workflows/snapshoty.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -# Publish a snapshot. A "snapshot" is a packaging of the latest *unreleased* APM agent, -# published to a known GCS bucket for use in edge demo/test environments. -name: Snapshoty - -on: - push: - branches: - - main - paths-ignore: - - '*.md' - - '*.asciidoc' - - 'docs/**' - -jobs: - upload: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - uses: ./.github/workflows/maven-goal - with: - command: ./mvnw clean install -DskipTests=true -Dmaven.javadoc.skip=true - - - name: Publish snaphosts - uses: elastic/apm-pipeline-library/.github/actions/snapshoty-simple@current - with: - config: '.ci/snapshoty.yml' - vaultUrl: ${{ secrets.VAULT_ADDR }} - vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} - vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} diff --git a/.github/workflows/updatecli.yml b/.github/workflows/updatecli.yml index 1bfd2967b3..99369c845d 100644 --- a/.github/workflows/updatecli.yml +++ b/.github/workflows/updatecli.yml @@ -9,21 +9,35 @@ permissions: contents: read jobs: - bump: + compose: runs-on: ubuntu-latest + permissions: + contents: read + packages: read steps: - uses: actions/checkout@v4 - - uses: elastic/apm-pipeline-library/.github/actions/updatecli@current + + - uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446 # v3.2.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: elastic/oblt-actions/updatecli/run@v1 with: - vaultUrl: ${{ secrets.VAULT_ADDR }} - vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} - vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} - pipeline: .ci/updatecli/updatecli.d - values: .ci/updatecli/values.yml + command: --experimental compose diff + env: + GITHUB_TOKEN: ${{ secrets.UPDATECLI_GH_TOKEN }} + + - uses: elastic/oblt-actions/updatecli/run@v1 + with: + command: --experimental compose apply + env: + GITHUB_TOKEN: ${{ secrets.UPDATECLI_GH_TOKEN }} + - if: failure() - uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current + uses: elastic/oblt-actions/slack/send@v1 with: - vaultUrl: ${{ secrets.VAULT_ADDR }} - vaultRoleId: ${{ secrets.VAULT_ROLE_ID }} - vaultSecretId: ${{ secrets.VAULT_SECRET_ID }} - slackChannel: "#apm-agent-java" + bot-token: ${{ secrets.SLACK_BOT_TOKEN }} + channel-id: "#apm-agent-java" + message: ":traffic_cone: updatecli failed for `${{ github.repository }}@${{ github.ref_name }}`, @robots-ci please look what's going on " diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index c98b6f6a22..1c66d85875 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -34,6 +34,21 @@ Use subheadings with the "=====" level for adding notes for unreleased changes: [[release-notes-1.x]] === Java Agent version 1.x +[[release-notes-1.51.0]] +==== 1.51.0 - 2024/07/24 + +[float] +===== Bug fixes +* Restore compatibility with Java 7 - {pull}3657[#3657] +* Avoid `ClassCastException` and issue warning when trying to use otel span links - {pull}3672[#3672] +* Avoid `NullPointerException` with runtime attach API and invalid map entries - {pull}3712[#3712] +* Enhance invalid state JMX metrics handling - {pull}3713[#3713] +* Skips using NOFOLLOW_LINKS file open option when running on z/OS as it's unsupported there - {pull}3722[#3722] + +[float] +===== Features +* Added option to make routing-key part of RabbitMQ transaction/span names - {pull}3636[#3636] +* Added internal option for capturing request bodies for apache httpclient v4 - {pull}3692[#3692] [[release-notes-1.50.0]] ==== 1.50.0 - 2024/05/28 diff --git a/apm-agent-api/pom.xml b/apm-agent-api/pom.xml index 5fc39953af..d427230e91 100644 --- a/apm-agent-api/pom.xml +++ b/apm-agent-api/pom.xml @@ -5,7 +5,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 apm-agent-api diff --git a/apm-agent-attach-cli/pom.xml b/apm-agent-attach-cli/pom.xml index 5aeb2ba4a4..065db587e5 100644 --- a/apm-agent-attach-cli/pom.xml +++ b/apm-agent-attach-cli/pom.xml @@ -3,7 +3,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-attach/pom.xml b/apm-agent-attach/pom.xml index 9440483250..5b2c32d9b6 100644 --- a/apm-agent-attach/pom.xml +++ b/apm-agent-attach/pom.xml @@ -5,7 +5,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 apm-agent-attach diff --git a/apm-agent-attach/src/main/java/co/elastic/apm/attach/ElasticApmAttacher.java b/apm-agent-attach/src/main/java/co/elastic/apm/attach/ElasticApmAttacher.java index 7de283076f..c4f8137d33 100644 --- a/apm-agent-attach/src/main/java/co/elastic/apm/attach/ElasticApmAttacher.java +++ b/apm-agent-attach/src/main/java/co/elastic/apm/attach/ElasticApmAttacher.java @@ -150,7 +150,14 @@ public static void attach(String pid, Map configuration) { */ public static void attach(String pid, Map configuration, File agentJarFile) { // making a copy of provided configuration as user might have used an immutable map impl. - Map config = new HashMap<>(configuration); + // and guard against user-provided null keys and values + Map config = new HashMap<>(); + for (Map.Entry entry : configuration.entrySet()) { + if (entry.getKey() != null && entry.getValue() != null) { + config.put(entry.getKey(), entry.getValue()); + } + } + if (!config.containsKey("activation_method")) { config.put("activation_method", "PROGRAMMATIC_SELF_ATTACH"); } diff --git a/apm-agent-benchmarks/pom.xml b/apm-agent-benchmarks/pom.xml index e5b95911e8..08222ecfc4 100644 --- a/apm-agent-benchmarks/pom.xml +++ b/apm-agent-benchmarks/pom.xml @@ -5,7 +5,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 apm-agent-benchmarks @@ -97,22 +97,18 @@ com.fasterxml.jackson.core jackson-databind - ${version.jackson} com.fasterxml.jackson.module jackson-module-afterburner - ${version.jackson} com.fasterxml.jackson.dataformat jackson-dataformat-cbor - ${version.jackson} com.fasterxml.jackson.dataformat jackson-dataformat-protobuf - ${version.jackson} net.bytebuddy diff --git a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/AbstractMockApmServerBenchmark.java b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/AbstractMockApmServerBenchmark.java index de5de5b823..10e42b5749 100644 --- a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/AbstractMockApmServerBenchmark.java +++ b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/AbstractMockApmServerBenchmark.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.benchmark; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; import io.undertow.Undertow; @@ -79,8 +79,8 @@ public void setUp(Blackhole blackhole) throws IOException { tracer = new ElasticApmTracerBuilder() .configurationRegistry(ConfigurationRegistry.builder() .addConfigSource(new SimpleSource() - .add(CoreConfiguration.SERVICE_NAME, "benchmark") - .add(CoreConfiguration.INSTRUMENT, Boolean.toString(apmEnabled)) + .add(CoreConfigurationImpl.SERVICE_NAME, "benchmark") + .add(CoreConfigurationImpl.INSTRUMENT, Boolean.toString(apmEnabled)) .add("active", Boolean.toString(apmEnabled)) .add("api_request_size", "10mb") .add("capture_headers", "false") diff --git a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/LettuceActiveBenchmark.java b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/LettuceActiveBenchmark.java index 043babcc31..c970d16ee2 100644 --- a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/LettuceActiveBenchmark.java +++ b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/LettuceActiveBenchmark.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.benchmark; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.runner.RunnerException; @@ -34,7 +34,7 @@ public LettuceActiveBenchmark() { @Benchmark public String benchmarkLettuce() { - Transaction transaction = tracer.startRootTransaction(null).withName("transaction").activate(); + TransactionImpl transaction = tracer.startRootTransaction(null).withName("transaction").activate(); try { return sync.get("foo"); } finally { diff --git a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/LettuceNotActiveBenchmark.java b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/LettuceNotActiveBenchmark.java index 1b1249d51e..7e5c5bec5b 100644 --- a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/LettuceNotActiveBenchmark.java +++ b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/LettuceNotActiveBenchmark.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.benchmark; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.runner.RunnerException; @@ -36,7 +36,7 @@ public LettuceNotActiveBenchmark() { @Threads(4) @Benchmark public String benchmarkLettuce() { - Transaction transaction = tracer.startRootTransaction(null).withName("transaction").activate(); + TransactionImpl transaction = tracer.startRootTransaction(null).withName("transaction").activate(); try { return sync.get("foo"); } finally { diff --git a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/SizeOfSpan.java b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/SizeOfSpan.java index 13795b1d4e..5c9e9c6cb8 100644 --- a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/SizeOfSpan.java +++ b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/SizeOfSpan.java @@ -20,10 +20,10 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.util.MathUtils; import org.ehcache.sizeof.SizeOf; @@ -32,15 +32,15 @@ public class SizeOfSpan { public static void main(String[] args) { final SizeOf sizeOf = SizeOf.newInstance(); ElasticApmTracer tracer = new ElasticApmTracerBuilder().buildAndStart(); - final long sizeOfSpan = sizeOf.deepSizeOf(new Span(tracer)); - final long sizeOfTransaction = sizeOf.deepSizeOf(new Transaction(tracer)); - final long sizeOfError = sizeOf.deepSizeOf(new ErrorCapture(tracer)); + final long sizeOfSpan = sizeOf.deepSizeOf(new SpanImpl(tracer)); + final long sizeOfTransaction = sizeOf.deepSizeOf(new TransactionImpl(tracer)); + final long sizeOfError = sizeOf.deepSizeOf(new ErrorCaptureImpl(tracer)); System.out.println("sizeof span: " + sizeOfSpan); System.out.println("sizeof transaction: " + sizeOfTransaction); System.out.println("sizeof error: " + sizeOfError); - final int queueSize = MathUtils.getNextPowerOf2(new ReporterConfiguration().getMaxQueueSize()); + final int queueSize = MathUtils.getNextPowerOf2(new ReporterConfigurationImpl().getMaxQueueSize()); final long sizeOfObjectPools = queueSize * 2 * sizeOfSpan + queueSize * 2 * sizeOfTransaction + queueSize * sizeOfError; diff --git a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/objectpool/ObjectPoolBenchmark.java b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/objectpool/ObjectPoolBenchmark.java index d1742cf30a..43850b3d1e 100644 --- a/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/objectpool/ObjectPoolBenchmark.java +++ b/apm-agent-benchmarks/src/main/java/co/elastic/apm/agent/benchmark/objectpool/ObjectPoolBenchmark.java @@ -21,8 +21,8 @@ import co.elastic.apm.agent.benchmark.AbstractBenchmark; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; import co.elastic.apm.agent.objectpool.impl.ThreadLocalObjectPool; import org.agrona.concurrent.ManyToManyConcurrentArrayQueue; @@ -45,11 +45,11 @@ public class ObjectPoolBenchmark extends AbstractBenchmark { private ElasticApmTracer tracer; - private ObjectPool blockingQueueObjectPool; - private ObjectPool agronaQueueObjectPool; - private ObjectPool threadLocalObjectPool; - private ObjectPool jctoolsQueueObjectPool; - private ObjectPool jctoolsAtomicQueueObjectPool; + private ObservableObjectPool blockingQueueObjectPool; + private ObservableObjectPool agronaQueueObjectPool; + private ObservableObjectPool threadLocalObjectPool; + private ObservableObjectPool jctoolsQueueObjectPool; + private ObservableObjectPool jctoolsAtomicQueueObjectPool; public static void main(String[] args) throws RunnerException { run(ObjectPoolBenchmark.class); @@ -58,11 +58,11 @@ public static void main(String[] args) throws RunnerException { @Setup public void setUp() { tracer = new ElasticApmTracerBuilder().buildAndStart(); - blockingQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new ArrayBlockingQueue<>(256), true, () -> new Transaction(tracer)); - jctoolsQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new MpmcArrayQueue<>(256), true, () -> new Transaction(tracer)); - jctoolsAtomicQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue<>(256), true, () -> new Transaction(tracer)); - agronaQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new ManyToManyConcurrentArrayQueue<>(256), true, () -> new Transaction(tracer)); - threadLocalObjectPool = new ThreadLocalObjectPool<>(64, true, () -> new Transaction(tracer)); + blockingQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new ArrayBlockingQueue<>(256), true, () -> new TransactionImpl(tracer)); + jctoolsQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new MpmcArrayQueue<>(256), true, () -> new TransactionImpl(tracer)); + jctoolsAtomicQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue<>(256), true, () -> new TransactionImpl(tracer)); + agronaQueueObjectPool = QueueBasedObjectPool.ofRecyclable(new ManyToManyConcurrentArrayQueue<>(256), true, () -> new TransactionImpl(tracer)); + threadLocalObjectPool = new ThreadLocalObjectPool<>(64, true, () -> new TransactionImpl(tracer)); } @TearDown @@ -72,46 +72,46 @@ public void tearDown() { // @Benchmark @Threads(8) - public Transaction testNewOperator() { - return new Transaction(tracer); + public TransactionImpl testNewOperator() { + return new TransactionImpl(tracer); } @Benchmark @Threads(8) - public Transaction testJctoolsAtomicQueueObjectPool() { - Transaction transaction = jctoolsAtomicQueueObjectPool.createInstance(); + public TransactionImpl testJctoolsAtomicQueueObjectPool() { + TransactionImpl transaction = jctoolsAtomicQueueObjectPool.createInstance(); jctoolsAtomicQueueObjectPool.recycle(transaction); return transaction; } // @Benchmark @Threads(8) - public Transaction testArgonaQueueObjectPool() { - Transaction transaction = agronaQueueObjectPool.createInstance(); + public TransactionImpl testArgonaQueueObjectPool() { + TransactionImpl transaction = agronaQueueObjectPool.createInstance(); agronaQueueObjectPool.recycle(transaction); return transaction; } @Benchmark @Threads(8) - public Transaction testJctoolsQueueObjectPool() { - Transaction transaction = jctoolsQueueObjectPool.createInstance(); + public TransactionImpl testJctoolsQueueObjectPool() { + TransactionImpl transaction = jctoolsQueueObjectPool.createInstance(); jctoolsQueueObjectPool.recycle(transaction); return transaction; } //@Benchmark @Threads(8) - public Transaction testBlockingQueueObjectPool() { - Transaction transaction = blockingQueueObjectPool.createInstance(); + public TransactionImpl testBlockingQueueObjectPool() { + TransactionImpl transaction = blockingQueueObjectPool.createInstance(); blockingQueueObjectPool.recycle(transaction); return transaction; } // @Benchmark @Threads(8) - public Transaction testThreadLocalObjectPool() { - Transaction transaction = threadLocalObjectPool.createInstance(); + public TransactionImpl testThreadLocalObjectPool() { + TransactionImpl transaction = threadLocalObjectPool.createInstance(); threadLocalObjectPool.recycle(transaction); return transaction; } diff --git a/apm-agent-bootstrap/pom.xml b/apm-agent-bootstrap/pom.xml index dbfc584ac0..ecc5bcec1e 100644 --- a/apm-agent-bootstrap/pom.xml +++ b/apm-agent-bootstrap/pom.xml @@ -5,7 +5,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 apm-agent-bootstrap diff --git a/apm-agent-builds/apm-agent-java8/pom.xml b/apm-agent-builds/apm-agent-java8/pom.xml index f7a5443d78..59a1a5fc3f 100644 --- a/apm-agent-builds/apm-agent-java8/pom.xml +++ b/apm-agent-builds/apm-agent-java8/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-agent-builds - 1.50.0 + 1.51.0 apm-agent-java8 diff --git a/apm-agent-builds/apm-agent/pom.xml b/apm-agent-builds/apm-agent/pom.xml index 5761479578..0b7dd8d4b2 100644 --- a/apm-agent-builds/apm-agent/pom.xml +++ b/apm-agent-builds/apm-agent/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-agent-builds - 1.50.0 + 1.51.0 apm-agent diff --git a/apm-agent-builds/apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporter.java b/apm-agent-builds/apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporter.java index 811054c294..c446b7d6b6 100644 --- a/apm-agent-builds/apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporter.java +++ b/apm-agent-builds/apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporter.java @@ -20,7 +20,6 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; import org.stagemonitor.configuration.ConfigurationOptionProvider; import org.stagemonitor.configuration.ConfigurationRegistry; @@ -39,7 +38,7 @@ public class ConfigurationExporter { public static void main(String[] args) throws Exception { ElasticApmTracer tracer = mock(ElasticApmTracer.class); doReturn(tracer).when(tracer).require(ElasticApmTracer.class); - doReturn(Tracer.TracerState.UNINITIALIZED).when(tracer).getState(); + doReturn(ElasticApmTracer.TracerState.UNINITIALIZED).when(tracer).getState(); GlobalTracer.init(tracer); try { ConfigurationRegistry configurationRegistry = ConfigurationRegistry.builder() diff --git a/apm-agent-builds/apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporterTest.java b/apm-agent-builds/apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporterTest.java index 162fd1155d..dca098e68e 100644 --- a/apm-agent-builds/apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporterTest.java +++ b/apm-agent-builds/apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporterTest.java @@ -21,7 +21,6 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.util.DependencyInjectingServiceLoader; import freemarker.template.Configuration; @@ -89,7 +88,7 @@ void setUp() { renderedDocumentationPath = Paths.get("../../docs/configuration.asciidoc"); ElasticApmTracer tracer = mock(ElasticApmTracer.class); doReturn(tracer).when(tracer).require(ElasticApmTracer.class); - doReturn(Tracer.TracerState.UNINITIALIZED).when(tracer).getState(); + doReturn(ElasticApmTracer.TracerState.UNINITIALIZED).when(tracer).getState(); GlobalTracer.init(tracer); configurationRegistry = ConfigurationRegistry.builder() .optionProviders(ServiceLoader.load(ConfigurationOptionProvider.class)) diff --git a/apm-agent-builds/pom.xml b/apm-agent-builds/pom.xml index aa69f9b148..0029da24a6 100644 --- a/apm-agent-builds/pom.xml +++ b/apm-agent-builds/pom.xml @@ -3,7 +3,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-cached-lookup-key/pom.xml b/apm-agent-cached-lookup-key/pom.xml index b9eb3d3a37..ae1c75e499 100644 --- a/apm-agent-cached-lookup-key/pom.xml +++ b/apm-agent-cached-lookup-key/pom.xml @@ -3,7 +3,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-common/pom.xml b/apm-agent-common/pom.xml index e03f5175f2..57cfb78bd2 100644 --- a/apm-agent-common/pom.xml +++ b/apm-agent-common/pom.xml @@ -3,7 +3,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-common/src/main/java/co/elastic/apm/agent/common/JvmRuntimeInfo.java b/apm-agent-common/src/main/java/co/elastic/apm/agent/common/JvmRuntimeInfo.java index 521659f9ce..d1b905b95a 100644 --- a/apm-agent-common/src/main/java/co/elastic/apm/agent/common/JvmRuntimeInfo.java +++ b/apm-agent-common/src/main/java/co/elastic/apm/agent/common/JvmRuntimeInfo.java @@ -25,7 +25,8 @@ public class JvmRuntimeInfo { private static final JvmRuntimeInfo CURRENT_VM = new JvmRuntimeInfo(System.getProperty("java.version"), - System.getProperty("java.vm.name"), System.getProperty("java.vendor"), System.getProperty("java.vm.version")); + System.getProperty("java.vm.name"), System.getProperty("java.vendor"), System.getProperty("java.vm.version"), + System.getProperty("os.name")); private final String javaVersion; private final String javaVmName; @@ -37,6 +38,7 @@ public class JvmRuntimeInfo { private final boolean isJ9; private final boolean isHpUx; private final boolean isCoretto; + private final boolean isZos; public static JvmRuntimeInfo ofCurrentVM() { return CURRENT_VM; @@ -52,6 +54,10 @@ public static JvmRuntimeInfo ofCurrentVM() { * @param vmVersion jvm version, from {@code System.getProperty("java.vm.version")} */ public JvmRuntimeInfo(String version, String vmName, String vendorName, @Nullable String vmVersion) { + this(version, vmName, vendorName, vmVersion, null); + } + + private JvmRuntimeInfo(String version, String vmName, String vendorName, @Nullable String vmVersion, @Nullable String osName) { javaVersion = version; javaVmName = vmName; javaVmVersion = vmVersion; @@ -61,6 +67,7 @@ public JvmRuntimeInfo(String version, String vmName, String vendorName, @Nullabl isJ9 = vmName.contains("J9"); isHpUx = version.endsWith("-hp-ux"); isCoretto = vendorName != null && vendorName.contains("Amazon"); + isZos = (osName != null) && osName.toLowerCase().contains("z/os"); if (isHpUx) { // remove extra hp-ux suffix for parsing @@ -162,6 +169,10 @@ public boolean isCoretto() { return isCoretto; } + public boolean isZos() { + return isZos; + } + @Override public String toString() { return String.format("%s %s %s", javaVersion, javaVmName, javaVmVersion); diff --git a/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/ResourceExtractionUtil.java b/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/ResourceExtractionUtil.java index 9cfec464ab..fcb4177ad3 100644 --- a/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/ResourceExtractionUtil.java +++ b/apm-agent-common/src/main/java/co/elastic/apm/agent/common/util/ResourceExtractionUtil.java @@ -18,6 +18,8 @@ */ package co.elastic.apm.agent.common.util; +import co.elastic.apm.agent.common.JvmRuntimeInfo; + import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; @@ -99,7 +101,9 @@ public static synchronized Path extractResourceToDirectory(String resource, Stri } } } catch (FileAlreadyExistsException e) { - try (FileChannel channel = FileChannel.open(tempFile, READ, NOFOLLOW_LINKS)) { + try (FileChannel channel = JvmRuntimeInfo.ofCurrentVM().isZos() ? + FileChannel.open(tempFile, READ) : + FileChannel.open(tempFile, READ, NOFOLLOW_LINKS)) { // wait until other JVM instances have fully written the file // multiple JVMs can read the file at the same time try (FileLock readLock = channel.lock(0, Long.MAX_VALUE, true)) { diff --git a/apm-agent-core/README.md b/apm-agent-core/README.md index d2c704efd0..470b964141 100644 --- a/apm-agent-core/README.md +++ b/apm-agent-core/README.md @@ -19,7 +19,7 @@ It's based on a Disruptor/ring buffer and receives finished transactions potenti The ring buffer decouples the transaction-producing threads from the co.elastic.apm.agent.report.ReportingEventHandler, which is single-threaded and sends the transactions to the APM server via HTTP. -The class co.elastic.apm.agent.report.ReporterConfiguration contains all relevant configuration options for the reporter. +The class co.elastic.apm.agent.report.ReporterConfigurationImpl contains all relevant configuration options for the reporter. ## Lifecycle diff --git a/apm-agent-core/pom.xml b/apm-agent-core/pom.xml index 69bce0515f..db09a71f45 100644 --- a/apm-agent-core/pom.xml +++ b/apm-agent-core/pom.xml @@ -5,7 +5,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 apm-agent-core @@ -56,7 +56,7 @@ org.jctools jctools-core - 4.0.3 + 4.0.5 com.googlecode.concurrentlinkedhashmap diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java index d0c7a468c4..9f60cf3363 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/ElasticApmAgent.java @@ -34,10 +34,9 @@ import co.elastic.apm.agent.bci.modules.ModuleOpener; import co.elastic.apm.agent.common.ThreadUtils; import co.elastic.apm.agent.common.util.SystemStandardOutputLogger; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; -import co.elastic.apm.agent.impl.Tracer; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.logging.ApmServerLogAppender; import co.elastic.apm.agent.matcher.MethodMatcher; @@ -153,7 +152,7 @@ public static void initialize(@Nullable final String agentArguments, final Instr // silently early abort when agent is disabled to minimize the number of loaded classes List configSources = ElasticApmTracerBuilder.getConfigSources(agentArguments, premain); for (ConfigurationSource configSource : configSources) { - String enabled = configSource.getValue(CoreConfiguration.ENABLED_KEY); + String enabled = configSource.getValue(CoreConfigurationImpl.ENABLED_KEY); if (enabled != null && !Boolean.parseBoolean(enabled)) { return; } @@ -172,7 +171,7 @@ public static void initInstrumentation(ElasticApmTracer tracer, Instrumentation } private static void initInstrumentation(ElasticApmTracer tracer, Instrumentation instrumentation, boolean premain) { - if (!tracer.getConfig(CoreConfiguration.class).isEnabled()) { + if (!tracer.getConfig(CoreConfigurationImpl.class).isEnabled()) { return; } GlobalTracer.init(tracer); @@ -181,12 +180,12 @@ private static void initInstrumentation(ElasticApmTracer tracer, Instrumentation } @Nonnull - private static Iterable loadInstrumentations(Tracer tracer) { + private static Iterable loadInstrumentations(ElasticApmTracer tracer) { List pluginClassLoaders = new ArrayList<>(); pluginClassLoaders.add(PrivilegedActionUtils.getClassLoader(ElasticApmAgent.class)); - pluginClassLoaders.addAll(createExternalPluginClassLoaders(tracer.getConfig(CoreConfiguration.class).getPluginsDir())); + pluginClassLoaders.addAll(createExternalPluginClassLoaders(tracer.getConfig(CoreConfigurationImpl.class).getPluginsDir())); final List instrumentations = DependencyInjectingServiceLoader.load(ElasticApmInstrumentation.class, pluginClassLoaders, tracer); - for (MethodMatcher traceMethod : tracer.getConfig(CoreConfiguration.class).getTraceMethods()) { + for (MethodMatcher traceMethod : tracer.getConfig(CoreConfigurationImpl.class).getTraceMethods()) { instrumentations.add(new TraceMethodInstrumentation(tracer, traceMethod)); } return instrumentations; @@ -234,7 +233,7 @@ public static synchronized void initInstrumentation(final ElasticApmTracer trace private static synchronized void initInstrumentation(final ElasticApmTracer tracer, Instrumentation instrumentation, Iterable instrumentations, boolean premain) { - CoreConfiguration coreConfig = tracer.getConfig(CoreConfiguration.class); + CoreConfigurationImpl coreConfig = tracer.getConfig(CoreConfigurationImpl.class); if (!coreConfig.isEnabled()) { return; } @@ -291,7 +290,7 @@ public void run() { AgentBuilder agentBuilder = initAgentBuilder(tracer, instrumentation, instrumentations, logger, AgentBuilder.DescriptionStrategy.Default.POOL_ONLY, premain); // Warmup Byte Buddy and agent's invokedynamic linkage paths on the attaching thread before installing it - if (tracer.getConfig(CoreConfiguration.class).shouldWarmupByteBuddy()) { + if (tracer.getConfig(CoreConfigurationImpl.class).shouldWarmupByteBuddy()) { agentBuilder = agentBuilder.with(new InstallationListenerImpl()) .warmUp(NonInstrumented.class) .warmUp(Instrumented.class); @@ -310,7 +309,7 @@ public void onChange(ConfigurationOption configurationOption, Object oldValue, O } public static synchronized Future reInitInstrumentation() { - final Tracer tracer = GlobalTracer.get().require(Tracer.class); + final ElasticApmTracer tracer = GlobalTracer.get().require(ElasticApmTracer.class); if (instrumentation == null) { throw new IllegalStateException("Can't re-init agent before it has been initialized"); } @@ -350,7 +349,7 @@ static synchronized void doReInitInstrumentation(Iterable instrumentations, Logger logger, AgentBuilder.DescriptionStrategy descriptionStrategy, boolean premain) { - final CoreConfiguration coreConfiguration = tracer.getConfig(CoreConfiguration.class); + final CoreConfigurationImpl coreConfiguration = tracer.getConfig(CoreConfigurationImpl.class); ElasticApmAgent.instrumentation = instrumentation; final ByteBuddy byteBuddy = new ByteBuddy() .with(TypeValidation.of(logger.isDebugEnabled())) @@ -378,11 +377,11 @@ private static AgentBuilder initAgentBuilder(ElasticApmTracer tracer, Instrument return agentBuilder; } - private static boolean isIncluded(ElasticApmInstrumentation advice, CoreConfiguration coreConfiguration) { + private static boolean isIncluded(ElasticApmInstrumentation advice, CoreConfigurationImpl coreConfiguration) { return isInstrumentationEnabled(advice, coreConfiguration) && coreConfiguration.isInstrumentationEnabled(advice.getInstrumentationGroupNames()); } - private static boolean isInstrumentationEnabled(ElasticApmInstrumentation advice, CoreConfiguration coreConfiguration) { + private static boolean isInstrumentationEnabled(ElasticApmInstrumentation advice, CoreConfigurationImpl coreConfiguration) { return advice.includeWhenInstrumentationIsDisabled() || coreConfiguration.isInstrument(); } @@ -390,8 +389,8 @@ private static AgentBuilder applyAdvice(final ElasticApmTracer tracer, final Age final ElasticApmInstrumentation instrumentation, final ElementMatcher typeMatcher) { final Logger logger = getLogger(); logger.debug("Applying instrumentation {}", instrumentation.getClass().getName()); - final boolean classLoadingMatchingPreFilter = tracer.getConfig(CoreConfiguration.class).isClassLoadingMatchingPreFilter(); - final boolean typeMatchingWithNamePreFilter = tracer.getConfig(CoreConfiguration.class).isTypeMatchingWithNamePreFilter(); + final boolean classLoadingMatchingPreFilter = tracer.getConfig(CoreConfigurationImpl.class).isClassLoadingMatchingPreFilter(); + final boolean typeMatchingWithNamePreFilter = tracer.getConfig(CoreConfigurationImpl.class).isTypeMatchingWithNamePreFilter(); final ElementMatcher.Junction classLoaderMatcher = instrumentation.getClassLoaderMatcher(); final ElementMatcher typeMatcherPreFilter = instrumentation.getTypeMatcherPreFilter(); final ElementMatcher.Junction versionPostFilter = instrumentation.getProtectionDomainPostFilter(); @@ -648,7 +647,7 @@ public static synchronized void reset() { if (instrumentation == null) { return; } - GlobalTracer.get().require(Tracer.class).stop(); + GlobalTracer.get().require(ElasticApmTracer.class).stop(); GlobalTracer.setNoop(); Exception exception = null; if (resettableClassFileTransformer != null) { @@ -678,7 +677,7 @@ public static synchronized void reset() { pluginPackages2pluginClassLoaderCustomizations.clear(); } - private static AgentBuilder getAgentBuilder(final ByteBuddy byteBuddy, final CoreConfiguration coreConfiguration, final Logger logger, + private static AgentBuilder getAgentBuilder(final ByteBuddy byteBuddy, final CoreConfigurationImpl coreConfiguration, final Logger logger, final AgentBuilder.DescriptionStrategy descriptionStrategy, final boolean premain, final boolean useTypePoolCache) { AgentBuilder.LocationStrategy locationStrategy = AgentBuilder.LocationStrategy.ForClassLoader.WEAK; @@ -826,7 +825,7 @@ private static void applyInstrumentation(Class classToInstrument, Collection< appliedInstrumentations = Collections.unmodifiableSet(appliedInstrumentations); dynamicallyInstrumentedClasses.put(classToInstrument, appliedInstrumentations); - CoreConfiguration config = tracer.getConfig(CoreConfiguration.class); + CoreConfigurationImpl config = tracer.getConfig(CoreConfigurationImpl.class); final Logger logger = LoggerFactory.getLogger(ElasticApmAgent.class); final ByteBuddy byteBuddy = new ByteBuddy() .with(TypeValidation.of(logger.isDebugEnabled())) diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/ErrorLoggingListener.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/ErrorLoggingListener.java index 4428669786..536b3b10eb 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/ErrorLoggingListener.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/bytebuddy/ErrorLoggingListener.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.bci.bytebuddy; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import net.bytebuddy.agent.builder.AgentBuilder; import net.bytebuddy.utility.JavaModule; import co.elastic.apm.agent.sdk.logging.Logger; @@ -35,7 +35,7 @@ public void onError(String typeName, ClassLoader classLoader, JavaModule module, "You may try setting the '{}' config option to 'true', but notice that it may cause VerificationErrors or other issues.", typeName, ((MinimumClassFileVersionValidator.UnsupportedClassFileVersionException)throwable).getMinVersion(), - CoreConfiguration.INSTRUMENT_ANCIENT_BYTECODE + CoreConfigurationImpl.INSTRUMENT_ANCIENT_BYTECODE ); } else { if (throwable instanceof net.bytebuddy.pool.TypePool.Resolution.NoSuchTypeException) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/ExternalPluginClassLoader.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/ExternalPluginClassLoader.java index 6fa9107f7d..4de316323f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/ExternalPluginClassLoader.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/bci/classloading/ExternalPluginClassLoader.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.bci.classloading; import co.elastic.apm.agent.common.util.AgentInfo; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -38,7 +38,7 @@ import static net.bytebuddy.matcher.ElementMatchers.not; /** - * Loads plugins from {@link CoreConfiguration#getPluginsDir() plugins_dir} + * Loads plugins from {@link CoreConfigurationImpl#getPluginsDir() plugins_dir} * * @see co.elastic.apm.agent.bci.IndyBootstrap */ diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSource.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSource.java index 0f63ac2d0c..09c54e7458 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSource.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSource.java @@ -160,7 +160,7 @@ private void pollConfig(ConfigurationRegistry configurationRegistry) { */ @Nullable String fetchConfig(final ConfigurationRegistry configurationRegistry) { - if (!configurationRegistry.getConfig(CoreConfiguration.class).isCentralConfigEnabled()) { + if (!configurationRegistry.getConfig(CoreConfigurationImpl.class).isCentralConfigEnabled()) { logger.debug("Remote configuration is disabled"); return null; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfigurationImpl.java similarity index 98% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfiguration.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfigurationImpl.java index b84f4bd172..7c42ebc23e 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfigurationImpl.java @@ -20,17 +20,12 @@ import co.elastic.apm.agent.bci.ElasticApmAgent; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.matcher.MethodMatcher; import co.elastic.apm.agent.matcher.MethodMatcherValueConverter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; -import co.elastic.apm.agent.tracer.configuration.ListValueConverter; -import co.elastic.apm.agent.tracer.configuration.RegexValidator; -import co.elastic.apm.agent.tracer.configuration.RoundedDoubleConverter; -import co.elastic.apm.agent.tracer.configuration.TimeDuration; -import co.elastic.apm.agent.tracer.configuration.TimeDurationValueConverter; -import co.elastic.apm.agent.tracer.configuration.WildcardMatcherValueConverter; +import co.elastic.apm.agent.tracer.configuration.*; import org.stagemonitor.configuration.ConfigurationOption; import org.stagemonitor.configuration.ConfigurationOptionProvider; import org.stagemonitor.configuration.converter.AbstractValueConverter; @@ -56,10 +51,10 @@ import java.util.Set; import java.util.concurrent.TimeUnit; -import static co.elastic.apm.agent.logging.LoggingConfiguration.AGENT_HOME_PLACEHOLDER; +import static co.elastic.apm.agent.logging.LoggingConfigurationImpl.AGENT_HOME_PLACEHOLDER; import static co.elastic.apm.agent.tracer.configuration.RangeValidator.isInRange; -public class CoreConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.agent.tracer.configuration.CoreConfiguration { +public class CoreConfigurationImpl extends ConfigurationOptionProvider implements CoreConfiguration { public static final int DEFAULT_LONG_FIELD_MAX_LENGTH = 10000; private final Logger logger = LoggerFactory.getLogger(getClass()); @@ -246,7 +241,7 @@ public class CoreConfiguration extends ConfigurationOptionProvider implements co .description("Limits the amount of spans that are recorded per transaction.\n\n" + "This is helpful in cases where a transaction creates a very high amount of spans (e.g. thousands of SQL queries).\n\n" + "Setting an upper limit will prevent overloading the agent and the APM server with too much work for such edge cases.\n\n" + - "A message will be logged when the max number of spans has been exceeded but only at a rate of once every " + TimeUnit.MICROSECONDS.toMinutes(Span.MAX_LOG_INTERVAL_MICRO_SECS) + " minutes to ensure performance is not impacted.") + "A message will be logged when the max number of spans has been exceeded but only at a rate of once every " + TimeUnit.MICROSECONDS.toMinutes(SpanImpl.MAX_LOG_INTERVAL_MICRO_SECS) + " minutes to ensure performance is not impacted.") .dynamic(true) .buildWithDefault(500); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/MetricsConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/MetricsConfigurationImpl.java similarity index 97% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/MetricsConfiguration.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/MetricsConfigurationImpl.java index 90c5ff563e..db67ada95f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/MetricsConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/MetricsConfigurationImpl.java @@ -19,6 +19,7 @@ package co.elastic.apm.agent.configuration; import co.elastic.apm.agent.tracer.configuration.ListValueConverter; +import co.elastic.apm.agent.tracer.configuration.MetricsConfiguration; import org.stagemonitor.configuration.ConfigurationOption; import org.stagemonitor.configuration.ConfigurationOptionProvider; import org.stagemonitor.configuration.converter.DoubleValueConverter; @@ -29,7 +30,7 @@ import java.util.HashSet; import java.util.List; -public class MetricsConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.agent.tracer.configuration.MetricsConfiguration { +public class MetricsConfigurationImpl extends ConfigurationOptionProvider implements MetricsConfiguration { private static final String METRICS_CATEGORY = "Metrics"; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServerlessConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServerlessConfigurationImpl.java similarity index 92% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServerlessConfiguration.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServerlessConfigurationImpl.java index 36875fbf04..6df65ad344 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServerlessConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/ServerlessConfigurationImpl.java @@ -19,15 +19,16 @@ package co.elastic.apm.agent.configuration; import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils; +import co.elastic.apm.agent.tracer.configuration.ServerlessConfiguration; import org.stagemonitor.configuration.ConfigurationOption; import org.stagemonitor.configuration.ConfigurationOptionProvider; -public class ServerlessConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.agent.tracer.configuration.ServerlessConfiguration { +public class ServerlessConfigurationImpl extends ConfigurationOptionProvider implements ServerlessConfiguration { public static final String SERVERLESS_CATEGORY = "Serverless"; private final boolean runsOnAwsLambda; - public ServerlessConfiguration() { + public ServerlessConfigurationImpl() { String lambdaName = PrivilegedActionUtils.getEnv("AWS_LAMBDA_FUNCTION_NAME"); this.runsOnAwsLambda = null != lambdaName && !lambdaName.isEmpty(); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/StartupInfo.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/StartupInfo.java index 4de8761af2..b2bb9e1c21 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/StartupInfo.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/StartupInfo.java @@ -22,7 +22,7 @@ import co.elastic.apm.agent.tracer.configuration.TimeDuration; import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; import co.elastic.apm.agent.util.VersionUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -63,8 +63,8 @@ public void init(Tracer tracer) { } void logConfiguration(ConfigurationRegistry configurationRegistry, Logger logger) { - final String serviceName = configurationRegistry.getConfig(CoreConfiguration.class).getServiceName(); - final String serviceVersion = configurationRegistry.getConfig(CoreConfiguration.class).getServiceVersion(); + final String serviceName = configurationRegistry.getConfig(CoreConfigurationImpl.class).getServiceName(); + final String serviceVersion = configurationRegistry.getConfig(CoreConfigurationImpl.class).getServiceVersion(); StringBuilder serviceNameAndVersion = new StringBuilder(serviceName); if (serviceVersion != null) { @@ -87,9 +87,9 @@ void logConfiguration(ConfigurationRegistry configurationRegistry, Logger logger } } } - if (configurationRegistry.getConfig(StacktraceConfiguration.class).getApplicationPackages().isEmpty()) { + if (configurationRegistry.getConfig(StacktraceConfigurationImpl.class).getApplicationPackages().isEmpty()) { logger.warn("To enable all features and decrease startup time, please configure {}", - StacktraceConfiguration.APPLICATION_PACKAGES); + StacktraceConfigurationImpl.APPLICATION_PACKAGES); } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ActivationListener.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ActivationListener.java index 4461a537e9..25e522b578 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ActivationListener.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ActivationListener.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.impl; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; /** - * A callback for {@link AbstractSpan} activation and deactivation events + * A callback for {@link AbstractSpanImpl} activation and deactivation events *

* The constructor can optionally have a {@link ElasticApmTracer} parameter. *

@@ -29,22 +29,22 @@ public interface ActivationListener { /** - * A callback for {@link AbstractSpan#activate()} + * A callback for {@link AbstractSpanImpl#activate()} * - * @param span the {@link AbstractSpan} that is being activated + * @param span the {@link AbstractSpanImpl} that is being activated * @throws Throwable if there was an error while calling this method */ - void beforeActivate(AbstractSpan span) throws Throwable; + void beforeActivate(AbstractSpanImpl span) throws Throwable; /** - * A callback for {@link AbstractSpan#deactivate()} + * A callback for {@link AbstractSpanImpl#deactivate()} *

- * Note: the corresponding span may already be {@link AbstractSpan#end() ended} and {@link AbstractSpan#resetState() recycled}. - * That's why there is no {@link AbstractSpan} parameter. + * Note: the corresponding span may already be {@link AbstractSpanImpl#end() ended} and {@link AbstractSpanImpl#resetState() recycled}. + * That's why there is no {@link AbstractSpanImpl} parameter. *

* * @param deactivatedSpan the context that has just been deactivated * @throws Throwable if there was an error while calling this method */ - void afterDeactivate(AbstractSpan deactivatedSpan) throws Throwable; + void afterDeactivate(AbstractSpanImpl deactivatedSpan) throws Throwable; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ActiveStack.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ActiveStack.java index e0d421b4f0..7bce0fef45 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ActiveStack.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ActiveStack.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.impl; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; -import co.elastic.apm.agent.impl.transaction.ElasticContextWrapper; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; +import co.elastic.apm.agent.impl.transaction.TraceStateWrapper; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -55,11 +55,11 @@ class ActiveStack { * Also, the caller does not have to keep a reference to the previously active span, as that is maintained by the stack. * This makes activating a span allocation-free (assuming the stack has enough pre-allocated slots available). */ - private final Deque> activeContextStack = new ArrayDeque>(); + private final Deque> activeContextStack = new ArrayDeque>(); - private final EmptyElasticContext emptyContext; + private final EmptyTraceState emptyContext; - ActiveStack(int stackMaxDepth, EmptyElasticContext emptyContextForTracer) { + ActiveStack(int stackMaxDepth, EmptyTraceState emptyContextForTracer) { this.stackMaxDepth = stackMaxDepth; this.emptyContext = emptyContextForTracer; } @@ -68,18 +68,18 @@ class ActiveStack { * @return the current context, potentially empty when no span, transaction or baggage is currently active. */ - public ElasticContext currentContext() { - ElasticContext current = activeContextStack.peek(); + public TraceStateImpl currentContext() { + TraceStateImpl current = activeContextStack.peek(); // When the active context is wrapped, the wrapper should be transparent to the caller, thus we always return // the underlying wrapped context. - if (current instanceof ElasticContextWrapper) { - return ((ElasticContextWrapper) current).getWrappedContext(); + if (current instanceof TraceStateWrapper) { + return ((TraceStateWrapper) current).getWrappedContext(); } return current != null ? current : emptyContext; } - boolean activate(ElasticContext context, List activationListeners) { + boolean activate(TraceStateImpl context, List activationListeners) { if (logger.isDebugEnabled()) { logger.debug("Activating {} on thread {}", context, Thread.currentThread().getId()); } @@ -96,7 +96,7 @@ boolean activate(ElasticContext context, List activationL } context.incrementReferences(); - AbstractSpan span = context.getSpan(); + AbstractSpanImpl span = context.getSpan(); if (span != null) { triggerActivationListeners(span, true, activationListeners); } @@ -105,7 +105,7 @@ boolean activate(ElasticContext context, List activationL return true; } - boolean deactivate(ElasticContext context, List activationListeners, boolean assertionsEnabled) { + boolean deactivate(TraceStateImpl context, List activationListeners, boolean assertionsEnabled) { if (logger.isDebugEnabled()) { logger.debug("Deactivating {} on thread {}", context, Thread.currentThread().getId()); } @@ -115,13 +115,13 @@ boolean deactivate(ElasticContext context, List activatio return false; } - ElasticContext activeContext = currentContext(); + TraceStateImpl activeContext = currentContext(); activeContextStack.remove(); try { assertIsActive(context, activeContext, assertionsEnabled); - AbstractSpan span = context.getSpan(); + AbstractSpanImpl span = context.getSpan(); if (null != span) { triggerActivationListeners(span, false, activationListeners); } @@ -131,7 +131,7 @@ boolean deactivate(ElasticContext context, List activatio return true; } - private void triggerActivationListeners(AbstractSpan span, boolean isActivate, List activationListeners) { + private void triggerActivationListeners(AbstractSpanImpl span, boolean isActivate, List activationListeners) { for (int i = 0, size = activationListeners.size(); i < size; i++) { ActivationListener listener = activationListeners.get(i); try { @@ -149,7 +149,7 @@ private void triggerActivationListeners(AbstractSpan span, boolean isActivate } } - private void assertIsActive(ElasticContext context, @Nullable ElasticContext currentlyActive, boolean assertionsEnabled) { + private void assertIsActive(TraceStateImpl context, @Nullable TraceStateImpl currentlyActive, boolean assertionsEnabled) { if (context != currentlyActive) { logger.warn("Deactivating a context ({}) which is not the currently active one ({}). " + "This can happen when not properly deactivating a previous span or context.", context, currentlyActive); @@ -169,17 +169,17 @@ private void assertIsActive(ElasticContext context, @Nullable ElasticContext< * @param wrapper type * @return newly (or previously) created wrapper */ - > T wrapActiveContextIfRequired(Class wrapperClass, Callable wrapFunction, int approximateContextSize) { + > T wrapActiveContextIfRequired(Class wrapperClass, Callable wrapFunction, int approximateContextSize) { // the current context might be either a "regular" one or a "wrapped" one if it has already been wrapped - ElasticContext current = activeContextStack.peek(); + TraceStateImpl current = activeContextStack.peek(); Objects.requireNonNull(current, "active context required for wrapping"); - ElasticContextWrapper wrapper; - if (current instanceof ElasticContextWrapper) { - wrapper = (ElasticContextWrapper) current; + TraceStateWrapper wrapper; + if (current instanceof TraceStateWrapper) { + wrapper = (TraceStateWrapper) current; } else { - wrapper = new ElasticContextWrapper<>(approximateContextSize, current); + wrapper = new TraceStateWrapper<>(approximateContextSize, current); } T wrapped = wrapper.wrapIfRequired(wrapperClass, wrapFunction); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java index 893dfb6c69..a675010497 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java @@ -25,17 +25,18 @@ import co.elastic.apm.agent.common.JvmRuntimeInfo; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.configuration.AutoDetectedServiceInfo; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.MetricsConfiguration; -import co.elastic.apm.agent.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; +import co.elastic.apm.agent.configuration.ServerlessConfigurationImpl; import co.elastic.apm.agent.impl.error.RedactedException; import co.elastic.apm.agent.impl.metadata.FaaSMetaDataExtension; import co.elastic.apm.agent.impl.metadata.Framework; import co.elastic.apm.agent.impl.metadata.MetaDataFuture; import co.elastic.apm.agent.impl.metadata.NameAndIdField; import co.elastic.apm.agent.impl.metadata.ServiceFactory; -import co.elastic.apm.agent.impl.transaction.Id; +import co.elastic.apm.agent.impl.transaction.*; import co.elastic.apm.agent.sdk.internal.util.LoggerUtils; +import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.tracer.pooling.Allocator; @@ -44,24 +45,19 @@ import co.elastic.apm.agent.configuration.SpanConfiguration; import co.elastic.apm.agent.context.ClosableLifecycleListenerAdapter; import co.elastic.apm.agent.tracer.LifecycleListener; -import co.elastic.apm.agent.impl.baggage.Baggage; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; import co.elastic.apm.agent.impl.baggage.W3CBaggagePropagation; -import co.elastic.apm.agent.impl.error.ErrorCapture; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.impl.sampling.ProbabilitySampler; import co.elastic.apm.agent.impl.sampling.Sampler; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.logging.LoggingConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.logging.LoggingConfigurationImpl; import co.elastic.apm.agent.metrics.MetricRegistry; -import co.elastic.apm.agent.objectpool.ObjectPool; -import co.elastic.apm.agent.objectpool.ObjectPoolFactory; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; +import co.elastic.apm.agent.objectpool.ObjectPoolFactoryImpl; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.report.Reporter; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils; import co.elastic.apm.agent.sdk.internal.util.VersionUtils; import co.elastic.apm.agent.sdk.logging.Logger; @@ -116,7 +112,7 @@ public class ElasticApmTracer implements Tracer { static { Set headerNames = new HashSet<>(); - headerNames.addAll(TraceContext.TRACE_TEXTUAL_HEADERS); + headerNames.addAll(TraceContextImpl.TRACE_TEXTUAL_HEADERS); headerNames.add(W3CBaggagePropagation.BAGGAGE_HEADER_NAME); TRACE_HEADER_NAMES = Collections.unmodifiableSet(headerNames); } @@ -126,15 +122,15 @@ public class ElasticApmTracer implements Tracer { private final ConfigurationRegistry configurationRegistry; private final ApmServerClient apmServerClient; private final List lifecycleListeners = new CopyOnWriteArrayList<>(); - private final ObjectPool transactionPool; - private final ObjectPool spanPool; - private final ObjectPool errorPool; - private final ObjectPool spanLinkPool; - private final ObjectPool profilingCorrelationStackTraceIdPool; + private final ObservableObjectPool transactionPool; + private final ObservableObjectPool spanPool; + private final ObservableObjectPool errorPool; + private final ObservableObjectPool spanLinkPool; + private final ObservableObjectPool profilingCorrelationStackTraceIdPool; private final Reporter reporter; - private final ObjectPoolFactory objectPoolFactory; + private final ObjectPoolFactoryImpl objectPoolFactory; - private final EmptyElasticContext emptyContext; + private final EmptyTraceState emptyContext; private final ThreadLocal activeStack = new ThreadLocal() { @Override @@ -146,7 +142,7 @@ protected ActiveStack initialValue() { } }; - private final CoreConfiguration coreConfiguration; + private final CoreConfigurationImpl coreConfiguration; private final int transactionMaxSpans; private final SpanConfiguration spanConfiguration; private final List activationListeners; @@ -172,12 +168,12 @@ protected ActiveStack initialValue() { static { checkClassloader(); - configs.put(co.elastic.apm.agent.tracer.configuration.CoreConfiguration.class, CoreConfiguration.class); - configs.put(co.elastic.apm.agent.tracer.configuration.LoggingConfiguration.class, LoggingConfiguration.class); - configs.put(co.elastic.apm.agent.tracer.configuration.MetricsConfiguration.class, MetricsConfiguration.class); - configs.put(co.elastic.apm.agent.tracer.configuration.ReporterConfiguration.class, ReporterConfiguration.class); - configs.put(co.elastic.apm.agent.tracer.configuration.ServerlessConfiguration.class, ServerlessConfiguration.class); - configs.put(co.elastic.apm.agent.tracer.configuration.StacktraceConfiguration.class, StacktraceConfiguration.class); + configs.put(co.elastic.apm.agent.tracer.configuration.CoreConfiguration.class, CoreConfigurationImpl.class); + configs.put(co.elastic.apm.agent.tracer.configuration.LoggingConfiguration.class, LoggingConfigurationImpl.class); + configs.put(co.elastic.apm.agent.tracer.configuration.MetricsConfiguration.class, MetricsConfigurationImpl.class); + configs.put(co.elastic.apm.agent.tracer.configuration.ReporterConfiguration.class, ReporterConfigurationImpl.class); + configs.put(co.elastic.apm.agent.tracer.configuration.ServerlessConfiguration.class, ServerlessConfigurationImpl.class); + configs.put(co.elastic.apm.agent.tracer.configuration.StacktraceConfiguration.class, StacktraceConfigurationImpl.class); } private static void checkClassloader() { @@ -219,17 +215,17 @@ private static void checkClassloader() { } - ElasticApmTracer(ConfigurationRegistry configurationRegistry, MetricRegistry metricRegistry, Reporter reporter, ObjectPoolFactory poolFactory, + ElasticApmTracer(ConfigurationRegistry configurationRegistry, MetricRegistry metricRegistry, Reporter reporter, ObjectPoolFactoryImpl poolFactory, ApmServerClient apmServerClient, final String ephemeralId, MetaDataFuture metaDataFuture) { - this.emptyContext = new EmptyElasticContext(this); + this.emptyContext = new EmptyTraceState(this); this.metricRegistry = metricRegistry; this.configurationRegistry = configurationRegistry; this.reporter = reporter; this.apmServerClient = apmServerClient; this.ephemeralId = ephemeralId; this.metaDataFuture = metaDataFuture; - int maxPooledElements = configurationRegistry.getConfig(ReporterConfiguration.class).getMaxQueueSize() * 2; - coreConfiguration = configurationRegistry.getConfig(CoreConfiguration.class); + int maxPooledElements = configurationRegistry.getConfig(ReporterConfigurationImpl.class).getMaxQueueSize() * 2; + coreConfiguration = configurationRegistry.getConfig(CoreConfigurationImpl.class); transactionMaxSpans = coreConfiguration.getTransactionMaxSpans(); spanConfiguration = configurationRegistry.getConfig(SpanConfiguration.class); @@ -250,12 +246,12 @@ public void onChange(ConfigurationOption configurationOption, Boolean oldValu errorPool = poolFactory.createErrorPool(maxPooledElements / 2, this); // span links pool allows for 10X the maximum allowed span links per span - spanLinkPool = poolFactory.createSpanLinkPool(AbstractSpan.MAX_ALLOWED_SPAN_LINKS * 10, this); + spanLinkPool = poolFactory.createSpanLinkPool(AbstractSpanImpl.MAX_ALLOWED_SPAN_LINKS * 10, this); - profilingCorrelationStackTraceIdPool = poolFactory.createRecyclableObjectPool(maxPooledElements, new Allocator() { + profilingCorrelationStackTraceIdPool = poolFactory.createRecyclableObjectPool(maxPooledElements, new Allocator() { @Override - public Id createInstance() { - return Id.new128BitId(); + public IdImpl createInstance() { + return IdImpl.new128BitId(); } }); @@ -283,32 +279,38 @@ public void onChange(ConfigurationOption configurationOption, Double oldValue @Override @Nullable - public Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader) { + public TransactionImpl startRootTransaction(@Nullable ClassLoader initiatingClassLoader) { return startRootTransaction(sampler, -1, currentContext().getBaggage(), initiatingClassLoader); } - @Override @Nullable - public Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader, long epochMicro) { + public TransactionImpl startRootTransaction(@Nullable ClassLoader initiatingClassLoader, long epochMicro) { return startRootTransaction(sampler, epochMicro, currentContext().getBaggage(), initiatingClassLoader); } @Nullable - @Override - public Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader, Baggage baseBaggage, long epochMicro) { + public TransactionImpl startRootTransaction(@Nullable ClassLoader initiatingClassLoader, BaggageImpl baseBaggage, long epochMicro) { return startRootTransaction(sampler, epochMicro, baseBaggage, initiatingClassLoader); } - @Nullable - public Transaction startRootTransaction(Sampler sampler, long epochMicros, @Nullable ClassLoader initiatingClassLoader) { + public TransactionImpl startRootTransaction(Sampler sampler, long epochMicros, @Nullable ClassLoader initiatingClassLoader) { return startRootTransaction(sampler, epochMicros, currentContext().getBaggage(), initiatingClassLoader); } - @Override + /** + * Starts a trace-root transaction with a specified sampler and start timestamp + * + * @param sampler the {@link Sampler} instance which is responsible for determining the sampling decision if this is a root transaction + * @param epochMicros the start timestamp + * @param initiatingClassLoader the class loader corresponding to the service which initiated the creation of the transaction. + * Used to determine the service name and to load application-scoped classes like the {@link org.slf4j.MDC}, + * for log correlation. + * @return a transaction that will be the root of the current trace if the agent is currently RUNNING; null otherwise + */ @Nullable - public Transaction startRootTransaction(Sampler sampler, long epochMicros, Baggage baseBaggage, @Nullable ClassLoader initiatingClassLoader) { - Transaction transaction = null; + public TransactionImpl startRootTransaction(Sampler sampler, long epochMicros, BaggageImpl baseBaggage, @Nullable ClassLoader initiatingClassLoader) { + TransactionImpl transaction = null; if (isRunning()) { transaction = createTransaction().startRoot(epochMicros, sampler, baseBaggage); afterTransactionStart(initiatingClassLoader, transaction); @@ -316,29 +318,40 @@ public Transaction startRootTransaction(Sampler sampler, long epochMicros, Bagga return transaction; } - @Override @Nullable - public Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter headersGetter, @Nullable ClassLoader initiatingClassLoader) { - return startChildTransaction(headerCarrier, headersGetter, sampler, -1, initiatingClassLoader); + public TransactionImpl startChildTransaction(@Nullable C headerCarrier, HeaderGetter headerGetter, @Nullable ClassLoader initiatingClassLoader) { + return startChildTransaction(headerCarrier, headerGetter, sampler, -1, initiatingClassLoader); } - @Override @Nullable - public Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter headersGetter, @Nullable ClassLoader initiatingClassLoader, Baggage baseBaggage, long epochMicros) { + public TransactionImpl startChildTransaction(@Nullable C headerCarrier, HeaderGetter headersGetter, @Nullable ClassLoader initiatingClassLoader, BaggageImpl baseBaggage, long epochMicros) { return startChildTransaction(headerCarrier, headersGetter, sampler, epochMicros, initiatingClassLoader); } - @Override + /** + * Starts a transaction as a child of the context headers obtained through the provided {@link HeaderGetter}. + * If the created transaction cannot be started as a child transaction (for example - if no parent context header is + * available), then it will be started as the root transaction of the trace. + * + * @param headerCarrier the Object from which context headers can be obtained, typically a request or a message + * @param headersGetter provides the trace context headers required in order to create a child transaction + * @param sampler the {@link Sampler} instance which is responsible for determining the sampling decision if this is a root transaction + * @param epochMicros the start timestamp + * @param initiatingClassLoader the class loader corresponding to the service which initiated the creation of the transaction. + * Used to determine the service name and to load application-scoped classes like the {@link org.slf4j.MDC}, + * for log correlation. + * @return a transaction which is a child of the provided parent if the agent is currently RUNNING; null otherwise + */ @Nullable - public Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter headersGetter, Sampler sampler, - long epochMicros, @Nullable ClassLoader initiatingClassLoader) { + public TransactionImpl startChildTransaction(@Nullable C headerCarrier, HeaderGetter headersGetter, Sampler sampler, + long epochMicros, @Nullable ClassLoader initiatingClassLoader) { return startChildTransaction(headerCarrier, headersGetter, sampler, epochMicros, currentContext().getBaggage(), initiatingClassLoader); } @Nullable - private Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter headersGetter, Sampler sampler, - long epochMicros, Baggage baseBaggage, @Nullable ClassLoader initiatingClassLoader) { - Transaction transaction = null; + private TransactionImpl startChildTransaction(@Nullable C headerCarrier, HeaderGetter headersGetter, Sampler sampler, + long epochMicros, BaggageImpl baseBaggage, @Nullable ClassLoader initiatingClassLoader) { + TransactionImpl transaction = null; if (isRunning()) { transaction = createTransaction().start(headerCarrier, headersGetter, epochMicros, sampler, baseBaggage); @@ -347,7 +360,7 @@ private Transaction startChildTransaction(@Nullable C headerCarrier, Head return transaction; } - private void afterTransactionStart(@Nullable ClassLoader initiatingClassLoader, Transaction transaction) { + private void afterTransactionStart(@Nullable ClassLoader initiatingClassLoader, TransactionImpl transaction) { if (logger.isDebugEnabled()) { logger.debug("startTransaction {}", transaction); if (logger.isTraceEnabled()) { @@ -362,12 +375,12 @@ private void afterTransactionStart(@Nullable ClassLoader initiatingClassLoader, profilingIntegration.afterTransactionStart(transaction); } - public Transaction noopTransaction() { + public TransactionImpl noopTransaction() { return createTransaction().startNoop(); } - private Transaction createTransaction() { - Transaction transaction = transactionPool.createInstance(); + private TransactionImpl createTransaction() { + TransactionImpl transaction = transactionPool.createInstance(); while (transaction.getReferenceCount() != 0) { logger.warn("Tried to start a transaction with a non-zero reference count {} {}", transaction.getReferenceCount(), transaction); transaction = transactionPool.createInstance(); @@ -377,14 +390,14 @@ private Transaction createTransaction() { @Override @Nullable - public Transaction currentTransaction() { + public TransactionImpl currentTransaction() { return currentContext().getTransaction(); } @Nullable @Override - public ErrorCapture getActiveError() { - return ErrorCapture.getActive(); + public ErrorCaptureImpl getActiveError() { + return ErrorCaptureImpl.getActive(); } /** @@ -408,12 +421,12 @@ public ErrorCapture getActiveError() { * @param the type of the parent context * @return a new started span */ - public Span startSpan(TraceContext.ChildContextCreator childContextCreator, T parentContext, Baggage baggage) { + public SpanImpl startSpan(TraceContextImpl.ChildContextCreator childContextCreator, T parentContext, BaggageImpl baggage) { return startSpan(childContextCreator, parentContext, baggage, -1); } - public Span startSpan(AbstractSpan parent, Baggage baggage, long epochMicros) { - return startSpan(TraceContext.fromParent(), parent, baggage, epochMicros); + public SpanImpl startSpan(AbstractSpanImpl parent, BaggageImpl baggage, long epochMicros) { + return startSpan(TraceContextImpl.fromParent(), parent, baggage, epochMicros); } /** @@ -421,12 +434,12 @@ public Span startSpan(AbstractSpan parent, Baggage baggage, long epochMicros) * @param epochMicros the start timestamp of the span in microseconds after epoch * @return a new started span */ - public Span startSpan(TraceContext.ChildContextCreator childContextCreator, T parentContext, Baggage baggage, long epochMicros) { + public SpanImpl startSpan(TraceContextImpl.ChildContextCreator childContextCreator, T parentContext, BaggageImpl baggage, long epochMicros) { return createSpan().start(childContextCreator, parentContext, baggage, epochMicros); } - private Span createSpan() { - Span span = spanPool.createInstance(); + private SpanImpl createSpan() { + SpanImpl span = spanPool.createInstance(); while (span.getReferenceCount() != 0) { logger.warn("Tried to start a span with a non-zero reference count {} {}", span.getReferenceCount(), span); span = spanPool.createInstance(); @@ -434,19 +447,17 @@ private Span createSpan() { return span; } - @Override public void captureAndReportException(@Nullable Throwable e, ClassLoader initiatingClassLoader) { - ErrorCapture errorCapture = captureException(System.currentTimeMillis() * 1000, e, currentContext(), initiatingClassLoader); + ErrorCaptureImpl errorCapture = captureException(System.currentTimeMillis() * 1000, e, currentContext(), initiatingClassLoader); if (errorCapture != null) { errorCapture.end(); } } - @Override @Nullable - public String captureAndReportException(long epochMicros, @Nullable Throwable e, ElasticContext parentContext) { + public String captureAndReportException(long epochMicros, @Nullable Throwable e, TraceStateImpl parentContext) { String id = null; - ErrorCapture errorCapture = captureException(epochMicros, e, parentContext, null); + ErrorCaptureImpl errorCapture = captureException(epochMicros, e, parentContext, null); if (errorCapture != null) { id = errorCapture.getTraceContext().getId().toString(); errorCapture.end(); @@ -454,20 +465,19 @@ public String captureAndReportException(long epochMicros, @Nullable Throwable e, return id; } - @Override @Nullable - public ErrorCapture captureException(@Nullable Throwable e, ElasticContext parentContext, @Nullable ClassLoader initiatingClassLoader) { + public ErrorCaptureImpl captureException(@Nullable Throwable e, TraceStateImpl parentContext, @Nullable ClassLoader initiatingClassLoader) { return captureException(System.currentTimeMillis() * 1000, e, parentContext, initiatingClassLoader); } @Nullable @Override - public ErrorCapture captureException(@Nullable Throwable e, @Nullable ClassLoader initiatingClassLoader) { + public ErrorCaptureImpl captureException(@Nullable Throwable e, @Nullable ClassLoader initiatingClassLoader) { return captureException(System.currentTimeMillis() * 1000, e, currentContext(), initiatingClassLoader); } @Nullable - private ErrorCapture captureException(long epochMicros, @Nullable Throwable e, ElasticContext parentContext, @Nullable ClassLoader initiatingClassLoader) { + private ErrorCaptureImpl captureException(long epochMicros, @Nullable Throwable e, TraceStateImpl parentContext, @Nullable ClassLoader initiatingClassLoader) { if (!isRunning() || e == null) { return null; } @@ -484,10 +494,10 @@ private ErrorCapture captureException(long epochMicros, @Nullable Throwable e, E // note: if we add inheritance support for exception filtering, caching would be required for performance if (e != null && !WildcardMatcher.isAnyMatch(coreConfiguration.getIgnoreExceptions(), e.getClass().getName())) { - ErrorCapture error = errorPool.createInstance(); + ErrorCaptureImpl error = errorPool.createInstance(); error.withTimestamp(epochMicros); error.setException(e); - Transaction currentTransaction = currentTransaction(); + TransactionImpl currentTransaction = currentTransaction(); if (currentTransaction != null) { if (currentTransaction.getNameForSerialization().length() > 0) { error.setTransactionName(currentTransaction.getNameForSerialization()); @@ -495,7 +505,7 @@ private ErrorCapture captureException(long epochMicros, @Nullable Throwable e, E error.setTransactionType(currentTransaction.getType()); error.setTransactionSampled(currentTransaction.isSampled()); } - AbstractSpan parent = parentContext.getSpan(); + AbstractSpanImpl parent = parentContext.getSpan(); if (parent != null) { error.asChildOf(parent); // don't discard spans leading up to an error, otherwise they'd point to an invalid parent @@ -508,7 +518,7 @@ private ErrorCapture captureException(long epochMicros, @Nullable Throwable e, E } } parentContext.getBaggage() - .storeBaggageInContext(error.getContext(), getConfig(CoreConfiguration.class).getBaggageToAttach()); + .storeBaggageInContext(error.getContext(), getConfig(CoreConfigurationImpl.class).getBaggageToAttach()); return error; } return null; @@ -533,7 +543,7 @@ public T getConfig(Class configProvider) { return configuration; } - public void endTransaction(Transaction transaction) { + public void endTransaction(TransactionImpl transaction) { if (logger.isDebugEnabled()) { logger.debug("endTransaction {}", transaction); if (logger.isTraceEnabled()) { @@ -551,11 +561,11 @@ public void endTransaction(Transaction transaction) { } } - public void reportPartialTransaction(Transaction transaction) { + public void reportPartialTransaction(TransactionImpl transaction) { reporter.reportPartialTransaction(transaction); } - public void endSpan(Span span) { + public void endSpan(SpanImpl span) { if (logger.isDebugEnabled()) { logger.debug("endSpan {}", span); if (logger.isTraceEnabled()) { @@ -564,7 +574,7 @@ public void endSpan(Span span) { } if (!span.isSampled()) { - Transaction transaction = span.getTransaction(); + TransactionImpl transaction = span.getTransaction(); if (transaction != null) { transaction.captureDroppedSpan(span); } @@ -584,7 +594,7 @@ public void endSpan(Span span) { } if (span.isDiscarded()) { logger.debug("Discarding span {}", span); - Transaction transaction = span.getTransaction(); + TransactionImpl transaction = span.getTransaction(); if (transaction != null) { transaction.captureDroppedSpan(span); } @@ -595,12 +605,12 @@ public void endSpan(Span span) { reportSpan(span); } - private void reportSpan(Span span) { - AbstractSpan parent = span.getParent(); + private void reportSpan(SpanImpl span) { + AbstractSpanImpl parent = span.getParent(); if (parent != null && parent.isDiscarded()) { logger.warn("Reporting a child of an discarded span. The current span '{}' will not be shown in the UI. Consider deactivating span_min_duration.", span); } - Transaction transaction = span.getTransaction(); + TransactionImpl transaction = span.getTransaction(); if (transaction != null) { transaction.getSpanCount().getReported().incrementAndGet(); } @@ -610,35 +620,35 @@ private void reportSpan(Span span) { reporter.report(span); } - public void endError(ErrorCapture error) { + public void endError(ErrorCaptureImpl error) { reporter.report(error); } - public TraceContext createSpanLink() { + public TraceContextImpl createSpanLink() { return spanLinkPool.createInstance(); } - public Id createProfilingCorrelationStackTraceId() { + public IdImpl createProfilingCorrelationStackTraceId() { return profilingCorrelationStackTraceIdPool.createInstance(); } - public void recycle(Transaction transaction) { + public void recycle(TransactionImpl transaction) { transactionPool.recycle(transaction); } - public void recycle(Span span) { + public void recycle(SpanImpl span) { spanPool.recycle(span); } - public void recycle(ErrorCapture error) { + public void recycle(ErrorCaptureImpl error) { errorPool.recycle(error); } - public void recycle(TraceContext traceContext) { + public void recycle(TraceContextImpl traceContext) { spanLinkPool.recycle(traceContext); } - public void recycleProfilingCorrelationStackTraceId(Id id) { + public void recycleProfilingCorrelationStackTraceId(IdImpl id) { profilingCorrelationStackTraceIdPool.recycle(id); } @@ -670,7 +680,7 @@ public synchronized void stop() { } //Shutting down logging resets the log level to OFF - subsequent tests in the class will get no log output, hence the guard if (!assertionsEnabled) { - LoggingConfiguration.shutdown(); + LoggingConfigurationImpl.shutdown(); } } @@ -687,7 +697,7 @@ public Sampler getSampler() { } @Override - public ObjectPoolFactory getObjectPoolFactory() { + public ObjectPoolFactoryImpl getObjectPoolFactory() { return objectPoolFactory; } @@ -729,7 +739,7 @@ void init(List lifecycleListeners) { * jvm parameter); false otherwise */ public synchronized void start(boolean premain) { - long delayInitMs = getConfig(CoreConfiguration.class).getDelayTracerStartMs(); + long delayInitMs = getConfig(CoreConfigurationImpl.class).getDelayTracerStartMs(); if (premain && shouldDelayOnPremain()) { delayInitMs = Math.max(delayInitMs, 5000L); } @@ -853,17 +863,15 @@ public boolean isRunning() { return tracerState == TracerState.RUNNING; } - @Override @Nullable - public Span createExitChildSpan() { - AbstractSpan active = getActive(); + public SpanImpl createExitChildSpan() { + AbstractSpanImpl active = getActive(); if (active == null) { return null; } return active.createExitSpan(); } - @Override public TracerState getState() { return tracerState; } @@ -882,13 +890,13 @@ public T getLifecycleListener(Class listenerClass) { * @return the currently active context, {@literal null} if there is none. */ - public ElasticContext currentContext() { + public TraceStateImpl currentContext() { return activeStack.get().currentContext(); } @Nullable @Override - public AbstractSpan getActive() { + public AbstractSpanImpl getActive() { return currentContext().getSpan(); } @@ -901,15 +909,15 @@ public AbstractSpan getActive() { * @param wrapper type * @return newly (or previously) created wrapper */ - public > T wrapActiveContextIfRequired(Class wrapperClass, Callable wrapFunction) { + public > T wrapActiveContextIfRequired(Class wrapperClass, Callable wrapFunction) { return activeStack.get().wrapActiveContextIfRequired(wrapperClass, wrapFunction, approximateContextSize); } - public void activate(ElasticContext context) { + public void activate(TraceStateImpl context) { activeStack.get().activate(context, activationListeners); } - public Scope activateInScope(final ElasticContext context) { + public Scope activateInScope(final TraceStateImpl context) { // already in scope if (currentContext() == context) { return NoopScope.INSTANCE; @@ -928,7 +936,7 @@ public void close() { }; } - public void deactivate(ElasticContext context) { + public void deactivate(TraceStateImpl context) { activeStack.get().deactivate(context, activationListeners, assertionsEnabled); } @@ -962,7 +970,6 @@ public void setServiceInfoForClassLoader(@Nullable ClassLoader classLoader, Serv } @Nullable - @Override public ServiceInfo getServiceInfoForClassLoader(@Nullable ClassLoader initiatingClassLoader) { if (initiatingClassLoader == null) { return null; @@ -1040,7 +1047,7 @@ public Service createService(String ephemeralId) { return new ServiceFactory().createService( coreConfiguration, ephemeralId, - configurationRegistry.getConfig(ServerlessConfiguration.class).runsOnAwsLambda() + configurationRegistry.getConfig(ServerlessConfigurationImpl.class).runsOnAwsLambda() ); } @@ -1055,7 +1062,7 @@ public Throwable redactExceptionIfRequired(@Nullable Throwable original) { @Override public void flush() { - long flushTimeout = configurationRegistry.getConfig(ServerlessConfiguration.class).getDataFlushTimeout(); + long flushTimeout = configurationRegistry.getConfig(ServerlessConfigurationImpl.class).getDataFlushTimeout(); try { if (!reporter.flush(flushTimeout, TimeUnit.MILLISECONDS, true)) { logger.error("APM data flush haven't completed within {} milliseconds.", flushTimeout); @@ -1102,9 +1109,35 @@ public void schedule(Runnable job, long interval, TimeUnit timeUnit) { sharedPool.scheduleAtFixedRate(job, 0, interval, timeUnit); } - @Override public void reportMetric(JsonWriter metrics) { reporter.reportMetrics(metrics); } + /** + * An enumeration used to represent the current tracer state. + */ + public enum TracerState { + /** + * The agent's state before it has been started for the first time. + */ + UNINITIALIZED, + + /** + * Indicates that the agent is currently fully functional - tracing, monitoring and sending data to the APM server. + */ + RUNNING, + + /** + * The agent is mostly idle, consuming minimal resources, ready to quickly resume back to RUNNING. When the agent + * is PAUSED, it is not tracing and not communicating with the APM server. However, classes are still instrumented + * and threads are still alive. + */ + PAUSED, + + /** + * Indicates that the agent had been stopped. + * NOTE: this state is irreversible- the agent cannot resume if it has already been stopped. + */ + STOPPED + } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilder.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilder.java index b68faae5dd..7d422d573f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilder.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilder.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.configuration.AgentArgumentsConfigurationSource; import co.elastic.apm.agent.configuration.ApmServerConfigurationSource; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.configuration.PrefixingConfigurationSourceWrapper; import co.elastic.apm.agent.configuration.source.ConfigSources; import co.elastic.apm.agent.configuration.source.SystemPropertyConfigurationSource; @@ -29,14 +29,14 @@ import co.elastic.apm.agent.tracer.LifecycleListener; import co.elastic.apm.agent.impl.metadata.MetaData; import co.elastic.apm.agent.impl.metadata.MetaDataFuture; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.logging.LoggingConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.logging.LoggingConfigurationImpl; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.builtin.AgentReporterMetrics; -import co.elastic.apm.agent.objectpool.ObjectPoolFactory; +import co.elastic.apm.agent.objectpool.ObjectPoolFactoryImpl; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.report.Reporter; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.report.ReporterFactory; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import co.elastic.apm.agent.report.serialize.SerializationConstants; @@ -74,7 +74,7 @@ public class ElasticApmTracerBuilder { @Nullable private Reporter reporter; - private ObjectPoolFactory objectPoolFactory; + private ObjectPoolFactoryImpl objectPoolFactory; private final List extraLifecycleListeners; @@ -98,9 +98,9 @@ public ElasticApmTracerBuilder() { public ElasticApmTracerBuilder(List configSources) { this.configSources = configSources; this.ephemeralId = UUID.randomUUID().toString(); - LoggingConfiguration.init(configSources, ephemeralId); + LoggingConfigurationImpl.init(configSources, ephemeralId); logger = LoggerFactory.getLogger(getClass()); - objectPoolFactory = new ObjectPoolFactory(); + objectPoolFactory = new ObjectPoolFactoryImpl(); extraLifecycleListeners = new ArrayList<>(); } @@ -115,7 +115,7 @@ public ElasticApmTracerBuilder reporter(Reporter reporter) { } - public ElasticApmTracerBuilder withObjectPoolFactory(ObjectPoolFactory objectPoolFactory) { + public ElasticApmTracerBuilder withObjectPoolFactory(ObjectPoolFactoryImpl objectPoolFactory) { this.objectPoolFactory = objectPoolFactory; return this; } @@ -158,11 +158,11 @@ private ElasticApmTracer build(boolean startTracer) { apmServerClient = new ApmServerClient(configurationRegistry); } - SerializationConstants.init(configurationRegistry.getConfig(CoreConfiguration.class)); + SerializationConstants.init(configurationRegistry.getConfig(CoreConfigurationImpl.class)); MetaDataFuture metaDataFuture = MetaData.create(configurationRegistry, ephemeralId); DslJsonSerializer payloadSerializer = new DslJsonSerializer( - configurationRegistry.getConfig(StacktraceConfiguration.class), + configurationRegistry.getConfig(StacktraceConfigurationImpl.class), apmServerClient, metaDataFuture ); @@ -178,8 +178,8 @@ private ElasticApmTracer build(boolean startTracer) { lifecycleListeners.add(configurationSource); } - MetricsConfiguration metricsConfig = configurationRegistry.getConfig(MetricsConfiguration.class); - MetricRegistry metricRegistry = new MetricRegistry(configurationRegistry.getConfig(ReporterConfiguration.class), metricsConfig); + MetricsConfigurationImpl metricsConfig = configurationRegistry.getConfig(MetricsConfigurationImpl.class); + MetricRegistry metricRegistry = new MetricRegistry(configurationRegistry.getConfig(ReporterConfigurationImpl.class), metricsConfig); if (reporter == null) { AgentReporterMetrics healthMetrics = new AgentReporterMetrics(metricRegistry, metricsConfig); @@ -229,9 +229,9 @@ private ConfigurationRegistry getDefaultConfigurationRegistry(List getConfigSources(@Nullable String agentA // Optionally loading agent configuration from external file, while it depends on sources above, it has higher // priority and is thus inserted before them. - String configFileLocation = CoreConfiguration.getConfigFileLocation(result, premain); + String configFileLocation = CoreConfigurationImpl.getConfigFileLocation(result, premain); ConfigurationSource configFileSource = ConfigSources.fromFileSystem(configFileLocation); if (configFileSource != null) { result.add(0, configFileSource); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/EmptyElasticContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/EmptyTraceState.java similarity index 73% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/EmptyElasticContext.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/EmptyTraceState.java index cac09a1c49..bf7782b8a8 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/EmptyElasticContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/EmptyTraceState.java @@ -18,27 +18,27 @@ */ package co.elastic.apm.agent.impl; -import co.elastic.apm.agent.impl.baggage.Baggage; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; import javax.annotation.Nullable; -class EmptyElasticContext extends ElasticContext { +class EmptyTraceState extends TraceStateImpl { - EmptyElasticContext(ElasticApmTracer tracer) { + EmptyTraceState(ElasticApmTracer tracer) { super(tracer); } @Nullable @Override - public AbstractSpan getSpan() { + public AbstractSpanImpl getSpan() { return null; } @Override - public Baggage getBaggage() { - return Baggage.EMPTY; + public BaggageImpl getBaggage() { + return BaggageImpl.EMPTY; } @Override diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Tracer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Tracer.java deleted file mode 100644 index f645420cd9..0000000000 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Tracer.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package co.elastic.apm.agent.impl; - -import co.elastic.apm.agent.tracer.service.ServiceInfo; -import co.elastic.apm.agent.impl.baggage.Baggage; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.sampling.Sampler; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; - -import javax.annotation.Nullable; - -public interface Tracer extends co.elastic.apm.agent.tracer.service.ServiceAwareTracer, co.elastic.apm.agent.tracer.Tracer { - - @Nullable - @Override - Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader); - - @Nullable - Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader, long epochMicro); - - @Nullable - Transaction startRootTransaction(@Nullable ClassLoader initiatingClassLoader, Baggage baseBaggage, long epochMicro); - - /** - * Starts a trace-root transaction with a specified sampler and start timestamp - * - * @param sampler the {@link Sampler} instance which is responsible for determining the sampling decision if this is a root transaction - * @param epochMicros the start timestamp - * @param initiatingClassLoader the class loader corresponding to the service which initiated the creation of the transaction. - * Used to determine the service name and to load application-scoped classes like the {@link org.slf4j.MDC}, - * for log correlation. - * @return a transaction that will be the root of the current trace if the agent is currently RUNNING; null otherwise - */ - @Nullable - Transaction startRootTransaction(Sampler sampler, long epochMicros, Baggage baseBaggage, @Nullable ClassLoader initiatingClassLoader); - - @Override - @Nullable - Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter headersGetter, @Nullable ClassLoader initiatingClassLoader); - - @Nullable - Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter headersGetter, @Nullable ClassLoader initiatingClassLoader, Baggage baseBaggage, long epochMicros); - - /** - * Starts a transaction as a child of the context headers obtained through the provided {@link HeaderGetter}. - * If the created transaction cannot be started as a child transaction (for example - if no parent context header is - * available), then it will be started as the root transaction of the trace. - * - * @param headerCarrier the Object from which context headers can be obtained, typically a request or a message - * @param headersGetter provides the trace context headers required in order to create a child transaction - * @param sampler the {@link Sampler} instance which is responsible for determining the sampling decision if this is a root transaction - * @param epochMicros the start timestamp - * @param initiatingClassLoader the class loader corresponding to the service which initiated the creation of the transaction. - * Used to determine the service name and to load application-scoped classes like the {@link org.slf4j.MDC}, - * for log correlation. - * @return a transaction which is a child of the provided parent if the agent is currently RUNNING; null otherwise - */ - @Nullable - Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter headersGetter, Sampler sampler, - long epochMicros, @Nullable ClassLoader initiatingClassLoader); - - - @Override - ElasticContext currentContext(); - - @Override - @Nullable - AbstractSpan getActive(); - - @Override - @Nullable - Transaction currentTransaction(); - - - /** - * Captures an exception without providing an explicit reference to a parent {@link AbstractSpan} - * - * @param e the exception to capture - * @param initiatingClassLoader the class - */ - void captureAndReportException(@Nullable Throwable e, ClassLoader initiatingClassLoader); - - @Nullable - String captureAndReportException(long epochMicros, @Nullable Throwable e, ElasticContext parentContext); - - @Nullable - ErrorCapture captureException(@Nullable Throwable e, ElasticContext parentContext, @Nullable ClassLoader initiatingClassLoader); - - TracerState getState(); - - @Nullable - ServiceInfo getServiceInfoForClassLoader(@Nullable ClassLoader classLoader); - - /** - * Sets the service name and version for all {@link Transaction}s, - * {@link Span}s and {@link ErrorCapture}s which are created by the service which corresponds to the provided {@link ClassLoader}. - *

- * The main use case is being able to differentiate between multiple services deployed to the same application server. - *

- * - * @param classLoader the class loader which corresponds to a particular service - * @param serviceInfo the service name and version for this class loader - */ - void setServiceInfoForClassLoader(@Nullable ClassLoader classLoader, ServiceInfo serviceInfo); - - /** - * Called when the container shuts down. - * Cleans up thread pools and other resources. - */ - void stop(); - - @Override - boolean isRunning(); - - @Nullable - Span createExitChildSpan(); - - /** - * An enumeration used to represent the current tracer state. - */ - enum TracerState { - /** - * The agent's state before it has been started for the first time. - */ - UNINITIALIZED, - - /** - * Indicates that the agent is currently fully functional - tracing, monitoring and sending data to the APM server. - */ - RUNNING, - - /** - * The agent is mostly idle, consuming minimal resources, ready to quickly resume back to RUNNING. When the agent - * is PAUSED, it is not tracing and not communicating with the APM server. However, classes are still instrumented - * and threads are still alive. - */ - PAUSED, - - /** - * Indicates that the agent had been stopped. - * NOTE: this state is irreversible- the agent cannot resume if it has already been stopped. - */ - STOPPED - } -} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/TracerConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/TracerConfiguration.java index 1a8394a36e..fd3e7e84b6 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/TracerConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/TracerConfiguration.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import org.stagemonitor.configuration.ConfigurationOption; import org.stagemonitor.configuration.ConfigurationOptionProvider; @@ -29,7 +29,7 @@ public class TracerConfiguration extends ConfigurationOptionProvider { .key(RECORDING) .aliasKeys("active") .tags("added[1.15.0]") - .configurationCategory(CoreConfiguration.CORE_CATEGORY) + .configurationCategory(CoreConfigurationImpl.CORE_CATEGORY) .description("NOTE: This option was available in older versions through the `active` key. The old key is still \n" + "supported in newer versions, but it is now deprecated.\n" + "\n" + diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/BaggageContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/BaggageContext.java index 831b731ade..d757a032ef 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/BaggageContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/BaggageContext.java @@ -18,19 +18,19 @@ */ package co.elastic.apm.agent.impl.baggage; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; import co.elastic.apm.agent.tracer.BaggageContextBuilder; import javax.annotation.Nullable; -public class BaggageContext extends ElasticContext { +public class BaggageContext extends TraceStateImpl { @Nullable - private final AbstractSpan span; - private final Baggage baggage; + private final AbstractSpanImpl span; + private final BaggageImpl baggage; - private BaggageContext(ElasticContext parent, Baggage baggage) { + private BaggageContext(TraceStateImpl parent, BaggageImpl baggage) { super(parent.getTracer()); this.span = parent.getSpan(); this.baggage = baggage; @@ -38,12 +38,12 @@ private BaggageContext(ElasticContext parent, Baggage baggage) { @Nullable @Override - public AbstractSpan getSpan() { + public AbstractSpanImpl getSpan() { return span; } @Override - public Baggage getBaggage() { + public BaggageImpl getBaggage() { return baggage; } @@ -61,16 +61,16 @@ public void decrementReferences() { } } - public static BaggageContext.Builder createBuilder(ElasticContext parent) { + public static BaggageContext.Builder createBuilder(TraceStateImpl parent) { return new Builder(parent); } public static class Builder implements BaggageContextBuilder { - private final ElasticContext parent; - private final Baggage.Builder baggageBuilder; + private final TraceStateImpl parent; + private final BaggageImpl.Builder baggageBuilder; - public Builder(ElasticContext parent) { + public Builder(TraceStateImpl parent) { this.parent = parent; this.baggageBuilder = parent.getBaggage().toBuilder(); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/Baggage.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/BaggageImpl.java similarity index 89% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/Baggage.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/BaggageImpl.java index cecfe45f9e..88934639d5 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/Baggage.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/BaggageImpl.java @@ -19,8 +19,9 @@ package co.elastic.apm.agent.impl.baggage; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.impl.context.AbstractContext; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.context.AbstractContextImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.tracer.Baggage; import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; @@ -32,11 +33,11 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -public class Baggage implements co.elastic.apm.agent.tracer.Baggage { +public class BaggageImpl implements Baggage { private static final String LIFTED_BAGGAGE_ATTRIBUTE_PREFIX = "baggage."; - public static final Baggage EMPTY = new Baggage(Collections.emptyMap(), Collections.emptyMap()); + public static final BaggageImpl EMPTY = new BaggageImpl(Collections.emptyMap(), Collections.emptyMap()); private final Map baggage; @@ -53,7 +54,7 @@ public class Baggage implements co.elastic.apm.agent.tracer.Baggage { * When automatically lifting baggage entries to be stored as span attributes we add the {@link #LIFTED_BAGGAGE_ATTRIBUTE_PREFIX} * to the key. * Because baggage is usually updated rarely but the lifting can happen for very many spans we cache the prefixed string in this map. - * See {@link #storeBaggageInAttributes(AbstractSpan, List)} for the implementation details. + * See {@link #storeBaggageInAttributes(AbstractSpanImpl, List)} for the implementation details. */ private volatile ConcurrentHashMap cachedKeysWithPrefix; @@ -67,7 +68,7 @@ public class Baggage implements co.elastic.apm.agent.tracer.Baggage { */ byte[] cachedSerializedW3CHeaderUtf8 = null; - private Baggage(Map baggage, Map baggageMetadata) { + private BaggageImpl(Map baggage, Map baggageMetadata) { this.baggage = baggage; this.baggageMetadata = baggageMetadata; } @@ -122,7 +123,7 @@ byte[] getCachedSerializedW3CHeaderUtf8() { return this.cachedSerializedW3CHeaderUtf8; } - public void storeBaggageInAttributes(AbstractSpan span, List keyFilter) { + public void storeBaggageInAttributes(AbstractSpanImpl span, List keyFilter) { if (baggage.isEmpty() || keyFilter.isEmpty()) { // early out to prevent unnecessarily allocating an iterator return; @@ -136,7 +137,7 @@ public void storeBaggageInAttributes(AbstractSpan span, List } } - public void storeBaggageInContext(AbstractContext context, List keyFilter) { + public void storeBaggageInContext(AbstractContextImpl context, List keyFilter) { if (baggage.isEmpty() || keyFilter.isEmpty()) { // early out to prevent unnecessarily allocating an iterator return; @@ -168,7 +169,7 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - Baggage baggage1 = (Baggage) o; + BaggageImpl baggage1 = (BaggageImpl) o; if (!baggage.equals(baggage1.baggage)) return false; return baggageMetadata.equals(baggage1.baggageMetadata); @@ -183,14 +184,14 @@ public int hashCode() { public static class Builder { - public Builder(Baggage parent) { + public Builder(BaggageImpl parent) { this.parent = parent; this.baggage = parent.baggage; this.baggageMetadata = parent.baggageMetadata; buildCalled = false; } - private final Baggage parent; + private final BaggageImpl parent; private Map baggage; private Map baggageMetadata; @@ -221,7 +222,7 @@ public Builder put(String key, @Nullable String value, @Nullable String metadata * * @return a baggage resulting from this builder. */ - public Baggage build() { + public BaggageImpl build() { buildCalled = true; boolean anyModifications = false; if (baggage != parent.baggage) { @@ -233,7 +234,7 @@ public Baggage build() { baggageMetadata = Collections.unmodifiableMap(baggageMetadata); } if (anyModifications) { - return new Baggage(baggage, baggageMetadata); + return new BaggageImpl(baggage, baggageMetadata); } else { return parent; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/W3CBaggagePropagation.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/W3CBaggagePropagation.java index 6a52a1712d..dcd498deb8 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/W3CBaggagePropagation.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/W3CBaggagePropagation.java @@ -40,9 +40,9 @@ public class W3CBaggagePropagation { public static final String BAGGAGE_HEADER_NAME = "baggage"; - private static final HeaderGetter.HeaderConsumer STRING_PARSING_CONSUMER = new HeaderGetter.HeaderConsumer() { + private static final HeaderGetter.HeaderConsumer STRING_PARSING_CONSUMER = new HeaderGetter.HeaderConsumer() { @Override - public void accept(@Nullable String headerValue, Baggage.Builder state) { + public void accept(@Nullable String headerValue, BaggageImpl.Builder state) { if (headerValue != null) { try { new Parser(headerValue).parseInto(state); @@ -54,9 +54,9 @@ public void accept(@Nullable String headerValue, Baggage.Builder state) { }; - private static final HeaderGetter.HeaderConsumer UTF8_BYTES_PARSING_CONSUMER = new HeaderGetter.HeaderConsumer() { + private static final HeaderGetter.HeaderConsumer UTF8_BYTES_PARSING_CONSUMER = new HeaderGetter.HeaderConsumer() { @Override - public void accept(@Nullable byte[] headerValue, Baggage.Builder state) { + public void accept(@Nullable byte[] headerValue, BaggageImpl.Builder state) { if (headerValue != null) { try { STRING_PARSING_CONSUMER.accept(new String(headerValue, StandardCharsets.UTF_8), state); @@ -68,19 +68,19 @@ public void accept(@Nullable byte[] headerValue, Baggage.Builder state) { }; @SuppressWarnings("unchecked") - public static void parse(C carrier, HeaderGetter headerGetter, Baggage.Builder into) { - HeaderGetter.HeaderConsumer consumer; + public static void parse(C carrier, HeaderGetter headerGetter, BaggageImpl.Builder into) { + HeaderGetter.HeaderConsumer consumer; if (headerGetter instanceof TextHeaderGetter) { - consumer = (HeaderGetter.HeaderConsumer) STRING_PARSING_CONSUMER; + consumer = (HeaderGetter.HeaderConsumer) STRING_PARSING_CONSUMER; } else if (headerGetter instanceof UTF8ByteHeaderGetter) { - consumer = (HeaderGetter.HeaderConsumer) UTF8_BYTES_PARSING_CONSUMER; + consumer = (HeaderGetter.HeaderConsumer) UTF8_BYTES_PARSING_CONSUMER; } else { throw new IllegalArgumentException("HeaderGetter must be either a TextHeaderGetter or UTF8ByteHeaderGetter: " + headerGetter.getClass().getName()); } headerGetter.forEach(BAGGAGE_HEADER_NAME, carrier, into, consumer); } - public static void propagate(Baggage baggage, C carrier, HeaderSetter setter) { + public static void propagate(BaggageImpl baggage, C carrier, HeaderSetter setter) { if (baggage.isEmpty()) { return; } @@ -91,7 +91,7 @@ public static void propagate(Baggage baggage, C carrier, HeaderSetter T getTextHeader(Baggage baggage, HeaderSetter setter) { + private static T getTextHeader(BaggageImpl baggage, HeaderSetter setter) { if (setter instanceof TextHeaderSetter) { return (T) getTextHeaderString(baggage); } else if (setter instanceof UTF8ByteHeaderSetter) { @@ -102,13 +102,13 @@ private static T getTextHeader(Baggage baggage, HeaderSetter setter) { } @Nullable - private static byte[] getTextHeaderUtf8Bytes(Baggage baggage) { + private static byte[] getTextHeaderUtf8Bytes(BaggageImpl baggage) { getTextHeaderString(baggage); //ensures that the string-header is computed and cached return baggage.getCachedSerializedW3CHeaderUtf8(); } @Nullable - private static String getTextHeaderString(Baggage baggage) { + private static String getTextHeaderString(BaggageImpl baggage) { String header = baggage.getCachedSerializedW3CHeader(); if (header == null) { header = encodeToHeader(baggage); @@ -121,7 +121,7 @@ private static String getTextHeaderString(Baggage baggage) { } - private static String encodeToHeader(Baggage baggage) { + private static String encodeToHeader(BaggageImpl baggage) { StringBuilder header = new StringBuilder(); for (String key : baggage.keys()) { String value = baggage.get(key); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/otel/Parser.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/otel/Parser.java index d797defbb8..519899291a 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/otel/Parser.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/baggage/otel/Parser.java @@ -26,7 +26,7 @@ package co.elastic.apm.agent.impl.baggage.otel; -import co.elastic.apm.agent.impl.baggage.Baggage; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; @@ -63,7 +63,7 @@ public Parser(String baggageHeader) { reset(0); } - public void parseInto(Baggage.Builder baggageBuilder) { + public void parseInto(BaggageImpl.Builder baggageBuilder) { for (int i = 0, n = baggageHeader.length(); i < n; i++) { char current = baggageHeader.charAt(i); @@ -141,7 +141,7 @@ public void parseInto(Baggage.Builder baggageBuilder) { } private static void putBaggage( - Baggage.Builder baggage, + BaggageImpl.Builder baggage, @Nullable String key, @Nullable String value, @Nullable String metadataValue) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/AbstractContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/AbstractContextImpl.java similarity index 89% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/AbstractContext.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/AbstractContextImpl.java index afcd86a802..de6b883c37 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/AbstractContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/AbstractContextImpl.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.impl.context; +import co.elastic.apm.agent.tracer.AbstractContext; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; @@ -25,7 +26,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -public abstract class AbstractContext implements Recyclable, co.elastic.apm.agent.tracer.AbstractContext { +public abstract class AbstractContextImpl implements Recyclable, AbstractContext { public static final String REDACTED_CONTEXT_STRING = "[REDACTED]"; @@ -41,7 +42,7 @@ public abstract class AbstractContext implements Recyclable, co.elastic.apm.agen /** * An object containing contextual data for Messages (incoming in case of transactions or outgoing in case of spans) */ - private final Message message = new Message(); + private final MessageImpl message = new MessageImpl(); public Iterator> getLabelIterator() { return labels.entrySet().iterator(); @@ -73,7 +74,7 @@ public boolean hasLabels() { } @Override - public Message getMessage() { + public MessageImpl getMessage() { return message; } @@ -87,7 +88,7 @@ public boolean hasContent() { return !labels.isEmpty() || message.hasContent(); } - public void copyFrom(AbstractContext other) { + public void copyFrom(AbstractContextImpl other) { labels.putAll(other.labels); message.copyFrom(other.message); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/BodyCaptureImpl.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/BodyCaptureImpl.java new file mode 100644 index 0000000000..11b037254c --- /dev/null +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/BodyCaptureImpl.java @@ -0,0 +1,162 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.impl.context; + +import co.elastic.apm.agent.objectpool.Resetter; +import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; +import co.elastic.apm.agent.tracer.configuration.WebConfiguration; +import co.elastic.apm.agent.tracer.metadata.BodyCapture; +import co.elastic.apm.agent.tracer.pooling.Allocator; +import co.elastic.apm.agent.tracer.pooling.ObjectPool; +import co.elastic.apm.agent.tracer.pooling.Recyclable; +import org.jctools.queues.atomic.MpmcAtomicArrayQueue; + +import javax.annotation.Nullable; +import java.nio.ByteBuffer; + +public class BodyCaptureImpl implements BodyCapture, Recyclable { + private static final ObjectPool BYTE_BUFFER_POOL = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, + new Allocator() { + @Override + public ByteBuffer createInstance() { + return ByteBuffer.allocate(WebConfiguration.MAX_BODY_CAPTURE_BYTES); + } + }, + new Resetter() { + @Override + public void recycle(ByteBuffer object) { + object.clear(); + } + }); + + private enum CaptureState { + NOT_ELIGIBLE, + ELIGIBLE, + STARTED + } + + private volatile CaptureState state; + + private final StringBuilder charset; + + /** + * The maximum number of bytes to capture, if the body is longer remaining bytes will be dropped. + */ + private int numBytesToCapture; + + @Nullable + private ByteBuffer bodyBuffer; + + BodyCaptureImpl() { + charset = new StringBuilder(); + resetState(); + } + + @Override + public void resetState() { + state = CaptureState.NOT_ELIGIBLE; + charset.setLength(0); + if (bodyBuffer != null) { + BYTE_BUFFER_POOL.recycle(bodyBuffer); + } + } + + @Override + public void markEligibleForCapturing() { + if (state == CaptureState.NOT_ELIGIBLE) { + synchronized (this) { + if (state == CaptureState.NOT_ELIGIBLE) { + state = CaptureState.ELIGIBLE; + } + } + } + } + + @Override + public boolean isEligibleForCapturing() { + return state != CaptureState.NOT_ELIGIBLE; + } + + @Override + public boolean startCapture(@Nullable String requestCharset, int numBytesToCapture) { + if (numBytesToCapture > WebConfiguration.MAX_BODY_CAPTURE_BYTES) { + throw new IllegalArgumentException("Capturing " + numBytesToCapture + " bytes is not supported, maximum is " + WebConfiguration.MAX_BODY_CAPTURE_BYTES + " bytes"); + } + if (state == CaptureState.ELIGIBLE) { + synchronized (this) { + if (state == CaptureState.ELIGIBLE) { + if (requestCharset != null) { + this.charset.append(requestCharset); + } + this.numBytesToCapture = numBytesToCapture; + state = CaptureState.STARTED; + return true; + } + } + } + return false; + } + + private void acquireBodyBufferIfRequired() { + if (state != CaptureState.STARTED) { + throw new IllegalStateException("Capturing has not been started!"); + } + if (bodyBuffer == null) { + bodyBuffer = BYTE_BUFFER_POOL.createInstance(); + } + } + + @Override + public void append(byte b) { + acquireBodyBufferIfRequired(); + if (!isFull()) { + bodyBuffer.put(b); + } + } + + @Override + public void append(byte[] b, int offset, int len) { + acquireBodyBufferIfRequired(); + int remaining = numBytesToCapture - bodyBuffer.position(); + if (remaining > 0) { + bodyBuffer.put(b, offset, Math.min(len, remaining)); + } + } + + @Override + public boolean isFull() { + if (bodyBuffer == null) { + return false; + } + return bodyBuffer.position() >= numBytesToCapture; + } + + @Nullable + public CharSequence getCharset() { + if (charset.length() == 0) { + return null; + } + return charset; + } + + @Nullable + public ByteBuffer getBody() { + return bodyBuffer; + } +} diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/BodyProcessor.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/BodyProcessor.java index 12af85bff8..f68508ad0c 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/BodyProcessor.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/BodyProcessor.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.report.processor.Processor; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import org.stagemonitor.configuration.ConfigurationRegistry; import static co.elastic.apm.agent.tracer.configuration.CoreConfiguration.EventType.ALL; @@ -29,30 +29,30 @@ import static co.elastic.apm.agent.tracer.configuration.CoreConfiguration.EventType.TRANSACTIONS; /** - * This processor redacts the body according to the {@link co.elastic.apm.agent.configuration.CoreConfiguration#captureBody} + * This processor redacts the body according to the {@link CoreConfigurationImpl#captureBody} * configuration option */ @SuppressWarnings("JavadocReference") public class BodyProcessor implements Processor { - private final CoreConfiguration coreConfiguration; + private final CoreConfigurationImpl coreConfiguration; public BodyProcessor(ConfigurationRegistry configurationRegistry) { - coreConfiguration = configurationRegistry.getConfig(CoreConfiguration.class); + coreConfiguration = configurationRegistry.getConfig(CoreConfigurationImpl.class); } @Override - public void processBeforeReport(Transaction transaction) { + public void processBeforeReport(TransactionImpl transaction) { redactBodyIfNecessary(transaction.getContext(), TRANSACTIONS); } @Override - public void processBeforeReport(ErrorCapture error) { + public void processBeforeReport(ErrorCaptureImpl error) { redactBodyIfNecessary(error.getContext(), ERRORS); } - private void redactBodyIfNecessary(TransactionContext context, CoreConfiguration.EventType eventType) { - final CoreConfiguration.EventType eventTypeConfig = coreConfiguration.getCaptureBody(); + private void redactBodyIfNecessary(TransactionContextImpl context, CoreConfigurationImpl.EventType eventType) { + final CoreConfigurationImpl.EventType eventTypeConfig = coreConfiguration.getCaptureBody(); if (eventTypeConfig != eventType && eventTypeConfig != ALL) { if (context.getRequest().getBody() != null) { context.getRequest().redactBody(); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/CloudOrigin.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/CloudOriginImpl.java similarity index 83% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/CloudOrigin.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/CloudOriginImpl.java index 3dbcd57f8b..d5eca191a9 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/CloudOrigin.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/CloudOriginImpl.java @@ -18,11 +18,12 @@ */ package co.elastic.apm.agent.impl.context; +import co.elastic.apm.agent.tracer.metadata.CloudOrigin; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -public class CloudOrigin implements Recyclable, co.elastic.apm.agent.tracer.metadata.CloudOrigin { +public class CloudOriginImpl implements Recyclable, CloudOrigin { @Nullable protected String accountId; @@ -42,7 +43,7 @@ public String getAccountId() { } @Override - public CloudOrigin withAccountId(@Nullable String accountId) { + public CloudOriginImpl withAccountId(@Nullable String accountId) { this.accountId = accountId; return this; } @@ -53,7 +54,7 @@ public String getProvider() { } @Override - public CloudOrigin withProvider(@Nullable String provider) { + public CloudOriginImpl withProvider(@Nullable String provider) { this.provider = provider; return this; } @@ -64,7 +65,7 @@ public String getRegion() { } @Override - public CloudOrigin withRegion(@Nullable String region) { + public CloudOriginImpl withRegion(@Nullable String region) { this.region = region; return this; } @@ -75,7 +76,7 @@ public String getServiceName() { } @Override - public CloudOrigin withServiceName(@Nullable String serviceName) { + public CloudOriginImpl withServiceName(@Nullable String serviceName) { this.serviceName = serviceName; return this; } @@ -95,7 +96,7 @@ public boolean hasContent() { serviceName != null; } - public void copyFrom(CloudOrigin other) { + public void copyFrom(CloudOriginImpl other) { accountId = other.accountId; provider = other.provider; region = other.region; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Db.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/DbImpl.java similarity index 88% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Db.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/DbImpl.java index e2f5825b75..ea5090c4c4 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Db.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/DbImpl.java @@ -18,10 +18,11 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; import co.elastic.apm.agent.objectpool.Resetter; import co.elastic.apm.agent.report.serialize.SerializationConstants; +import co.elastic.apm.agent.tracer.metadata.Db; import co.elastic.apm.agent.tracer.pooling.Allocator; import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.jctools.queues.atomic.MpmcAtomicArrayQueue; @@ -30,9 +31,9 @@ import java.nio.Buffer; import java.nio.CharBuffer; -public class Db implements Recyclable, co.elastic.apm.agent.tracer.metadata.Db { +public class DbImpl implements Recyclable, Db { - private static final ObjectPool charBufferPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, + private static final ObservableObjectPool charBufferPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, new Allocator() { @Override public CharBuffer createInstance() { @@ -91,7 +92,7 @@ public String getInstance() { } @Override - public Db withInstance(@Nullable String instance) { + public DbImpl withInstance(@Nullable String instance) { this.instance = instance; return this; } @@ -105,7 +106,7 @@ public String getStatement() { } @Override - public Db withStatement(@Nullable String statement) { + public DbImpl withStatement(@Nullable String statement) { this.statement = statement; return this; } @@ -133,7 +134,7 @@ public String getType() { } @Override - public Db withType(@Nullable String type) { + public DbImpl withType(@Nullable String type) { this.type = type; return this; } @@ -147,7 +148,7 @@ public String getUser() { } @Override - public Db withUser(@Nullable String user) { + public DbImpl withUser(@Nullable String user) { this.user = user; return this; } @@ -163,7 +164,7 @@ public String getDbLink() { /** * DB Link for connections between 2 databases */ - public Db withDbLink(@Nullable String dbLink) { + public DbImpl withDbLink(@Nullable String dbLink) { this.dbLink = dbLink; return this; } @@ -176,7 +177,7 @@ public long getAffectedRowsCount(){ } @Override - public Db withAffectedRowsCount(long count){ + public DbImpl withAffectedRowsCount(long count){ this.affectedRowsCount = count; return this; } @@ -204,7 +205,7 @@ public boolean hasContent() { statementBuffer != null; } - public void copyFrom(Db other) { + public void copyFrom(DbImpl other) { instance = other.instance; statement = other.statement; type = other.type; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Destination.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/DestinationImpl.java similarity index 84% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Destination.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/DestinationImpl.java index 2152dc2c18..1cc0b359b5 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Destination.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/DestinationImpl.java @@ -18,6 +18,8 @@ */ package co.elastic.apm.agent.impl.context; +import co.elastic.apm.agent.tracer.metadata.Cloud; +import co.elastic.apm.agent.tracer.metadata.Destination; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; @@ -25,7 +27,7 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; -public class Destination implements Recyclable, co.elastic.apm.agent.tracer.metadata.Destination { +public class DestinationImpl implements Recyclable, Destination { /** * An IP (v4 or v6) or a host/domain name. @@ -42,14 +44,14 @@ public class Destination implements Recyclable, co.elastic.apm.agent.tracer.meta private boolean portSetByUser; @Override - public Destination withAddress(@Nullable CharSequence address) { + public DestinationImpl withAddress(@Nullable CharSequence address) { if (address != null && !addressSetByUser) { withAddress(address, 0, address.length()); } return this; } - public Destination withUserAddress(@Nullable CharSequence address) { + public DestinationImpl withUserAddress(@Nullable CharSequence address) { if (address == null || address.length() == 0) { this.address.setLength(0); } else { @@ -64,14 +66,14 @@ public StringBuilder getAddress() { } @Override - public Destination withPort(int port) { + public DestinationImpl withPort(int port) { if (!portSetByUser) { this.port = port; } return this; } - public Destination withUserPort(int port) { + public DestinationImpl withUserPort(int port) { withPort(port); portSetByUser = true; return this; @@ -82,7 +84,7 @@ public int getPort() { } @Override - public Destination withAddressPort(@Nullable String addressPort) { + public DestinationImpl withAddressPort(@Nullable String addressPort) { if (addressPort != null) { int separator = addressPort.lastIndexOf(':'); if (separator > 0) { @@ -137,10 +139,10 @@ private void withAddress(CharSequence address, int start, int end) { } } - private final Cloud cloud = new Cloud(); + private final CloudImpl cloud = new CloudImpl(); @Override - public Cloud getCloud() { + public CloudImpl getCloud() { return cloud; } @@ -159,7 +161,7 @@ public void resetState() { } @Override - public Destination withSocketAddress(SocketAddress socketAddress) { + public DestinationImpl withSocketAddress(SocketAddress socketAddress) { if (socketAddress instanceof InetSocketAddress) { withInetSocketAddress((InetSocketAddress) socketAddress); } @@ -167,7 +169,7 @@ public Destination withSocketAddress(SocketAddress socketAddress) { } @Override - public Destination withInetSocketAddress(InetSocketAddress inetSocketAddress) { + public DestinationImpl withInetSocketAddress(InetSocketAddress inetSocketAddress) { InetAddress inetAddress = inetSocketAddress.getAddress(); if (inetAddress != null) { withInetAddress(inetAddress); @@ -179,16 +181,16 @@ public Destination withInetSocketAddress(InetSocketAddress inetSocketAddress) { } @Override - public Destination withInetAddress(InetAddress inetAddress) { + public DestinationImpl withInetAddress(InetAddress inetAddress) { withAddress(inetAddress.getHostAddress()); return this; } - public static class Cloud implements Recyclable, co.elastic.apm.agent.tracer.metadata.Cloud { + public static class CloudImpl implements Recyclable, Cloud { private final StringBuilder region = new StringBuilder(); @Override - public Cloud withRegion(@Nullable String region) { + public CloudImpl withRegion(@Nullable String region) { this.region.setLength(0); if (region != null) { this.region.append(region); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Http.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/HttpImpl.java similarity index 78% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Http.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/HttpImpl.java index 0af4652db8..67a7169682 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Http.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/HttpImpl.java @@ -18,16 +18,19 @@ */ package co.elastic.apm.agent.impl.context; +import co.elastic.apm.agent.tracer.metadata.Http; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -public class Http implements Recyclable, co.elastic.apm.agent.tracer.metadata.Http { +public class HttpImpl implements Recyclable, Http { /** * URL used by this HTTP outgoing span */ - private final Url url = new Url(); + private final UrlImpl url = new UrlImpl(); + + private final BodyCaptureImpl requestBody = new BodyCaptureImpl(); /** * HTTP method used by this HTTP outgoing span @@ -48,9 +51,9 @@ public CharSequence getUrl() { } /** - * @return internal {@link Url} instance + * @return internal {@link UrlImpl} instance */ - public Url getInternalUrl() { + public UrlImpl getInternalUrl() { return url; } @@ -65,7 +68,12 @@ public int getStatusCode() { } @Override - public Http withUrl(@Nullable String url) { + public BodyCaptureImpl getRequestBody() { + return requestBody; + } + + @Override + public HttpImpl withUrl(@Nullable String url) { if (url != null) { this.url.withFull(url); } @@ -73,13 +81,13 @@ public Http withUrl(@Nullable String url) { } @Override - public Http withMethod(String method) { + public HttpImpl withMethod(String method) { this.method = method; return this; } @Override - public Http withStatusCode(int statusCode) { + public HttpImpl withStatusCode(int statusCode) { this.statusCode = statusCode; return this; } @@ -87,6 +95,7 @@ public Http withStatusCode(int statusCode) { @Override public void resetState() { url.resetState(); + requestBody.resetState(); method = null; statusCode = 0; } @@ -97,9 +106,4 @@ public boolean hasContent() { statusCode > 0; } - public void copyFrom(Http other) { - url.copyFrom(other.url); - method = other.method; - statusCode = other.statusCode; - } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Message.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/MessageImpl.java similarity index 82% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Message.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/MessageImpl.java index aa45d22ed5..e2af0dba7d 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Message.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/MessageImpl.java @@ -18,20 +18,21 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; import co.elastic.apm.agent.objectpool.Resetter; +import co.elastic.apm.agent.tracer.metadata.Message; import co.elastic.apm.agent.tracer.pooling.Allocator; import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.jctools.queues.atomic.MpmcAtomicArrayQueue; import javax.annotation.Nullable; -import static co.elastic.apm.agent.impl.context.AbstractContext.REDACTED_CONTEXT_STRING; +import static co.elastic.apm.agent.impl.context.AbstractContextImpl.REDACTED_CONTEXT_STRING; -public class Message implements Recyclable, co.elastic.apm.agent.tracer.metadata.Message { +public class MessageImpl implements Recyclable, Message { - private static final ObjectPool stringBuilderPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, + private static final ObservableObjectPool stringBuilderPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, new Allocator() { @Override public StringBuilder createInstance() { @@ -71,13 +72,13 @@ public String getQueueName() { } @Override - public Message withQueue(@Nullable String queueName) { + public MessageImpl withQueue(@Nullable String queueName) { this.queueName = queueName; return this; } @Override - public Message withRoutingKey(String routingKey) { + public MessageImpl withRoutingKey(String routingKey) { this.routingKey = routingKey; return this; } @@ -109,7 +110,7 @@ public StringBuilder getBodyForRead() { } @Override - public Message withBody(@Nullable String body) { + public MessageImpl withBody(@Nullable String body) { StringBuilder thisBody = getBodyForWrite(); thisBody.setLength(0); thisBody.append(body); @@ -117,7 +118,7 @@ public Message withBody(@Nullable String body) { } @Override - public Message appendToBody(CharSequence bodyContent) { + public MessageImpl appendToBody(CharSequence bodyContent) { getBodyForWrite().append(bodyContent); return this; } @@ -130,13 +131,13 @@ public void redactBody() { } @Override - public Message addHeader(@Nullable String key, @Nullable String value) { + public MessageImpl addHeader(@Nullable String key, @Nullable String value) { headers.add(key, value); return this; } @Override - public Message addHeader(@Nullable String key, @Nullable byte[] value) { + public MessageImpl addHeader(@Nullable String key, @Nullable byte[] value) { headers.add(key, value); return this; } @@ -147,7 +148,7 @@ public long getAge() { @SuppressWarnings("UnusedReturnValue") @Override - public Message withAge(long age) { + public MessageImpl withAge(long age) { this.age = age; return this; } @@ -172,7 +173,7 @@ public void resetState() { routingKey = null; } - public void copyFrom(Message other) { + public void copyFrom(MessageImpl other) { resetState(); this.queueName = other.getQueueName(); if (other.body != null) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Request.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/RequestImpl.java similarity index 86% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Request.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/RequestImpl.java index a6d2694b4e..ad8af7fd77 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Request.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/RequestImpl.java @@ -18,11 +18,12 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; import co.elastic.apm.agent.objectpool.Resetter; import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; import co.elastic.apm.agent.report.serialize.SerializationConstants; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; +import co.elastic.apm.agent.tracer.metadata.Request; import co.elastic.apm.agent.tracer.pooling.Allocator; import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.jctools.queues.atomic.MpmcAtomicArrayQueue; @@ -32,12 +33,12 @@ import java.nio.CharBuffer; import java.util.Enumeration; -import static co.elastic.apm.agent.impl.context.AbstractContext.REDACTED_CONTEXT_STRING; +import static co.elastic.apm.agent.impl.context.AbstractContextImpl.REDACTED_CONTEXT_STRING; -public class Request implements Recyclable, co.elastic.apm.agent.tracer.metadata.Request { +public class RequestImpl implements Recyclable, Request { - private static final ObjectPool charBufferPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, + private static final ObservableObjectPool charBufferPool = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue(128), false, new Allocator() { @Override public CharBuffer createInstance() { @@ -56,12 +57,12 @@ public void recycle(CharBuffer object) { * Should include any headers sent by the requester. Map will be taken by headers if supplied. */ private final PotentiallyMultiValuedMap headers = new PotentiallyMultiValuedMap(); - private final Socket socket = new Socket(); + private final SocketImpl socket = new SocketImpl(); /** * A complete Url, with scheme, host and path. * (Required) */ - private final Url url = new Url(); + private final UrlImpl url = new UrlImpl(); /** * A parsed key-value object of cookies */ @@ -120,13 +121,13 @@ public void redactBody() { setRawBody(REDACTED_CONTEXT_STRING); } - public Request addFormUrlEncodedParameter(String key, String value) { + public RequestImpl addFormUrlEncodedParameter(String key, String value) { this.postParams.add(key, value); return this; } @Override - public Request addFormUrlEncodedParameters(String key, String[] values) { + public RequestImpl addFormUrlEncodedParameters(String key, String[] values) { this.postParams.set(key, values); return this; } @@ -158,7 +159,7 @@ public CharBuffer getBodyBuffer() { } /** - * Returns the body buffer if it was written to and writing to it was finished through {@link Request#endOfBufferInput()} + * Returns the body buffer if it was written to and writing to it was finished through {@link RequestImpl#endOfBufferInput()} * * @return body buffer if it was written to and writing was finished; returns {@code null} otherwise. */ @@ -176,7 +177,7 @@ public PotentiallyMultiValuedMap getFormUrlEncodedParameters() { } @Override - public Request addHeader(String headerName, @Nullable String headerValue) { + public RequestImpl addHeader(String headerName, @Nullable String headerValue) { if (headerValue != null) { headers.add(headerName, headerValue); } @@ -184,7 +185,7 @@ public Request addHeader(String headerName, @Nullable String headerValue) { } @Override - public Request addHeader(String headerName, @Nullable Enumeration headerValues) { + public RequestImpl addHeader(String headerName, @Nullable Enumeration headerValues) { if (headerValues != null) { while (headerValues.hasMoreElements()) { headers.add(headerName, headerValues.nextElement()); @@ -207,7 +208,7 @@ public String getHttpVersion() { } @Override - public Request withHttpVersion(@Nullable String httpVersion) { + public RequestImpl withHttpVersion(@Nullable String httpVersion) { if (httpVersion != null) { this.httpVersion = getHttpVersion(httpVersion); } @@ -238,23 +239,23 @@ public String getMethod() { } @Override - public Request withMethod(@Nullable String method) { + public RequestImpl withMethod(@Nullable String method) { this.method = method; return this; } @Override - public Socket getSocket() { + public SocketImpl getSocket() { return socket; } @Override - public Url getUrl() { + public UrlImpl getUrl() { return url; } @Override - public Request addCookie(String cookieName, String cookieValue) { + public RequestImpl addCookie(String cookieName, String cookieValue) { cookies.add(cookieName, cookieValue); return this; } @@ -284,7 +285,7 @@ public void resetState() { rawBody = null; } - public void copyFrom(Request other) { + public void copyFrom(RequestImpl other) { this.postParams.copyFrom(other.postParams); this.headers.copyFrom(other.headers); this.httpVersion = other.httpVersion; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Response.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ResponseImpl.java similarity index 85% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Response.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ResponseImpl.java index 4a6ef90b99..50f57c7730 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Response.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ResponseImpl.java @@ -19,12 +19,13 @@ package co.elastic.apm.agent.impl.context; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; +import co.elastic.apm.agent.tracer.metadata.Response; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; import java.util.Collection; -public class Response implements Recyclable, co.elastic.apm.agent.tracer.metadata.Response { +public class ResponseImpl implements Recyclable, Response { /** * A mapping of HTTP headers of the response object @@ -48,7 +49,7 @@ public boolean isFinished() { } @Override - public Response withFinished(boolean finished) { + public ResponseImpl withFinished(boolean finished) { this.finished = finished; return this; } @@ -61,7 +62,7 @@ public Response withFinished(boolean finished) { * @return {@code this}, for fluent method chaining */ @Override - public Response addHeader(String headerName, @Nullable String headerValue) { + public ResponseImpl addHeader(String headerName, @Nullable String headerValue) { if (headerValue != null) { headers.add(headerName, headerValue); } @@ -69,7 +70,7 @@ public Response addHeader(String headerName, @Nullable String headerValue) { } @Override - public Response addHeader(String headerName, @Nullable Collection headerValues) { + public ResponseImpl addHeader(String headerName, @Nullable Collection headerValues) { if (headerValues != null) { for (String headerValue : headerValues) { headers.add(headerName, headerValue); @@ -89,7 +90,7 @@ public boolean isHeadersSent() { } @Override - public Response withHeadersSent(boolean headersSent) { + public ResponseImpl withHeadersSent(boolean headersSent) { this.headersSent = headersSent; return this; } @@ -102,7 +103,7 @@ public int getStatusCode() { } @Override - public Response withStatusCode(int statusCode) { + public ResponseImpl withStatusCode(int statusCode) { this.statusCode = statusCode; return this; } @@ -115,7 +116,7 @@ public void resetState() { statusCode = 0; } - public void copyFrom(Response other) { + public void copyFrom(ResponseImpl other) { this.finished = other.finished; this.headers.copyFrom(other.headers); this.headersSent = other.headersSent; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SanitizingWebProcessor.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SanitizingWebProcessor.java index 45f30d5ab1..4c79fddb99 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SanitizingWebProcessor.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SanitizingWebProcessor.java @@ -18,43 +18,43 @@ */ package co.elastic.apm.agent.impl.context; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.report.processor.Processor; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; import org.stagemonitor.configuration.ConfigurationRegistry; -import static co.elastic.apm.agent.impl.context.AbstractContext.REDACTED_CONTEXT_STRING; +import static co.elastic.apm.agent.impl.context.AbstractContextImpl.REDACTED_CONTEXT_STRING; /** - * Sanitizes web-related fields according to the {@link CoreConfiguration#sanitizeFieldNames} setting + * Sanitizes web-related fields according to the {@link CoreConfigurationImpl#sanitizeFieldNames} setting */ public class SanitizingWebProcessor implements Processor { - private final CoreConfiguration config; + private final CoreConfigurationImpl config; public SanitizingWebProcessor(ConfigurationRegistry configurationRegistry) { - config = configurationRegistry.getConfig(CoreConfiguration.class); + config = configurationRegistry.getConfig(CoreConfigurationImpl.class); } @Override - public void processBeforeReport(Transaction transaction) { + public void processBeforeReport(TransactionImpl transaction) { sanitizeContext(transaction.getContext()); } @Override - public void processBeforeReport(ErrorCapture error) { + public void processBeforeReport(ErrorCaptureImpl error) { sanitizeContext(error.getContext()); } - private void sanitizeContext(TransactionContext context) { + private void sanitizeContext(TransactionContextImpl context) { sanitizeRequest(context.getRequest()); sanitizeMap(context.getResponse().getHeaders()); } - private void sanitizeRequest(Request request) { + private void sanitizeRequest(RequestImpl request) { sanitizeMap(request.getHeaders()); // cookies are stored in Request.cookies // storing it twice would be wasteful diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceOrigin.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceOriginImpl.java similarity index 83% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceOrigin.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceOriginImpl.java index 5cdf69b407..a5d65ae213 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceOrigin.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceOriginImpl.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.impl.context; +import co.elastic.apm.agent.tracer.ServiceOrigin; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; @@ -28,7 +29,7 @@ * If a request originated from another service, * the service origin interface can be used to collect information about the origin service. */ -public class ServiceOrigin implements co.elastic.apm.agent.tracer.ServiceOrigin, Recyclable { +public class ServiceOriginImpl implements ServiceOrigin, Recyclable { @Nullable private String id; @@ -44,7 +45,7 @@ public String getId() { } @Override - public ServiceOrigin withId(@Nullable String id) { + public ServiceOriginImpl withId(@Nullable String id) { this.id = id; return this; } @@ -54,7 +55,7 @@ public StringBuilder getName() { } @Override - public ServiceOrigin withName(@Nullable CharSequence name) { + public ServiceOriginImpl withName(@Nullable CharSequence name) { this.name.setLength(0); if (name != null) { this.name.append(name); @@ -62,7 +63,7 @@ public ServiceOrigin withName(@Nullable CharSequence name) { return this; } - public ServiceOrigin appendToName(@Nullable String namePart) { + public ServiceOriginImpl appendToName(@Nullable String namePart) { if (namePart != null) { this.name.append(namePart); } @@ -75,7 +76,7 @@ public String getVersion() { } @Override - public ServiceOrigin withVersion(@Nullable String version) { + public ServiceOriginImpl withVersion(@Nullable String version) { this.version = version; return this; } @@ -93,7 +94,7 @@ public boolean hasContent() { version != null; } - public void copyFrom(ServiceOrigin other) { + public void copyFrom(ServiceOriginImpl other) { id = other.id; withName(other.getName()); version = other.version; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceTarget.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceTargetImpl.java similarity index 87% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceTarget.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceTargetImpl.java index 26433233a6..ba4eaefd1b 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceTarget.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/ServiceTargetImpl.java @@ -18,11 +18,12 @@ */ package co.elastic.apm.agent.impl.context; +import co.elastic.apm.agent.tracer.ServiceTarget; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -public class ServiceTarget implements Recyclable, co.elastic.apm.agent.tracer.ServiceTarget { +public class ServiceTargetImpl implements Recyclable, ServiceTarget { @Nullable private String type; @@ -36,12 +37,12 @@ public class ServiceTarget implements Recyclable, co.elastic.apm.agent.tracer.Se private final StringBuilder destinationResource; - public ServiceTarget() { + public ServiceTargetImpl() { this.name = new StringBuilder(); this.destinationResource = new StringBuilder(); } - public ServiceTarget withType(@Nullable String type) { + public ServiceTargetImpl withType(@Nullable String type) { if (typeSetByUser) { return this; } @@ -49,7 +50,7 @@ public ServiceTarget withType(@Nullable String type) { return this; } - public ServiceTarget withUserType(@Nullable String type) { + public ServiceTargetImpl withUserType(@Nullable String type) { this.type = type; this.typeSetByUser = true; return this; @@ -60,7 +61,7 @@ public String getType() { return type; } - public ServiceTarget withName(@Nullable CharSequence name) { + public ServiceTargetImpl withName(@Nullable CharSequence name) { if (name == null || name.length() == 0 || nameSetByUser) { return this; } @@ -70,7 +71,7 @@ public ServiceTarget withName(@Nullable CharSequence name) { return this; } - public ServiceTarget withUserName(@Nullable CharSequence name) { + public ServiceTargetImpl withUserName(@Nullable CharSequence name) { this.name.setLength(0); if (name != null) { this.name.append(name); @@ -89,7 +90,7 @@ public CharSequence getName() { * * @return this */ - public ServiceTarget withNameOnlyDestinationResource() { + public ServiceTargetImpl withNameOnlyDestinationResource() { onlyNameInResource = true; return this; } @@ -101,7 +102,7 @@ public ServiceTarget withNameOnlyDestinationResource() { * @param port network port * @return this */ - public ServiceTarget withHostPortName(@Nullable CharSequence host, int port) { + public ServiceTargetImpl withHostPortName(@Nullable CharSequence host, int port) { if (host == null || host.length() == 0 || nameSetByUser) { return this; } @@ -162,7 +163,7 @@ public boolean isSetByUser() { return typeSetByUser || nameSetByUser; } - public void copyFrom(ServiceTarget other) { + public void copyFrom(ServiceTargetImpl other) { this.withType(other.type); this.withName(other.name); this.typeSetByUser = other.typeSetByUser; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Socket.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SocketImpl.java similarity index 85% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Socket.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SocketImpl.java index 4340dd5e4b..b567526a74 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Socket.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SocketImpl.java @@ -18,11 +18,12 @@ */ package co.elastic.apm.agent.impl.context; +import co.elastic.apm.agent.tracer.metadata.Socket; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -public class Socket implements Recyclable, co.elastic.apm.agent.tracer.metadata.Socket { +public class SocketImpl implements Recyclable, Socket { @Nullable private String remoteAddress; @@ -33,7 +34,7 @@ public String getRemoteAddress() { } @Override - public Socket withRemoteAddress(@Nullable String remoteAddress) { + public SocketImpl withRemoteAddress(@Nullable String remoteAddress) { this.remoteAddress = remoteAddress; return this; } @@ -43,7 +44,7 @@ public void resetState() { remoteAddress = null; } - public void copyFrom(Socket other) { + public void copyFrom(SocketImpl other) { this.remoteAddress = other.remoteAddress; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SpanContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SpanContextImpl.java similarity index 77% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SpanContext.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SpanContextImpl.java index f5245d642c..aaf03038c2 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SpanContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/SpanContextImpl.java @@ -19,48 +19,50 @@ package co.elastic.apm.agent.impl.context; +import co.elastic.apm.agent.tracer.SpanContext; + /** * Any other arbitrary data captured by the agent, optionally provided by the user */ -public class SpanContext extends AbstractContext implements co.elastic.apm.agent.tracer.SpanContext { +public class SpanContextImpl extends AbstractContextImpl implements SpanContext { /** * An object containing contextual data for database spans */ - private final Db db = new Db(); + private final DbImpl db = new DbImpl(); /** * An object containing contextual data for outgoing HTTP spans */ - private final Http http = new Http(); + private final HttpImpl http = new HttpImpl(); /** * An object containing contextual data for service maps */ - private final Destination destination = new Destination(); + private final DestinationImpl destination = new DestinationImpl(); /** * An object containing contextual data for service target */ - private final ServiceTarget serviceTarget = new ServiceTarget(); + private final ServiceTargetImpl serviceTarget = new ServiceTargetImpl(); @Override - public Db getDb() { + public DbImpl getDb() { return db; } @Override - public Http getHttp() { + public HttpImpl getHttp() { return http; } @Override - public Destination getDestination() { + public DestinationImpl getDestination() { return destination; } @Override - public ServiceTarget getServiceTarget() { + public ServiceTargetImpl getServiceTarget() { return serviceTarget; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/TransactionContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/TransactionContextImpl.java similarity index 81% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/TransactionContext.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/TransactionContextImpl.java index 05df0e1015..523b70195f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/TransactionContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/TransactionContextImpl.java @@ -18,6 +18,8 @@ */ package co.elastic.apm.agent.impl.context; +import co.elastic.apm.agent.tracer.TransactionContext; + import java.util.Iterator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -28,7 +30,7 @@ *

* Any arbitrary contextual information regarding the event, captured by the agent, optionally provided by the user */ -public class TransactionContext extends AbstractContext implements co.elastic.apm.agent.tracer.TransactionContext { +public class TransactionContextImpl extends AbstractContextImpl implements TransactionContext { /** * A flat mapping of user-defined {@link String} keys and {@link String}, {@link Number} or {@link Boolean} values @@ -37,35 +39,35 @@ public class TransactionContext extends AbstractContext implements co.elastic.ap *

*/ private final Map custom = new ConcurrentHashMap<>(); - private final Response response = new Response(); + private final ResponseImpl response = new ResponseImpl(); /** * Request *

* If a log record was generated as a result of a http request, the http interface can be used to collect this information. */ - private final Request request = new Request(); + private final RequestImpl request = new RequestImpl(); /** * User *

* Describes the authenticated User for a request. */ - private final User user = new User(); + private final UserImpl user = new UserImpl(); /** * CloudOrigin *

* Describes the cloud information about the origin of a request. */ - private final CloudOrigin cloudOrigin = new CloudOrigin(); + private final CloudOriginImpl cloudOrigin = new CloudOriginImpl(); /** * ServiceOrigin *

* Describes the service information about the origin of a request. */ - private final ServiceOrigin serviceOrigin = new ServiceOrigin(); + private final ServiceOriginImpl serviceOrigin = new ServiceOriginImpl(); - public void copyFrom(TransactionContext other) { + public void copyFrom(TransactionContextImpl other) { super.copyFrom(other); response.copyFrom(other.response); request.copyFrom(other.request); @@ -79,7 +81,7 @@ public Object getCustom(String key) { } @Override - public Response getResponse() { + public ResponseImpl getResponse() { return response; } @@ -104,22 +106,22 @@ public boolean hasCustom() { } @Override - public Request getRequest() { + public RequestImpl getRequest() { return request; } @Override - public User getUser() { + public UserImpl getUser() { return user; } @Override - public CloudOrigin getCloudOrigin() { + public CloudOriginImpl getCloudOrigin() { return cloudOrigin; } @Override - public ServiceOrigin getServiceOrigin() { + public ServiceOriginImpl getServiceOrigin() { return serviceOrigin; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Url.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/UrlImpl.java similarity index 94% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Url.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/UrlImpl.java index bd94242d25..915e6250e2 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Url.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/UrlImpl.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.impl.context; +import co.elastic.apm.agent.tracer.metadata.Url; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; @@ -27,7 +28,7 @@ import java.net.URL; -public class Url implements Recyclable, co.elastic.apm.agent.tracer.metadata.Url { +public class UrlImpl implements Recyclable, Url { /** * The full, possibly agent-assembled URL of the request, e.g https://example.com:443/search?q=elasticsearch#top. @@ -67,7 +68,7 @@ public String getProtocol() { } @Override - public Url withProtocol(@Nullable String protocol) { + public UrlImpl withProtocol(@Nullable String protocol) { this.protocol = protocol; return this; } @@ -112,7 +113,7 @@ private void updateFull() { * @param value full URL * @return this */ - public Url withFull(CharSequence value) { + public UrlImpl withFull(CharSequence value) { if (!urlNeedsSanitization(value)) { full.setLength(0); full.append(value); @@ -150,7 +151,7 @@ public String getHostname() { } @Override - public Url withHostname(@Nullable String hostname) { + public UrlImpl withHostname(@Nullable String hostname) { this.hostname = hostname; return this; } @@ -163,7 +164,7 @@ public int getPort() { } @Override - public Url withPort(int port) { + public UrlImpl withPort(int port) { this.port = port; return this; } @@ -177,7 +178,7 @@ public String getPathname() { } @Override - public Url withPathname(@Nullable String pathname) { + public UrlImpl withPathname(@Nullable String pathname) { this.pathname = pathname; return this; } @@ -191,7 +192,7 @@ public String getSearch() { } @Override - public Url withSearch(@Nullable String search) { + public UrlImpl withSearch(@Nullable String search) { this.search = search; return this; } @@ -285,7 +286,7 @@ public void resetState() { search = null; } - public void copyFrom(Url other) { + public void copyFrom(UrlImpl other) { this.protocol = other.protocol; this.full.setLength(0); this.full.append(other.full); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/User.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/UserImpl.java similarity index 87% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/User.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/UserImpl.java index 00ea8751c7..880af3ed5f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/User.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/UserImpl.java @@ -18,12 +18,13 @@ */ package co.elastic.apm.agent.impl.context; +import co.elastic.apm.agent.tracer.metadata.User; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -public class User implements Recyclable, co.elastic.apm.agent.tracer.metadata.User { +public class UserImpl implements Recyclable, User { /** * Domain of the logged in user @@ -59,7 +60,7 @@ public String getDomain() { /** * Domain of the logged in user */ - public User withDomain(@Nullable String domain) { + public UserImpl withDomain(@Nullable String domain) { this.domain = domain; return this; } @@ -75,7 +76,7 @@ public String getId() { /** * Identifier of the logged in user, e.g. the primary key of the user */ - public User withId(@Nullable String id) { + public UserImpl withId(@Nullable String id) { this.id = id; return this; } @@ -91,7 +92,7 @@ public String getEmail() { /** * Email of the logged in user */ - public User withEmail(@Nullable String email) { + public UserImpl withEmail(@Nullable String email) { this.email = email; return this; } @@ -103,7 +104,7 @@ public String getUsername() { } @Override - public User withUsername(@Nullable String username) { + public UserImpl withUsername(@Nullable String username) { this.username = username; return this; } @@ -116,7 +117,7 @@ public void resetState() { username = null; } - public void copyFrom(User other) { + public void copyFrom(UserImpl other) { this.domain = other.domain; this.email = other.email; this.id = other.id; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/ErrorCapture.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/ErrorCaptureImpl.java similarity index 83% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/ErrorCapture.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/ErrorCaptureImpl.java index 5be5431390..065473b389 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/ErrorCapture.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/error/ErrorCaptureImpl.java @@ -19,15 +19,15 @@ package co.elastic.apm.agent.impl.error; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.context.TransactionContext; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.ErrorCapture; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; @@ -37,20 +37,20 @@ /** * Data captured by an agent representing an event occurring in a monitored service */ -public class ErrorCapture implements Recyclable, co.elastic.apm.agent.tracer.ErrorCapture { +public class ErrorCaptureImpl implements Recyclable, ErrorCapture { - private static final Logger logger = LoggerFactory.getLogger(ErrorCapture.class); + private static final Logger logger = LoggerFactory.getLogger(ErrorCaptureImpl.class); - private static final ThreadLocal activeError = new ThreadLocal<>(); + private static final ThreadLocal activeError = new ThreadLocal<>(); - private final TraceContext traceContext; + private final TraceContextImpl traceContext; /** * Context *

* Any arbitrary contextual information regarding the event, captured by the agent, optionally provided by the user */ - private final TransactionContext context = new TransactionContext(); + private final TransactionContextImpl context = new TransactionContextImpl(); private final ElasticApmTracer tracer; /** * Information about the originally thrown error. @@ -70,9 +70,9 @@ public class ErrorCapture implements Recyclable, co.elastic.apm.agent.tracer.Err private final StringBuilder culprit = new StringBuilder(); - public ErrorCapture(ElasticApmTracer tracer) { + public ErrorCaptureImpl(ElasticApmTracer tracer) { this.tracer = tracer; - traceContext = TraceContext.with128BitId(this.tracer); + traceContext = TraceContextImpl.with128BitId(this.tracer); } /** @@ -80,7 +80,7 @@ public ErrorCapture(ElasticApmTracer tracer) { *

* Any arbitrary contextual information regarding the event, captured by the agent, optionally provided by the user */ - public TransactionContext getContext() { + public TransactionContextImpl getContext() { return context; } @@ -100,7 +100,7 @@ public long getTimestamp() { return timestamp; } - public ErrorCapture withTimestamp(long epochMs) { + public ErrorCaptureImpl withTimestamp(long epochMs) { this.timestamp = epochMs; return this; } @@ -120,12 +120,12 @@ public void recycle() { } /** - * Creates a reference to a {@link TraceContext} + * Creates a reference to a {@link TraceContextImpl} * * @param parent parent trace context * @return {@code this}, for chaining */ - public ErrorCapture asChildOf(AbstractSpan parent) { + public ErrorCaptureImpl asChildOf(AbstractSpanImpl parent) { this.traceContext.asChildOf(parent.getTraceContext()); if (traceContext.getTraceId().isEmpty()) { logger.debug("Creating an Error as child of {} with a null trace_id", parent.getNameAsString()); @@ -133,13 +133,13 @@ public ErrorCapture asChildOf(AbstractSpan parent) { logger.trace("Stack trace related to Error capture: ", new Throwable()); } } - if (parent instanceof Transaction) { - Transaction transaction = (Transaction) parent; + if (parent instanceof TransactionImpl) { + TransactionImpl transaction = (TransactionImpl) parent; // The error might have occurred in a different thread than the one the transaction was recorded // That's why we have to ensure the visibility of the transaction properties context.copyFrom(transaction.getContextEnsureVisibility()); - } else if (parent instanceof Span) { - Span span = (Span) parent; + } else if (parent instanceof SpanImpl) { + SpanImpl span = (SpanImpl) parent; // TODO copy into SpanContext // https://github.com/elastic/apm-agent-java/issues/279 context.copyFrom(span.getContext()); @@ -148,7 +148,7 @@ public ErrorCapture asChildOf(AbstractSpan parent) { } @Override - public TraceContext getTraceContext() { + public TraceContextImpl getTraceContext() { return traceContext; } @@ -158,7 +158,7 @@ public void setException(Throwable e) { public StringBuilder getCulprit() { // lazily resolve culprit so that java.lang.Throwable.getStackTrace is called outside the application thread - final Collection applicationPackages = tracer.getConfig(StacktraceConfiguration.class).getApplicationPackages(); + final Collection applicationPackages = tracer.getConfig(StacktraceConfigurationImpl.class).getApplicationPackages(); if (exception != null && culprit.length() == 0 && !applicationPackages.isEmpty()) { computeCulprit(exception, applicationPackages); } @@ -201,19 +201,19 @@ private void setCulprit(StackTraceElement stackTraceElement) { } @Override - public ErrorCapture activate() { + public ErrorCaptureImpl activate() { activeError.set(this); return this; } @Override - public ErrorCapture deactivate() { + public ErrorCaptureImpl deactivate() { activeError.remove(); return this; } @Nullable - public static ErrorCapture getActive() { + public static ErrorCaptureImpl getActive() { return activeError.get(); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/CloudMetadataProvider.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/CloudMetadataProvider.java index caa060f0b7..6c27226bcf 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/CloudMetadataProvider.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/CloudMetadataProvider.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.impl.metadata; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.configuration.ServerlessConfigurationImpl; import co.elastic.apm.agent.util.ExecutorUtils; import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils; import co.elastic.apm.agent.util.UrlConnectionUtils; @@ -44,10 +44,10 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import static co.elastic.apm.agent.configuration.CoreConfiguration.CloudProvider.AWS; -import static co.elastic.apm.agent.configuration.CoreConfiguration.CloudProvider.AZURE; -import static co.elastic.apm.agent.configuration.CoreConfiguration.CloudProvider.GCP; -import static co.elastic.apm.agent.configuration.CoreConfiguration.CloudProvider.NONE; +import static co.elastic.apm.agent.configuration.CoreConfigurationImpl.CloudProvider.AWS; +import static co.elastic.apm.agent.configuration.CoreConfigurationImpl.CloudProvider.AZURE; +import static co.elastic.apm.agent.configuration.CoreConfigurationImpl.CloudProvider.GCP; +import static co.elastic.apm.agent.configuration.CoreConfigurationImpl.CloudProvider.NONE; import static java.nio.charset.StandardCharsets.UTF_8; public class CloudMetadataProvider { @@ -56,16 +56,16 @@ public class CloudMetadataProvider { private static final DslJson dslJson = new DslJson<>(new DslJson.Settings<>()); /** - * This method may block on multiple HTTP calls. See {@link #fetchAndParseCloudProviderInfo(CoreConfiguration.CloudProvider, int)} + * This method may block on multiple HTTP calls. See {@link #fetchAndParseCloudProviderInfo(CoreConfigurationImpl.CloudProvider, int)} * for details. * @param cloudProvider the configured cloud provided - used as an optimization to lookup specific APIs instead of trial-and-error * @param queryTimeoutMs a configured limitation for the maximum duration of each metadata discovery task * @return cloud provide metadata, or {@code null} if requested not to do any lookup by using - * {@link co.elastic.apm.agent.configuration.CoreConfiguration.CloudProvider#NONE} + * {@link CoreConfigurationImpl.CloudProvider#NONE} */ @Nullable - static CloudProviderInfo getCloudInfoProvider(final CoreConfiguration.CloudProvider cloudProvider, final int queryTimeoutMs, - ServerlessConfiguration serverlessConfiguration) { + static CloudProviderInfo getCloudInfoProvider(final CoreConfigurationImpl.CloudProvider cloudProvider, final int queryTimeoutMs, + ServerlessConfigurationImpl serverlessConfiguration) { if (serverlessConfiguration.runsOnAwsLambda()) { CloudProviderInfo awsLambdaInfo = new CloudProviderInfo("aws"); @@ -84,18 +84,18 @@ static CloudProviderInfo getCloudInfoProvider(final CoreConfiguration.CloudProvi /** * Automatic discovery of cloud provider and related metadata. This method is fetching data from public APIs * exposed by known cloud provider services through HTTP. - * When a specific {@link co.elastic.apm.agent.configuration.CoreConfiguration.CloudProvider} is specified, only + * When a specific {@link CoreConfigurationImpl.CloudProvider} is specified, only * the relevant API will be queried. - * However, when called with {@link co.elastic.apm.agent.configuration.CoreConfiguration.CloudProvider#AUTO}, all + * However, when called with {@link CoreConfigurationImpl.CloudProvider#AUTO}, all * known endpoints are queried concurrently. In such cases, blocking is expected to be long, bounded by the * HTTP requests timing out. * - * @param cloudProvider the expected {@link CoreConfiguration.CloudProvider} + * @param cloudProvider the expected {@link CoreConfigurationImpl.CloudProvider} * @param queryTimeoutMs timeout in milliseconds to limit the discovery duration * @return Automatically discovered {@link CloudProviderInfo}, or {@code null} if none found. */ @Nullable - static CloudProviderInfo fetchAndParseCloudProviderInfo(final CoreConfiguration.CloudProvider cloudProvider, final int queryTimeoutMs) { + static CloudProviderInfo fetchAndParseCloudProviderInfo(final CoreConfigurationImpl.CloudProvider cloudProvider, final int queryTimeoutMs) { Throwable unexpectedError = null; CloudProviderInfo cloudProviderInfo = null; @@ -137,7 +137,7 @@ static CloudProviderInfo fetchAndParseCloudProviderInfo(final CoreConfiguration. } @Nullable - private static CloudProviderInfo tryAllCloudProviders(final CoreConfiguration.CloudProvider cloudProvider, final int queryTimeoutMs) + private static CloudProviderInfo tryAllCloudProviders(final CoreConfigurationImpl.CloudProvider cloudProvider, final int queryTimeoutMs) throws InterruptedException, ExecutionException, TimeoutException { ExecutorService executor = ExecutorUtils.createThreadDaemonPool("cloud-metadata", 2, 2); @@ -192,7 +192,7 @@ public CloudProviderInfo call() { return cloudProviderInfo; } - private static void logSummary(CoreConfiguration.CloudProvider cloudProvider, + private static void logSummary(CoreConfigurationImpl.CloudProvider cloudProvider, @Nullable CloudProviderInfo cloudProviderInfo, @Nullable Throwable unexpectedError) { if (cloudProviderInfo == null) { if (cloudProvider == AWS || cloudProvider == AZURE || cloudProvider == GCP) { @@ -213,7 +213,7 @@ private static void logSummary(CoreConfiguration.CloudProvider cloudProvider, } @Nullable - private static CloudProviderInfo getAwsMetadata(int queryTimeoutMs, CoreConfiguration.CloudProvider configuredProvider) throws IOException { + private static CloudProviderInfo getAwsMetadata(int queryTimeoutMs, CoreConfigurationImpl.CloudProvider configuredProvider) throws IOException { String awsTokenUrl = "http://169.254.169.254/latest/api/token"; Map headers = new HashMap<>(1); headers.put("X-aws-ec2-metadata-token-ttl-seconds", "300"); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/MetaData.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/MetaData.java index 147c9b418d..39e3fc46ec 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/MetaData.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/MetaData.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.impl.metadata; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.ServerlessConfiguration; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.configuration.ServerlessConfigurationImpl; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.util.CompletableFuture; import co.elastic.apm.agent.util.ExecutorUtils; import org.stagemonitor.configuration.ConfigurationRegistry; @@ -39,7 +39,7 @@ public class MetaData { * Service * (Required) */ - private final Service service; + private final ServiceImpl service; /** * Process */ @@ -58,7 +58,7 @@ public class MetaData { private final ArrayList globalLabelKeys; private final ArrayList globalLabelValues; - MetaData(ProcessInfo process, Service service, SystemInfo system, @Nullable CloudProviderInfo cloudProviderInfo, + MetaData(ProcessInfo process, ServiceImpl service, SystemInfo system, @Nullable CloudProviderInfo cloudProviderInfo, Map globalLabels, @Nullable FaaSMetaDataExtension faasMetaDataExtension) { this.process = process; this.service = service; @@ -86,8 +86,8 @@ public class MetaData { * Creates a metadata to be used with all events sent by the agent. *

* NOTE: This method is blocking, possibly for several seconds, on outgoing HTTP requests, fetching for cloud - * metadata, unless the {@link CoreConfiguration#getCloudProvider() cloud_provider} config option is set to - * {@link CoreConfiguration.CloudProvider#NONE NONE}. + * metadata, unless the {@link CoreConfigurationImpl#getCloudProvider() cloud_provider} config option is set to + * {@link CoreConfigurationImpl.CloudProvider#NONE NONE}. *

* * @param configurationRegistry agent config @@ -99,13 +99,13 @@ public static MetaDataFuture create(ConfigurationRegistry configurationRegistry, ephemeralId = UUID.randomUUID().toString(); } - final CoreConfiguration coreConfiguration = configurationRegistry.getConfig(CoreConfiguration.class); + final CoreConfigurationImpl coreConfiguration = configurationRegistry.getConfig(CoreConfigurationImpl.class); - final ServerlessConfiguration serverlessConfiguration = configurationRegistry.getConfig(ServerlessConfiguration.class); + final ServerlessConfigurationImpl serverlessConfiguration = configurationRegistry.getConfig(ServerlessConfigurationImpl.class); final ServiceFactory serviceFactory = new ServiceFactory(); - final Service service = serviceFactory.createService(coreConfiguration, ephemeralId, serverlessConfiguration.runsOnAwsLambda()); + final ServiceImpl service = serviceFactory.createService(coreConfiguration, ephemeralId, serverlessConfiguration.runsOnAwsLambda()); final ProcessInfo processInformation = ProcessFactory.ForCurrentVM.INSTANCE.getProcessInformation(); - if (!configurationRegistry.getConfig(ReporterConfiguration.class).isIncludeProcessArguments()) { + if (!configurationRegistry.getConfig(ReporterConfigurationImpl.class).isIncludeProcessArguments()) { processInformation.getArgv().clear(); } @@ -163,7 +163,7 @@ public MetaData call() throws Exception { * * @return the service name */ - public Service getService() { + public ServiceImpl getService() { return service; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Node.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/NodeImpl.java similarity index 90% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Node.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/NodeImpl.java index 11717c4e1a..4bdfe4d8cd 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Node.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/NodeImpl.java @@ -18,12 +18,14 @@ */ package co.elastic.apm.agent.impl.metadata; +import co.elastic.apm.agent.tracer.service.Node; + import javax.annotation.Nullable; /** * A representation of a service node, ie JVM */ -public class Node implements co.elastic.apm.agent.tracer.service.Node { +public class NodeImpl implements Node { /** * (Optional) @@ -32,7 +34,7 @@ public class Node implements co.elastic.apm.agent.tracer.service.Node { @Nullable private final String name; - public Node(@Nullable String name) { + public NodeImpl(@Nullable String name) { this.name = name; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/ServiceFactory.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/ServiceFactory.java index 2a75c6b188..77a134b80e 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/ServiceFactory.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/ServiceFactory.java @@ -24,15 +24,15 @@ public class ServiceFactory { - public Service createService(CoreConfiguration coreConfiguration, String ephemeralId, boolean runsOnAwsLambda) { - Service service = new Service() + public ServiceImpl createService(CoreConfiguration coreConfiguration, String ephemeralId, boolean runsOnAwsLambda) { + ServiceImpl service = new ServiceImpl() .withName(coreConfiguration.getServiceName()) .withVersion(coreConfiguration.getServiceVersion()) .withEnvironment(coreConfiguration.getEnvironment()) .withAgent(new Agent("java", VersionUtils.getAgentVersion(), ephemeralId, coreConfiguration)) .withRuntime(new RuntimeInfo("Java", System.getProperty("java.version"))) .withLanguage(new Language("Java", System.getProperty("java.version"))) - .withNode(new Node(coreConfiguration.getServiceNodeName())); + .withNode(new NodeImpl(coreConfiguration.getServiceNodeName())); if (runsOnAwsLambda) { augmentServiceForAWSLambda(service); @@ -40,17 +40,17 @@ public Service createService(CoreConfiguration coreConfiguration, String ephemer return service; } - private void augmentServiceForAWSLambda(Service service) { + private void augmentServiceForAWSLambda(ServiceImpl service) { String runtimeName = PrivilegedActionUtils.getEnv("AWS_EXECUTION_ENV"); runtimeName = null != runtimeName ? runtimeName : "AWS_Lambda_java"; service.withRuntime(new RuntimeInfo(runtimeName, System.getProperty("java.version"))); - Node node = service.getNode(); + NodeImpl node = service.getNode(); String nodeName = (node != null) ? node.getName() : null; if (nodeName == null || nodeName.isEmpty()) { String serviceNodeName = PrivilegedActionUtils.getEnv("AWS_LAMBDA_LOG_STREAM_NAME"); if (null != serviceNodeName) { - service.withNode(new Node(serviceNodeName)); + service.withNode(new NodeImpl(serviceNodeName)); } } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Service.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/ServiceImpl.java similarity index 86% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Service.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/ServiceImpl.java index 6c44db9159..a1ed4d1309 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/Service.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/ServiceImpl.java @@ -19,13 +19,15 @@ package co.elastic.apm.agent.impl.metadata; +import co.elastic.apm.agent.tracer.service.Service; + import javax.annotation.Nullable; /** * Information about the instrumented Service */ -public class Service implements co.elastic.apm.agent.tracer.service.Service { +public class ServiceImpl implements Service { /** * Name and version of the Elastic APM agent @@ -47,7 +49,7 @@ public class Service implements co.elastic.apm.agent.tracer.service.Service { * Representation of a service node */ @Nullable - private Node node; + private NodeImpl node; /** * Immutable name of the service emitting this event * (Required) @@ -88,7 +90,7 @@ public Agent getAgent() { * Name and version of the Elastic APM agent * (Required) */ - public Service withAgent(Agent agent) { + public ServiceImpl withAgent(Agent agent) { this.agent = agent; return this; } @@ -106,7 +108,7 @@ public Framework getFramework() { * Name and version of the Framework * (Required) */ - public Service withFramework(Framework framework) { + public ServiceImpl withFramework(Framework framework) { this.framework = framework; return this; } @@ -122,21 +124,21 @@ public Language getLanguage() { /** * Name and version of the programming language used */ - public Service withLanguage(Language language) { + public ServiceImpl withLanguage(Language language) { this.language = language; return this; } @Nullable @Override - public Node getNode() { + public NodeImpl getNode() { return node; } /** * Representation of a service node */ - public Service withNode(Node node) { + public ServiceImpl withNode(NodeImpl node) { this.node = node; return this; } @@ -151,7 +153,7 @@ public String getName() { * Immutable name of the service emitting this event * (Required) */ - public Service withName(String name) { + public ServiceImpl withName(String name) { this.name = name; return this; } @@ -165,7 +167,7 @@ public String getEnvironment() { /** * Environment name of the service, e.g. "production" or "staging" */ - public Service withEnvironment(@Nullable String environment) { + public ServiceImpl withEnvironment(@Nullable String environment) { this.environment = environment; return this; } @@ -181,7 +183,7 @@ public RuntimeInfo getRuntime() { /** * Name and version of the language runtime running this service */ - public Service withRuntime(RuntimeInfo runtime) { + public ServiceImpl withRuntime(RuntimeInfo runtime) { this.runtime = runtime; return this; } @@ -195,7 +197,7 @@ public String getVersion() { /** * Version of the service emitting this event */ - public Service withVersion(@Nullable String version) { + public ServiceImpl withVersion(@Nullable String version) { this.version = version; return this; } @@ -211,7 +213,7 @@ public String getId() { /** * ID of the service emitting this event */ - public Service withId(@Nullable String id) { + public ServiceImpl withId(@Nullable String id) { this.id = id; return this; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/SystemInfo.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/SystemInfo.java index cb2c0f814a..0d6d386782 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/SystemInfo.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/metadata/SystemInfo.java @@ -20,7 +20,8 @@ import co.elastic.apm.agent.common.util.ProcessExecutionUtil; -import co.elastic.apm.agent.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.configuration.ServerlessConfigurationImpl; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -65,7 +66,7 @@ public class SystemInfo { private final String architecture; /** - * Hostname configured manually through {@link co.elastic.apm.agent.configuration.CoreConfiguration#hostname}. + * Hostname configured manually through {@link CoreConfigurationImpl#hostname}. */ @SuppressWarnings("JavadocReference") @Nullable @@ -112,13 +113,13 @@ public SystemInfo(String architecture, @Nullable String configuredHostname, @Nul * Creates a {@link SystemInfo} containing auto-discovered info about the system. * This method may block on reading files and executing external processes. * - * @param configuredHostname hostname configured through the {@link co.elastic.apm.agent.configuration.CoreConfiguration#hostname} config + * @param configuredHostname hostname configured through the {@link CoreConfigurationImpl#hostname} config * @param timeoutMillis enables to limit the execution of the system discovery task * @param serverlessConfiguration serverless config * @return a future from which this system's info can be obtained */ @SuppressWarnings("JavadocReference") - public static SystemInfo create(final @Nullable String configuredHostname, final long timeoutMillis, ServerlessConfiguration serverlessConfiguration) { + public static SystemInfo create(final @Nullable String configuredHostname, final long timeoutMillis, ServerlessConfigurationImpl serverlessConfiguration) { final String osName = System.getProperty("os.name"); final String osArch = System.getProperty("os.arch"); @@ -459,7 +460,7 @@ public String getHostname() { } /** - * The hostname manually configured through {@link co.elastic.apm.agent.configuration.CoreConfiguration#hostname} + * The hostname manually configured through {@link CoreConfigurationImpl#hostname} * * @return the manually configured hostname */ diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/ConstantSampler.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/ConstantSampler.java index 4a700880f0..dc4d59d199 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/ConstantSampler.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/ConstantSampler.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.sampling; -import co.elastic.apm.agent.impl.transaction.Id; +import co.elastic.apm.agent.impl.transaction.IdImpl; import co.elastic.apm.agent.impl.transaction.TraceState; /** @@ -49,7 +49,7 @@ public static Sampler of(boolean decision) { } @Override - public boolean isSampled(Id traceId) { + public boolean isSampled(IdImpl traceId) { return decision; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/ProbabilitySampler.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/ProbabilitySampler.java index c146defd20..21909403ea 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/ProbabilitySampler.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/ProbabilitySampler.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.sampling; -import co.elastic.apm.agent.impl.transaction.Id; +import co.elastic.apm.agent.impl.transaction.IdImpl; import co.elastic.apm.agent.impl.transaction.TraceState; /** @@ -29,9 +29,9 @@ *

* Implementation notes: *

- * We are taking advantage of the fact, that the {@link Id} is randomly generated. + * We are taking advantage of the fact, that the {@link IdImpl} is randomly generated. * So instead of generating another random number, - * we just see if the long value returned by {@link Id#getLeastSignificantBits()} + * we just see if the long value returned by {@link IdImpl#getLeastSignificantBits()} * falls into the range between the {@code lowerBound} and the higherBound. * This is a visual representation of the mechanism with a sampling rate of 0.5 (=50%): *
@@ -70,7 +70,7 @@ public static Sampler of(double samplingRate) {
     }
 
     @Override
-    public boolean isSampled(Id traceId) {
+    public boolean isSampled(IdImpl traceId) {
         final long leastSignificantBits = traceId.getLeastSignificantBits();
         return leastSignificantBits > lowerBound && leastSignificantBits < higherBound;
     }
diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/Sampler.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/Sampler.java
index 53a48f1b57..65e2bc2adb 100644
--- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/Sampler.java
+++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/sampling/Sampler.java
@@ -18,22 +18,22 @@
  */
 package co.elastic.apm.agent.impl.sampling;
 
-import co.elastic.apm.agent.impl.transaction.Id;
-import co.elastic.apm.agent.impl.transaction.Span;
-import co.elastic.apm.agent.impl.transaction.Transaction;
+import co.elastic.apm.agent.impl.transaction.IdImpl;
+import co.elastic.apm.agent.impl.transaction.SpanImpl;
+import co.elastic.apm.agent.impl.transaction.TransactionImpl;
 
 /**
- * A sampler is responsible for determining whether a {@link Transaction} should be sampled.
+ * A sampler is responsible for determining whether a {@link TransactionImpl} should be sampled.
  * 

* In contrast other tracing systems, * in Elastic APM, - * non-sampled {@link Transaction}s do get reported to the APM server. + * non-sampled {@link TransactionImpl}s do get reported to the APM server. * However, * to keep the size at a minimum, - * the reported {@link Transaction} only contains the transaction name, + * the reported {@link TransactionImpl} only contains the transaction name, * the duration and the id. * Also, - * {@link Span}s of non sampled {@link Transaction}s are not reported. + * {@link SpanImpl}s of non sampled {@link TransactionImpl}s are not reported. *

*/ public interface Sampler { @@ -44,7 +44,7 @@ public interface Sampler { * @param traceId The id of the transaction. * @return The sampling decision. */ - boolean isSampled(Id traceId); + boolean isSampled(IdImpl traceId); /** * @return current sample rate diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfigurationImpl.java similarity index 97% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfiguration.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfigurationImpl.java index 69db9c4dc6..c71ac3c97e 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfigurationImpl.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.impl.stacktrace; +import co.elastic.apm.agent.tracer.configuration.StacktraceConfiguration; import co.elastic.apm.agent.tracer.configuration.TimeDuration; import co.elastic.apm.agent.tracer.configuration.TimeDurationValueConverter; import org.stagemonitor.configuration.ConfigurationOption; @@ -26,7 +27,7 @@ import java.util.Collection; import java.util.Collections; -public class StacktraceConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.agent.tracer.configuration.StacktraceConfiguration { +public class StacktraceConfigurationImpl extends ConfigurationOptionProvider implements StacktraceConfiguration { private static final String STACKTRACE_CATEGORY = "Stacktrace"; public static final String APPLICATION_PACKAGES = "application_packages"; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractRefCountedContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractRefCountedContext.java index 9183f4d37c..fd4cc9d7cf 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractRefCountedContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractRefCountedContext.java @@ -25,7 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger; -public abstract class AbstractRefCountedContext> extends ElasticContext implements Recyclable { +public abstract class AbstractRefCountedContext> extends TraceStateImpl implements Recyclable { private static final Logger logger = LoggerFactory.getLogger(AbstractRefCountedContext.class); private final AtomicInteger references = new AtomicInteger(); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpan.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpanImpl.java similarity index 90% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpan.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpanImpl.java index acff311f89..d9e1c57c97 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpan.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractSpanImpl.java @@ -19,15 +19,16 @@ package co.elastic.apm.agent.impl.transaction; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.baggage.Baggage; -import co.elastic.apm.agent.impl.context.AbstractContext; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; +import co.elastic.apm.agent.impl.context.AbstractContextImpl; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.sdk.internal.collections.LongList; import co.elastic.apm.agent.sdk.internal.util.LoggerUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.AbstractSpan; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; import co.elastic.apm.agent.tracer.pooling.Recyclable; @@ -40,15 +41,15 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -public abstract class AbstractSpan> extends AbstractRefCountedContext implements Recyclable, co.elastic.apm.agent.tracer.AbstractSpan { - private static final Logger logger = LoggerFactory.getLogger(AbstractSpan.class); +public abstract class AbstractSpanImpl> extends AbstractRefCountedContext implements Recyclable, AbstractSpan { + private static final Logger logger = LoggerFactory.getLogger(AbstractSpanImpl.class); private static final Logger oneTimeDuplicatedEndLogger = LoggerUtils.logOnce(logger); private static final Logger oneTimeMaxSpanLinksLogger = LoggerUtils.logOnce(logger); protected static final double MS_IN_MICROS = TimeUnit.MILLISECONDS.toMicros(1); - protected final TraceContext traceContext; + protected final TraceContextImpl traceContext; - protected Baggage baggage = Baggage.EMPTY; + protected BaggageImpl baggage = BaggageImpl.EMPTY; /** * Generic designation of a transaction in the scope of a single service (eg: 'GET /users/:id') @@ -71,7 +72,7 @@ public abstract class AbstractSpan> extends AbstractRe * This use case for child ids is modifying parent/child relationships for profiler-inferred spans. * Inferred spans are sent after a profiling session ends (5s by default) and after stack traces have been processed into inferred spans. * Regular spans are sent right after the event (for example a DB call) has occurred. - * The effect is that a regular span cannot have a {@link TraceContext#parentId} pointing to an inferred span. + * The effect is that a regular span cannot have a {@link TraceContextImpl#parentId} pointing to an inferred span. * That is because the latter did not exist at the time the regular span has been created. *

*

@@ -113,11 +114,11 @@ public abstract class AbstractSpan> extends AbstractRe private volatile boolean sync = true; - protected final SpanAtomicReference bufferedSpan = new SpanAtomicReference<>(); + protected final SpanAtomicReference bufferedSpan = new SpanAtomicReference<>(); // Span links handling public static final int MAX_ALLOWED_SPAN_LINKS = 1000; - private final List spanLinks = new UniqueSpanLinkArrayList(); + private final List spanLinks = new UniqueSpanLinkArrayList(); @Nullable private OTelSpanKind otelKind = null; @@ -190,11 +191,11 @@ public long getDuration() { } } - public AbstractSpan(ElasticApmTracer tracer) { + public AbstractSpanImpl(ElasticApmTracer tracer) { super(tracer); - traceContext = TraceContext.with64BitId(this.tracer); - boolean selfTimeCollectionEnabled = !WildcardMatcher.isAnyMatch(tracer.getConfig(ReporterConfiguration.class).getDisableMetrics(), "span.self_time"); - boolean breakdownMetricsEnabled = tracer.getConfig(CoreConfiguration.class).isBreakdownMetricsEnabled(); + traceContext = TraceContextImpl.with64BitId(this.tracer); + boolean selfTimeCollectionEnabled = !WildcardMatcher.isAnyMatch(tracer.getConfig(ReporterConfigurationImpl.class).getDisableMetrics(), "span.self_time"); + boolean breakdownMetricsEnabled = tracer.getConfig(CoreConfigurationImpl.class).isBreakdownMetricsEnabled(); collectBreakdownMetrics = selfTimeCollectionEnabled && breakdownMetricsEnabled; } @@ -215,7 +216,7 @@ public long getSelfDuration() { } public double getDurationMs() { - return getDuration() / AbstractSpan.MS_IN_MICROS; + return getDuration() / AbstractSpanImpl.MS_IN_MICROS; } /** @@ -339,7 +340,7 @@ public long getTimestamp() { } @Override - public TraceContext getTraceContext() { + public TraceContextImpl getTraceContext() { return traceContext; } @@ -371,7 +372,7 @@ public boolean addSpanLink( } boolean added = false; try { - TraceContext childTraceContext = tracer.createSpanLink(); + TraceContextImpl childTraceContext = tracer.createSpanLink(); if (childTraceContext.asChildOf(carrier, headerGetter, false)) { added = spanLinks.add(childTraceContext); } @@ -393,13 +394,13 @@ public boolean addSpanLink( * @param the parent type - AbstractSpan, TraceContext or Tracer * @return {@code true} if added, {@code false} otherwise */ - public boolean addSpanLink(TraceContext.ChildContextCreator childContextCreator, T parent) { + public boolean addSpanLink(TraceContextImpl.ChildContextCreator childContextCreator, T parent) { if (!canAddSpanLink()) { return false; } boolean added = false; try { - TraceContext childTraceContext = tracer.createSpanLink(); + TraceContextImpl childTraceContext = tracer.createSpanLink(); if (childContextCreator.asChildOf(childTraceContext, parent)) { added = spanLinks.add(childTraceContext); } @@ -413,13 +414,13 @@ public boolean addSpanLink(TraceContext.ChildContextCreator childContextC } /** - * Returns a list of links from this span to other spans in the format of child {@link TraceContext}s, of which parent is the linked + * Returns a list of links from this span to other spans in the format of child {@link TraceContextImpl}s, of which parent is the linked * span. For each entry in the returned list, the linked span's {@code traceId} can be retrieved through - * {@link TraceContext#getTraceId()} and the {@code spanId} can be retrieved through {@link TraceContext#getParentId()}. + * {@link TraceContextImpl#getTraceId()} and the {@code spanId} can be retrieved through {@link TraceContextImpl#getParentId()}. * - * @return a list of child {@link TraceContext}s of linked spans + * @return a list of child {@link TraceContextImpl}s of linked spans */ - public List getSpanLinks() { + public List getSpanLinks() { return spanLinks; } @@ -433,7 +434,7 @@ public void resetState() { timestamp.set(0L); endTimestamp.set(0L); traceContext.resetState(); - baggage = Baggage.EMPTY; + baggage = BaggageImpl.EMPTY; childDurations.resetState(); namePriority = PRIORITY_DEFAULT; discardRequested = false; @@ -457,19 +458,19 @@ private void recycleSpanLinks() { } @Override - public Span createSpan() { + public SpanImpl createSpan() { return createSpan(getBaggage()); } - public Span createSpan(long epochMicros) { + public SpanImpl createSpan(long epochMicros) { return createSpan(getBaggage(), epochMicros); } - public Span createSpan(Baggage newBaggage) { + public SpanImpl createSpan(BaggageImpl newBaggage) { return createSpan(newBaggage, traceContext.getClock().getEpochMicros()); } - private Span createSpan(Baggage baggage, long epochMicros) { + private SpanImpl createSpan(BaggageImpl baggage, long epochMicros) { return tracer.startSpan(this, baggage, epochMicros); } @@ -528,7 +529,7 @@ public void addLabel(String key, Boolean value) { } @Override - public abstract AbstractContext getContext(); + public abstract AbstractContextImpl getContext(); /** * Called after the span has been started and its parent references are set @@ -539,7 +540,7 @@ protected void onAfterStart() { // or even after its reported and the last child span is ended incrementReferences(); - List baggageToAttach = tracer.getConfig(CoreConfiguration.class).getBaggageToAttach(); + List baggageToAttach = tracer.getConfig(CoreConfigurationImpl.class).getBaggageToAttach(); baggage.storeBaggageInAttributes(this, baggageToAttach); } @@ -564,7 +565,7 @@ public final void end(long epochMicros) { beforeEnd(epochMicros); this.finished = true; - Span buffered = bufferedSpan.incrementReferencesAndGet(); + SpanImpl buffered = bufferedSpan.incrementReferencesAndGet(); if (buffered != null) { try { if (bufferedSpan.compareAndSet(buffered, null)) { @@ -605,11 +606,11 @@ protected boolean hasCapturedExceptions() { protected abstract void afterEnd(); - public boolean isChildOf(AbstractSpan parent) { + public boolean isChildOf(AbstractSpanImpl parent) { return traceContext.isChildOf(parent.traceContext) || parent.hasChildId(traceContext.getId()); } - private boolean hasChildId(Id spanId) { + private boolean hasChildId(IdImpl spanId) { if (childIds != null) { return childIds.contains(spanId.readLong(0)); } @@ -617,7 +618,7 @@ private boolean hasChildId(Id spanId) { } @Override - public Baggage getBaggage() { + public BaggageImpl getBaggage() { return baggage; } @@ -627,7 +628,7 @@ public Baggage getBaggage() { * * @return the transaction. */ - public abstract Transaction getParentTransaction(); + public abstract TransactionImpl getParentTransaction(); /** * Set start timestamp @@ -714,7 +715,7 @@ public T withUserOutcome(Outcome outcome) { } @Override - public AbstractSpan getSpan() { + public AbstractSpanImpl getSpan() { return this; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/DroppedSpanStats.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/DroppedSpanStats.java index 74bcf45c95..ada478514e 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/DroppedSpanStats.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/DroppedSpanStats.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.impl.transaction; -import co.elastic.apm.agent.impl.context.ServiceTarget; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.agent.impl.context.ServiceTargetImpl; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.util.CharSequenceUtils; @@ -59,7 +59,7 @@ public StatsKey() { cachedHashCode = Integer.MIN_VALUE; } - public StatsKey init(ServiceTarget serviceTarget, Outcome outcome) { + public StatsKey init(ServiceTargetImpl serviceTarget, Outcome outcome) { resetState(); // we have to use a copy as argument is mutable will be recycled this.serviceType = Objects.requireNonNull(serviceTarget.getType()); @@ -148,14 +148,14 @@ public void resetState() { } } - private static final ObjectPool statsKeyObjectPool = QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue(512), false, new Allocator() { + private static final ObservableObjectPool statsKeyObjectPool = QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue(512), false, new Allocator() { @Override public StatsKey createInstance() { return new StatsKey(); } }); - private static final ObjectPool statsObjectPool = QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue(512), false, new Allocator() { + private static final ObservableObjectPool statsObjectPool = QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue(512), false, new Allocator() { @Override public Stats createInstance() { return new Stats(); @@ -167,12 +167,12 @@ public Stats createInstance() { // only used during testing @Nullable Stats getStats(String serviceType, @Nullable String serviceName, Outcome outcome){ - ServiceTarget st = new ServiceTarget().withType(serviceType).withName(serviceName); + ServiceTargetImpl st = new ServiceTargetImpl().withType(serviceType).withName(serviceName); return statsMap.get(new StatsKey().init(st, outcome)); } - public void captureDroppedSpan(Span span) { - ServiceTarget serviceTarget = span.getContext().getServiceTarget(); + public void captureDroppedSpan(SpanImpl span) { + ServiceTargetImpl serviceTarget = span.getContext().getServiceTarget(); if (!span.isExit() || !serviceTarget.hasContent() ) { return; } @@ -187,7 +187,7 @@ public void captureDroppedSpan(Span span) { stats.sum.addAndGet(span.getDuration()); } - private Stats getOrCreateStats(ServiceTarget serviceTarget, Outcome outcome) { + private Stats getOrCreateStats(ServiceTargetImpl serviceTarget, Outcome outcome) { StatsKey statsKey = statsKeyObjectPool.createInstance().init(serviceTarget, outcome); Stats stats = statsMap.get(statsKey); if (stats != null) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/EpochTickClock.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/EpochTickClock.java index ad205eea0b..e3d5c95422 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/EpochTickClock.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/EpochTickClock.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.tracer.pooling.Recyclable; /** - * This clock makes sure that each {@link Span} and {@link Transaction} uses a consistent clock + * This clock makes sure that each {@link SpanImpl} and {@link TransactionImpl} uses a consistent clock * which does not drift in case of NTP updates or leap seconds. *

* The clock is initialized with wall clock time when the transaction starts and from there on diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Faas.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasImpl.java similarity index 82% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Faas.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasImpl.java index 1299184003..5025320e94 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Faas.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasImpl.java @@ -18,11 +18,12 @@ */ package co.elastic.apm.agent.impl.transaction; +import co.elastic.apm.agent.tracer.Faas; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -public class Faas implements co.elastic.apm.agent.tracer.Faas, Recyclable { +public class FaasImpl implements Faas, Recyclable { @Nullable private String execution; @@ -38,7 +39,7 @@ public class Faas implements co.elastic.apm.agent.tracer.Faas, Recyclable { private boolean coldStart; - private final FaasTrigger trigger = new FaasTrigger(); + private final FaasTriggerImpl trigger = new FaasTriggerImpl(); @Nullable public String getExecution() { @@ -49,7 +50,7 @@ public boolean isColdStart() { return coldStart; } - public FaasTrigger getTrigger() { + public FaasTriggerImpl getTrigger() { return trigger; } @@ -69,31 +70,31 @@ public String getVersion() { } @Override - public Faas withExecution(@Nullable String execution) { + public FaasImpl withExecution(@Nullable String execution) { this.execution = execution; return this; } @Override - public Faas withColdStart(boolean coldStart) { + public FaasImpl withColdStart(boolean coldStart) { this.coldStart = coldStart; return this; } @Override - public Faas withId(@Nullable String id) { + public FaasImpl withId(@Nullable String id) { this.id = id; return this; } @Override - public Faas withName(@Nullable String name) { + public FaasImpl withName(@Nullable String name) { this.name = name; return this; } @Override - public Faas withVersion(@Nullable String version) { + public FaasImpl withVersion(@Nullable String version) { this.version = version; return this; } @@ -108,7 +109,7 @@ public void resetState() { this.trigger.resetState(); } - public void copyFrom(Faas other) { + public void copyFrom(FaasImpl other) { this.execution = other.execution; this.id = other.id; this.name = other.name; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasTrigger.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasTriggerImpl.java similarity index 84% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasTrigger.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasTriggerImpl.java index d3d3fb3775..5e26825f87 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasTrigger.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/FaasTriggerImpl.java @@ -18,11 +18,12 @@ */ package co.elastic.apm.agent.impl.transaction; +import co.elastic.apm.agent.tracer.FaasTrigger; import co.elastic.apm.agent.tracer.pooling.Recyclable; import javax.annotation.Nullable; -public class FaasTrigger implements co.elastic.apm.agent.tracer.FaasTrigger, Recyclable { +public class FaasTriggerImpl implements FaasTrigger, Recyclable { @Nullable private String type; @@ -41,13 +42,13 @@ public String getRequestId() { } @Override - public FaasTrigger withType(@Nullable String type) { + public FaasTriggerImpl withType(@Nullable String type) { this.type = type; return this; } @Override - public FaasTrigger withRequestId(@Nullable String requestId) { + public FaasTriggerImpl withRequestId(@Nullable String requestId) { this.requestId = requestId; return this; } @@ -58,7 +59,7 @@ public void resetState() { this.requestId = null; } - public void copyFrom(FaasTrigger other) { + public void copyFrom(FaasTriggerImpl other) { this.type = other.type; this.requestId = other.requestId; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Id.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/IdImpl.java similarity index 94% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Id.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/IdImpl.java index 899bf68d28..223590ab3c 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Id.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/IdImpl.java @@ -20,6 +20,7 @@ import co.elastic.apm.agent.report.serialize.Base64SerializationUtils; import co.elastic.apm.agent.report.serialize.HexSerializationUtils; +import co.elastic.apm.agent.tracer.Id; import co.elastic.apm.agent.tracer.pooling.Recyclable; import co.elastic.apm.agent.tracer.util.HexUtils; import com.dslplatform.json.JsonWriter; @@ -33,22 +34,22 @@ /** * A 128 bit globally unique ID of the whole trace forest */ -public class Id implements Recyclable, co.elastic.apm.agent.tracer.Id { +public class IdImpl implements Recyclable, Id { private final byte[] data; private boolean empty = true; @Nullable private String cachedStringRepresentation; - public static Id new128BitId() { - return new Id(16); + public static IdImpl new128BitId() { + return new IdImpl(16); } - public static Id new64BitId() { - return new Id(8); + public static IdImpl new64BitId() { + return new IdImpl(8); } - private Id(int idLengthBytes) { + private IdImpl(int idLengthBytes) { data = new byte[idLengthBytes]; } @@ -111,7 +112,7 @@ public void resetState() { onMutation(true); } - public void copyFrom(Id other) { + public void copyFrom(IdImpl other) { System.arraycopy(other.data, 0, data, 0, data.length); this.cachedStringRepresentation = other.cachedStringRepresentation; this.empty = other.empty; @@ -130,7 +131,7 @@ private void onMutation(boolean empty) { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - Id that = (Id) o; + IdImpl that = (IdImpl) o; return Arrays.equals(data, that.data); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/SpanAtomicReference.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/SpanAtomicReference.java index d95315a53d..83487c2750 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/SpanAtomicReference.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/SpanAtomicReference.java @@ -20,7 +20,7 @@ import javax.annotation.Nullable; -class SpanAtomicReference> { +class SpanAtomicReference> { @Nullable private V ref; @@ -28,9 +28,9 @@ class SpanAtomicReference> { private final Object LOCK = new Object(); /** - * Increments the referenced {@link AbstractSpan} reference count and returns it. The returned span is guaranteed not to be recycled. + * Increments the referenced {@link AbstractSpanImpl} reference count and returns it. The returned span is guaranteed not to be recycled. * It is then the responsibility of the caller to decrement the ref count appropriately. - * @return the referenced {@link AbstractSpan} with reference count incremented, or {@code null} if no span is referenced + * @return the referenced {@link AbstractSpanImpl} with reference count incremented, or {@code null} if no span is referenced */ @Nullable public V incrementReferencesAndGet() { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Span.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/SpanImpl.java similarity index 88% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Span.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/SpanImpl.java index c4183d2cff..e1d3d50e86 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Span.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/SpanImpl.java @@ -18,15 +18,16 @@ */ package co.elastic.apm.agent.impl.transaction; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.baggage.Baggage; -import co.elastic.apm.agent.impl.context.Db; -import co.elastic.apm.agent.impl.context.Message; -import co.elastic.apm.agent.impl.context.ServiceTarget; -import co.elastic.apm.agent.impl.context.SpanContext; -import co.elastic.apm.agent.impl.context.Url; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; +import co.elastic.apm.agent.impl.context.DbImpl; +import co.elastic.apm.agent.impl.context.MessageImpl; +import co.elastic.apm.agent.impl.context.ServiceTargetImpl; +import co.elastic.apm.agent.impl.context.SpanContextImpl; +import co.elastic.apm.agent.impl.context.UrlImpl; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.util.ResultUtil; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -39,12 +40,12 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; -public class Span extends AbstractSpan implements Recyclable, co.elastic.apm.agent.tracer.Span { +public class SpanImpl extends AbstractSpanImpl implements Recyclable, Span { - private static final Logger logger = LoggerFactory.getLogger(Span.class); + private static final Logger logger = LoggerFactory.getLogger(SpanImpl.class); public static final long MAX_LOG_INTERVAL_MICRO_SECS = TimeUnit.MINUTES.toMicros(5); private static long lastSpanMaxWarningTimestamp; - private final StacktraceConfiguration stacktraceConfiguration; + private final StacktraceConfigurationImpl stacktraceConfiguration; /** * A subtype describing this span (eg 'mysql', 'elasticsearch', 'jsf' etc) @@ -63,14 +64,14 @@ public class Span extends AbstractSpan implements Recyclable, co.elastic.a /** * Any other arbitrary data captured by the agent, optionally provided by the user */ - private final SpanContext context = new SpanContext(); + private final SpanContextImpl context = new SpanContextImpl(); private final Composite composite = new Composite(); @Nullable private Throwable stacktrace; @Nullable - private AbstractSpan parent; + private AbstractSpanImpl parent; @Nullable - private Transaction transaction; + private TransactionImpl transaction; @Nullable private List stackFrames; @@ -86,33 +87,33 @@ public void setNonDiscardable() { } } - public Span(ElasticApmTracer tracer) { + public SpanImpl(ElasticApmTracer tracer) { super(tracer); - this.stacktraceConfiguration = tracer.getConfig(StacktraceConfiguration.class); + this.stacktraceConfiguration = tracer.getConfig(StacktraceConfigurationImpl.class); } - public Span start(TraceContext.ChildContextCreator childContextCreator, T parentContext, Baggage parentBaggage, long epochMicros) { + public SpanImpl start(TraceContextImpl.ChildContextCreator childContextCreator, T parentContext, BaggageImpl parentBaggage, long epochMicros) { this.baggage = parentBaggage; childContextCreator.asChildOf(traceContext, parentContext); - if (parentContext instanceof Transaction) { - this.transaction = (Transaction) parentContext; + if (parentContext instanceof TransactionImpl) { + this.transaction = (TransactionImpl) parentContext; this.parent = this.transaction; - } else if (parentContext instanceof Span) { - final Span parentSpan = (Span) parentContext; + } else if (parentContext instanceof SpanImpl) { + final SpanImpl parentSpan = (SpanImpl) parentContext; this.parent = parentSpan; this.transaction = parentSpan.transaction; } return start(epochMicros); } - private Span start(long epochMicros) { + private SpanImpl start(long epochMicros) { if (transaction != null) { SpanCount spanCount = transaction.getSpanCount(); if (transaction.isSpanLimitReached()) { if (epochMicros - lastSpanMaxWarningTimestamp > MAX_LOG_INTERVAL_MICRO_SECS) { lastSpanMaxWarningTimestamp = epochMicros; logger.warn("Max spans ({}) for transaction {} has been reached. For this transaction and possibly others, further spans will be dropped. See config param 'transaction_max_spans'.", - tracer.getConfig(CoreConfiguration.class).getTransactionMaxSpans(), transaction); + tracer.getConfig(CoreConfigurationImpl.class).getTransactionMaxSpans(), transaction); } logger.debug("Span exceeds transaction_max_spans {}", this); traceContext.setRecorded(false); @@ -149,7 +150,7 @@ protected void onAfterStart() { * Any other arbitrary data captured by the agent, optionally provided by the user */ @Override - public SpanContext getContext() { + public SpanContextImpl getContext() { return context; } @@ -162,13 +163,13 @@ public Composite getComposite() { } @Override - public Span withSubtype(@Nullable String subtype) { + public SpanImpl withSubtype(@Nullable String subtype) { this.subtype = normalizeEmpty(subtype); return this; } @Override - public Span withAction(@Nullable String action) { + public SpanImpl withAction(@Nullable String action) { this.action = normalizeEmpty(action); return this; } @@ -235,11 +236,11 @@ public void beforeEnd(long epochMicros) { // auto-infer context.destination.service.resource as per spec: // https://github.com/elastic/apm/blob/main/specs/agents/tracing-spans-destination.md#contextdestinationserviceresource - ServiceTarget serviceTarget = getContext().getServiceTarget(); + ServiceTargetImpl serviceTarget = getContext().getServiceTarget(); if (isExit() && !serviceTarget.hasContent() && !serviceTarget.isSetByUser()) { - Db db = context.getDb(); - Message message = context.getMessage(); - Url httpUrl = context.getHttp().getInternalUrl(); + DbImpl db = context.getDb(); + MessageImpl message = context.getMessage(); + UrlImpl httpUrl = context.getHttp().getInternalUrl(); String targetServiceType = (subtype != null) ? subtype : type; if (db.hasContent()) { serviceTarget.withType(targetServiceType).withName(db.getInstance()); @@ -286,7 +287,7 @@ protected void afterEnd() { this.incrementReferences(); try { if (transaction != null && transaction.isSpanCompressionEnabled() && parent != null) { - Span parentBuffered = parent.bufferedSpan.incrementReferencesAndGet(); + SpanImpl parentBuffered = parent.bufferedSpan.incrementReferencesAndGet(); try { //per the reference, if it is not compression-eligible or if its parent has already ended, it is reported immediately if (parent.isFinished() || !isCompressionEligible()) { @@ -351,7 +352,7 @@ private boolean isCompressionEligible() { return isExit() && isDiscardable() && (outcomeNotSet() || getOutcome() == Outcome.SUCCESS); } - private boolean tryToCompress(Span sibling) { + private boolean tryToCompress(SpanImpl sibling) { boolean canBeCompressed = isComposite() ? tryToCompressComposite(sibling) : tryToCompressRegular(sibling); if (!canBeCompressed) { return false; @@ -383,7 +384,7 @@ private boolean tryToCompress(Span sibling) { return true; } - private boolean tryToCompressRegular(Span sibling) { + private boolean tryToCompressRegular(SpanImpl sibling) { if (!isSameKind(sibling)) { return false; } @@ -419,7 +420,7 @@ private boolean tryToCompressRegular(Span sibling) { private void setCompressedSpanName() { name.setLength(0); - ServiceTarget serviceTarget = context.getServiceTarget(); + ServiceTargetImpl serviceTarget = context.getServiceTarget(); String serviceType = serviceTarget.getType(); CharSequence serviceName = serviceTarget.getName(); @@ -440,7 +441,7 @@ private void setCompressedSpanName() { } } - private boolean tryToCompressComposite(Span sibling) { + private boolean tryToCompressComposite(SpanImpl sibling) { String compressionStrategy = composite.getCompressionStrategy(); if (compressionStrategy == null) { //lose the compression rather than retry, so that the application proceeds with minimum delay @@ -461,9 +462,9 @@ private boolean tryToCompressComposite(Span sibling) { return false; } - private boolean isSameKind(Span other) { - ServiceTarget serviceTarget = context.getServiceTarget(); - ServiceTarget otherServiceTarget = other.context.getServiceTarget(); + private boolean isSameKind(SpanImpl other) { + ServiceTargetImpl serviceTarget = context.getServiceTarget(); + ServiceTargetImpl otherServiceTarget = other.context.getServiceTarget(); return Objects.equals(type, other.type) && Objects.equals(subtype, other.subtype) && Objects.equals(serviceTarget.getType(), otherServiceTarget.getType()) @@ -492,7 +493,7 @@ public String toString() { return String.format("'%s' %s (%s)", name, traceContext, Integer.toHexString(System.identityHashCode(this))); } - public Span withStacktrace(Throwable stacktrace) { + public SpanImpl withStacktrace(Throwable stacktrace) { this.stacktrace = stacktrace; return this; } @@ -519,7 +520,7 @@ protected void recycle() { } @Override - protected Span thiz() { + protected SpanImpl thiz() { return this; } @@ -534,12 +535,12 @@ public List getStackFrames() { @Override - public Transaction getParentTransaction() { + public TransactionImpl getParentTransaction() { return transaction; } @Nullable - public AbstractSpan getParent() { + public AbstractSpanImpl getParent() { return parent; } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContextImpl.java similarity index 89% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContextImpl.java index cc3df527cb..13a1f5cf20 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContextImpl.java @@ -18,12 +18,13 @@ */ package co.elastic.apm.agent.impl.transaction; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.baggage.Baggage; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; import co.elastic.apm.agent.impl.sampling.Sampler; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.TraceContext; import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; import co.elastic.apm.agent.tracer.dispatch.HeaderRemover; import co.elastic.apm.agent.tracer.dispatch.HeaderSetter; @@ -59,7 +60,7 @@ *

*

*/ -public class TraceContext implements Recyclable, co.elastic.apm.agent.tracer.TraceContext { +public class TraceContextImpl implements Recyclable, TraceContext { public static final String ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME = "elastic-apm-traceparent"; public static final String W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME = "traceparent"; @@ -69,7 +70,7 @@ public class TraceContext implements Recyclable, co.elastic.apm.agent.tracer.Tra private static final int TEXT_HEADER_TRACE_ID_OFFSET = 3; private static final int TEXT_HEADER_PARENT_ID_OFFSET = 36; private static final int TEXT_HEADER_FLAGS_OFFSET = 53; - private static final Logger logger = LoggerFactory.getLogger(TraceContext.class); + private static final Logger logger = LoggerFactory.getLogger(TraceContextImpl.class); private static final Double SAMPLE_RATE_ZERO = 0d; @@ -83,31 +84,31 @@ public class TraceContext implements Recyclable, co.elastic.apm.agent.tracer.Tra TRACE_TEXTUAL_HEADERS = Collections.unmodifiableSet(traceParentTextualHeaders); } - private static final ChildContextCreator FROM_PARENT_CONTEXT = new ChildContextCreator() { + private static final ChildContextCreator FROM_PARENT_CONTEXT = new ChildContextCreator() { @Override - public boolean asChildOf(TraceContext child, TraceContext parent) { + public boolean asChildOf(TraceContextImpl child, TraceContextImpl parent) { child.asChildOf(parent); return true; } }; - private static final ChildContextCreator> FROM_PARENT = new ChildContextCreator>() { + private static final ChildContextCreator> FROM_PARENT = new ChildContextCreator>() { @Override - public boolean asChildOf(TraceContext child, AbstractSpan parent) { + public boolean asChildOf(TraceContextImpl child, AbstractSpanImpl parent) { child.asChildOf(parent.getTraceContext()); return true; } }; - private static final HeaderGetter.HeaderConsumer STRING_TRACESTATE_HEADER_CONSUMER = new HeaderGetter.HeaderConsumer() { + private static final HeaderGetter.HeaderConsumer STRING_TRACESTATE_HEADER_CONSUMER = new HeaderGetter.HeaderConsumer() { @Override - public void accept(@Nullable String tracestateHeaderValue, TraceContext state) { + public void accept(@Nullable String tracestateHeaderValue, TraceContextImpl state) { state.addTraceStateHeader(tracestateHeaderValue, CharAccessor.forCharSequence()); } }; - private static final HeaderGetter.HeaderConsumer UTF8_BYTES_TRACESTATE_HEADER_CONSUMER = new HeaderGetter.HeaderConsumer() { + private static final HeaderGetter.HeaderConsumer UTF8_BYTES_TRACESTATE_HEADER_CONSUMER = new HeaderGetter.HeaderConsumer() { @Override - public void accept(@Nullable byte[] tracestateHeaderValue, TraceContext state) { + public void accept(@Nullable byte[] tracestateHeaderValue, TraceContextImpl state) { state.addTraceStateHeader(tracestateHeaderValue, CharAccessor.forAsciiBytes()); } }; @@ -119,13 +120,13 @@ public boolean asChildOf(@Nullable C carrier, HeaderGetter headerGe @SuppressWarnings("unchecked") public boolean asChildOf(@Nullable C carrier, HeaderGetter headerGetter, boolean parseTraceState) { CharAccessor headerValueAccessor; - HeaderGetter.HeaderConsumer traceStateConsumer; + HeaderGetter.HeaderConsumer traceStateConsumer; if (headerGetter instanceof TextHeaderGetter) { headerValueAccessor = (CharAccessor) CharAccessor.forCharSequence(); - traceStateConsumer = (HeaderGetter.HeaderConsumer) STRING_TRACESTATE_HEADER_CONSUMER; + traceStateConsumer = (HeaderGetter.HeaderConsumer) STRING_TRACESTATE_HEADER_CONSUMER; } else if (headerGetter instanceof UTF8ByteHeaderGetter) { headerValueAccessor = (CharAccessor) CharAccessor.forAsciiBytes(); - traceStateConsumer = (HeaderGetter.HeaderConsumer) UTF8_BYTES_TRACESTATE_HEADER_CONSUMER; + traceStateConsumer = (HeaderGetter.HeaderConsumer) UTF8_BYTES_TRACESTATE_HEADER_CONSUMER; } else { throw new IllegalArgumentException("HeaderGetter must be either a TextHeaderGetter or UTF8ByteHeaderGetter: " + headerGetter.getClass().getName()); } @@ -188,18 +189,18 @@ public static void copyTraceContextTextHeaders(S source, TextHeaderGetter // ???????1 -> maybe recorded // ???????0 -> not recorded private static final byte FLAG_RECORDED = 0b0000_0001; - private final Id traceId = Id.new128BitId(); + private final IdImpl traceId = IdImpl.new128BitId(); private final ElasticApmTracer tracer; - private final Id id; - private final Id parentId = Id.new64BitId(); - private final Id transactionId = Id.new64BitId(); + private final IdImpl id; + private final IdImpl parentId = IdImpl.new64BitId(); + private final IdImpl transactionId = IdImpl.new64BitId(); private final StringBuilder outgoingTextHeader = new StringBuilder(TEXT_HEADER_EXPECTED_LENGTH); private byte flags; private boolean discardable = true; private final TraceState traceState; - final CoreConfiguration coreConfiguration; + final CoreConfigurationImpl coreConfiguration; /** * Avoids clock drifts within a transaction. @@ -214,8 +215,8 @@ public static void copyTraceContextTextHeaders(S source, TextHeaderGetter @Nullable private String serviceVersion; - private TraceContext(ElasticApmTracer tracer, Id id) { - coreConfiguration = tracer.getConfig(CoreConfiguration.class); + private TraceContextImpl(ElasticApmTracer tracer, IdImpl id) { + coreConfiguration = tracer.getConfig(CoreConfigurationImpl.class); traceState = new TraceState(); traceState.setSizeLimit(coreConfiguration.getTracestateSizeLimit()); this.tracer = tracer; @@ -223,33 +224,33 @@ private TraceContext(ElasticApmTracer tracer, Id id) { } /** - * Creates a new {@code traceparent}-compliant {@link TraceContext} with a 64 bit {@link #id}. + * Creates a new {@code traceparent}-compliant {@link TraceContextImpl} with a 64 bit {@link #id}. *

* Note: the {@link #traceId} will still be 128 bit *

* * @param tracer a valid tracer */ - public static TraceContext with64BitId(ElasticApmTracer tracer) { - return new TraceContext(tracer, Id.new64BitId()); + public static TraceContextImpl with64BitId(ElasticApmTracer tracer) { + return new TraceContextImpl(tracer, IdImpl.new64BitId()); } /** - * Creates a new {@link TraceContext} with a 128 bit {@link #id}, + * Creates a new {@link TraceContextImpl} with a 128 bit {@link #id}, * suitable for errors, * as those might not have a trace reference and therefore require a larger id in order to be globally unique. * * @param tracer a valid tracer */ - public static TraceContext with128BitId(ElasticApmTracer tracer) { - return new TraceContext(tracer, Id.new128BitId()); + public static TraceContextImpl with128BitId(ElasticApmTracer tracer) { + return new TraceContextImpl(tracer, IdImpl.new128BitId()); } - public static ChildContextCreator fromParentContext() { + public static ChildContextCreator fromParentContext() { return FROM_PARENT_CONTEXT; } - public static ChildContextCreator> fromParent() { + public static ChildContextCreator> fromParent() { return FROM_PARENT; } @@ -348,7 +349,7 @@ public void asRootSpan(Sampler sampler) { onMutation(); } - public void asChildOf(TraceContext parent) { + public void asChildOf(TraceContextImpl parent) { traceId.copyFrom(parent.traceId); parentId.copyFrom(parent.id); transactionId.copyFrom(parent.transactionId); @@ -378,22 +379,22 @@ public void resetState() { } @Override - public Id getTraceId() { + public IdImpl getTraceId() { return traceId; } @Override - public Id getId() { + public IdImpl getId() { return id; } @Override - public Id getParentId() { + public IdImpl getParentId() { return parentId; } @Override - public Id getTransactionId() { + public IdImpl getTransactionId() { return transactionId; } @@ -537,7 +538,7 @@ StringBuilder getOutgoingTraceParentTextHeader() { return outgoingTextHeader; } - private void fillTraceParentHeader(StringBuilder sb, Id spanId) { + private void fillTraceParentHeader(StringBuilder sb, IdImpl spanId) { sb.append("00-"); traceId.writeAsHex(sb); sb.append('-'); @@ -546,7 +547,7 @@ private void fillTraceParentHeader(StringBuilder sb, Id spanId) { HexUtils.writeByteAsHex(flags, sb); } - public boolean isChildOf(TraceContext other) { + public boolean isChildOf(TraceContextImpl other) { return other.getTraceId().equals(traceId) && other.getId().equals(parentId); } @@ -554,7 +555,7 @@ public boolean hasContent() { return !id.isEmpty(); } - public void copyFrom(TraceContext other) { + public void copyFrom(TraceContextImpl other) { traceId.copyFrom(other.traceId); id.copyFrom(other.id); parentId.copyFrom(other.parentId); @@ -612,20 +613,20 @@ public String getServiceVersion() { * @param epochMicros the span start time * @return the newly started span */ - public Span createSpan(long epochMicros) { - return tracer.startSpan(fromParentContext(), this, Baggage.EMPTY, epochMicros); + public SpanImpl createSpan(long epochMicros) { + return tracer.startSpan(fromParentContext(), this, BaggageImpl.EMPTY, epochMicros); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - TraceContext that = (TraceContext) o; + TraceContextImpl that = (TraceContextImpl) o; return id.equals(that.id) && traceId.equals(that.traceId); } - public boolean idEquals(@Nullable TraceContext o) { + public boolean idEquals(@Nullable TraceContextImpl o) { if (this == o) return true; if (o == null) return false; return id.equals(o.id); @@ -694,16 +695,16 @@ public byte getFlags() { } public interface ChildContextCreator { - boolean asChildOf(TraceContext child, T parent); + boolean asChildOf(TraceContextImpl child, T parent); } - public TraceContext copy() { - final TraceContext copy; + public TraceContextImpl copy() { + final TraceContextImpl copy; final int idLength = id.getLength(); if (idLength == 8) { - copy = TraceContext.with64BitId(tracer); + copy = TraceContextImpl.with64BitId(tracer); } else if (idLength == 16) { - copy = TraceContext.with128BitId(tracer); + copy = TraceContextImpl.with128BitId(tracer); } else { throw new IllegalStateException("Id has invalid length: " + idLength); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceState.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceState.java index 006ad35131..e8b48f68c4 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceState.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceState.java @@ -303,7 +303,7 @@ void appendTracestateHeaderValue(String headerValue, StringBuilder tracestateBuf public static boolean includesElasticVendor(HeaderGetter headers, C parent){ boolean[] tracestateIncludesElasticVendor = new boolean[1]; HeaderGetter.HeaderConsumer rawHeaderConsumer = TraceState.ELASTIC_TRACESTATE_HEADER_CHECKER; - headers.forEach(TraceContext.TRACESTATE_HEADER_NAME, parent, tracestateIncludesElasticVendor, rawHeaderConsumer); + headers.forEach(TraceContextImpl.TRACESTATE_HEADER_NAME, parent, tracestateIncludesElasticVendor, rawHeaderConsumer); return tracestateIncludesElasticVendor[0]; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContext.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceStateImpl.java similarity index 79% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContext.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceStateImpl.java index a59d74dfcc..5bfe590323 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContext.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceStateImpl.java @@ -19,30 +19,31 @@ package co.elastic.apm.agent.impl.transaction; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.baggage.Baggage; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; import co.elastic.apm.agent.impl.baggage.BaggageContext; import co.elastic.apm.agent.impl.baggage.W3CBaggagePropagation; import co.elastic.apm.agent.tracer.Scope; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.dispatch.HeaderGetter; import co.elastic.apm.agent.tracer.dispatch.HeaderSetter; import co.elastic.apm.agent.tracer.dispatch.HeaderUtils; import javax.annotation.Nullable; -public abstract class ElasticContext> implements co.elastic.apm.agent.tracer.ElasticContext { +public abstract class TraceStateImpl> implements TraceState { protected final ElasticApmTracer tracer; - protected ElasticContext(ElasticApmTracer tracer) { + protected TraceStateImpl(ElasticApmTracer tracer) { this.tracer = tracer; } @Nullable @Override - public abstract AbstractSpan getSpan(); + public abstract AbstractSpanImpl getSpan(); @Override - public abstract Baggage getBaggage(); + public abstract BaggageImpl getBaggage(); public final ElasticApmTracer getTracer() { return tracer; @@ -52,8 +53,8 @@ public final ElasticApmTracer getTracer() { * @return transaction associated to this context, {@literal null} if there is none */ @Nullable - public final Transaction getTransaction() { - AbstractSpan contextSpan = getSpan(); + public final TransactionImpl getTransaction() { + AbstractSpanImpl contextSpan = getSpan(); return contextSpan != null ? contextSpan.getParentTransaction() : null; } @@ -83,15 +84,15 @@ public BaggageContext.Builder withUpdatedBaggage() { @Nullable @Override - public co.elastic.apm.agent.impl.transaction.Span createSpan() { - AbstractSpan currentSpan = getSpan(); + public SpanImpl createSpan() { + AbstractSpanImpl currentSpan = getSpan(); return currentSpan == null ? null : currentSpan.createSpan(getBaggage()); } @Nullable @Override - public final co.elastic.apm.agent.impl.transaction.Span createExitSpan() { - AbstractSpan contextSpan = getSpan(); + public final SpanImpl createExitSpan() { + AbstractSpanImpl contextSpan = getSpan(); if (contextSpan == null || contextSpan.isExit()) { return null; } @@ -109,14 +110,14 @@ public final void propagateContext(C carrier, HeaderSetter headerSette @Override public void propagateContext(C1 carrier, HeaderSetter headerSetter, @Nullable C2 carrier2, @Nullable HeaderGetter headerGetter) { - AbstractSpan contextSpan = getSpan(); + AbstractSpanImpl contextSpan = getSpan(); if (contextSpan != null) { - if (headerGetter == null || carrier2 == null || !HeaderUtils.containsAny(TraceContext.TRACE_TEXTUAL_HEADERS, carrier2, headerGetter)) { + if (headerGetter == null || carrier2 == null || !HeaderUtils.containsAny(TraceContextImpl.TRACE_TEXTUAL_HEADERS, carrier2, headerGetter)) { contextSpan.setNonDiscardable(); contextSpan.getTraceContext().propagateTraceContext(carrier, headerSetter); } } - Baggage baggage = getBaggage(); + BaggageImpl baggage = getBaggage(); if (!baggage.isEmpty()) { if (headerGetter == null || carrier2 == null || headerGetter.getFirstHeader(W3CBaggagePropagation.BAGGAGE_HEADER_NAME, carrier2) == null) { W3CBaggagePropagation.propagate(baggage, carrier, headerSetter); @@ -126,15 +127,15 @@ public void propagateContext(C1 carrier, HeaderSetter headerSett @Override public boolean isPropagationRequired(C carrier, HeaderGetter headerGetter) { - AbstractSpan contextSpan = getSpan(); - boolean traceContextPropagationRequired = contextSpan != null && !HeaderUtils.containsAny(TraceContext.TRACE_TEXTUAL_HEADERS, carrier, headerGetter); + AbstractSpanImpl contextSpan = getSpan(); + boolean traceContextPropagationRequired = contextSpan != null && !HeaderUtils.containsAny(TraceContextImpl.TRACE_TEXTUAL_HEADERS, carrier, headerGetter); boolean baggagePropagationRequired = !getBaggage().isEmpty() && headerGetter.getFirstHeader(W3CBaggagePropagation.BAGGAGE_HEADER_NAME, carrier) == null; return traceContextPropagationRequired || baggagePropagationRequired; } @Override public final boolean shouldSkipChildSpanCreation() { - Transaction contextTransaction = getTransaction(); + TransactionImpl contextTransaction = getTransaction(); return contextTransaction == null || contextTransaction.checkSkipChildSpanCreation(); } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContextWrapper.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceStateWrapper.java similarity index 82% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContextWrapper.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceStateWrapper.java index aa08522c89..cf7a3e1969 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/ElasticContextWrapper.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceStateWrapper.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.impl.transaction; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.baggage.Baggage; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; import co.elastic.apm.agent.tracer.Scope; import javax.annotation.Nullable; @@ -29,37 +29,37 @@ import java.util.concurrent.Callable; /** - * Implementation of {@link ElasticContext} that allows to wrap an existing {@link ElasticContext} object in order to + * Implementation of {@link TraceStateImpl} that allows to wrap an existing {@link TraceStateImpl} object in order to * integrate it with an alternate Tracing API. This is required in the following cases: *
    *
  • an active Elastic span/transaction is accessed from OpenTelemetry API
  • *
  • an active OpenTelemetry span created by one external plugin is accessed from another external plugin
  • *
*

- * When such cases occur, the currently active {@link ElasticContext} in {@link co.elastic.apm.agent.impl.ElasticApmTracer} + * When such cases occur, the currently active {@link TraceStateImpl} in {@link co.elastic.apm.agent.impl.ElasticApmTracer} * is replaced with an instance of this class in order to store references to the wrapper objects that allow to expose * the active span to the alternate Tracing API. *

*

- * This replacement is transparent to the creator of the original active {@link ElasticContext}. Calling (and + * This replacement is transparent to the creator of the original active {@link TraceStateImpl}. Calling (and * optionally register) the wrapper is done through {@link ElasticApmTracer#wrapActiveContextIfRequired(Class, Callable)} *

* * @param */ -public class ElasticContextWrapper> extends ElasticContext { +public class TraceStateWrapper> extends TraceStateImpl { /** * Original wrapped context */ - private final ElasticContext context; + private final TraceStateImpl context; /** * Contains other stored wrappers, one entry per type */ - private final Map, ElasticContext> contextWrappers; + private final Map, TraceStateImpl> contextWrappers; - public ElasticContextWrapper(int initialSize, ElasticContext context) { + public TraceStateWrapper(int initialSize, TraceStateImpl context) { super(context.tracer); this.contextWrappers = new HashMap<>(initialSize, 1.0f); this.context = context; @@ -73,8 +73,8 @@ public ElasticContextWrapper(int initialSize, ElasticContext context) { * @param type of context wrapper * @return newly or previously created wrapper */ - public > C wrapIfRequired(Class wrapperType, Callable wrapFunction) { - ElasticContext wrapped = contextWrappers.get(wrapperType); + public > C wrapIfRequired(Class wrapperType, Callable wrapFunction) { + TraceStateImpl wrapped = contextWrappers.get(wrapperType); if (wrapped == null) { try { wrapped = Objects.requireNonNull(wrapFunction.call()); @@ -90,7 +90,7 @@ public > C wrapIfRequired(Class wrapperType, Call /** * @return original context that was wrapped in this wrapper */ - public ElasticContext getWrappedContext() { + public TraceStateImpl getWrappedContext() { return context; } @@ -116,12 +116,12 @@ private static UnsupportedOperationException activationNotSupported() { @Override @Nullable - public AbstractSpan getSpan() { + public AbstractSpanImpl getSpan() { return context.getSpan(); } @Override - public Baggage getBaggage() { + public BaggageImpl getBaggage() { throw new UnsupportedOperationException("Baggage should not be accessed on context wrapper"); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Transaction.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TransactionImpl.java similarity index 89% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Transaction.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TransactionImpl.java index 83213a352c..0a0750125e 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Transaction.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TransactionImpl.java @@ -19,14 +19,15 @@ package co.elastic.apm.agent.impl.transaction; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpanConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.baggage.Baggage; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; import co.elastic.apm.agent.impl.baggage.W3CBaggagePropagation; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.context.TransactionContext; +import co.elastic.apm.agent.impl.context.ResponseImpl; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; import co.elastic.apm.agent.impl.sampling.Sampler; +import co.elastic.apm.agent.tracer.Transaction; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.Timer; @@ -41,13 +42,13 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import static co.elastic.apm.agent.configuration.CoreConfiguration.TraceContinuationStrategy.RESTART; -import static co.elastic.apm.agent.configuration.CoreConfiguration.TraceContinuationStrategy.RESTART_EXTERNAL; +import static co.elastic.apm.agent.configuration.CoreConfigurationImpl.TraceContinuationStrategy.RESTART; +import static co.elastic.apm.agent.configuration.CoreConfigurationImpl.TraceContinuationStrategy.RESTART_EXTERNAL; /** * Data captured by an agent representing an event occurring in a monitored service */ -public class Transaction extends AbstractSpan implements co.elastic.apm.agent.tracer.Transaction { +public class TransactionImpl extends AbstractSpanImpl implements Transaction { /** * Mutable labels instance used when reporting transaction metrics. @@ -60,7 +61,7 @@ public class Transaction extends AbstractSpan implements co.elastic *

* Any arbitrary contextual information regarding the event, captured by the agent, optionally provided by the user */ - private final TransactionContext context = new TransactionContext(); + private final TransactionContextImpl context = new TransactionContextImpl(); private final SpanCount spanCount = new SpanCount(); private final DroppedSpanStats droppedSpanStats = new DroppedSpanStats(); /** @@ -74,7 +75,7 @@ public class Transaction extends AbstractSpan implements co.elastic */ private final KeyListConcurrentHashMap> timerBySpanTypeAndSubtype = new KeyListConcurrentHashMap<>(); private final WriterReaderPhaser phaser = new WriterReaderPhaser(); - private final CoreConfiguration coreConfig; + private final CoreConfigurationImpl coreConfig; private final SpanConfiguration spanConfig; /** @@ -108,49 +109,49 @@ public class Transaction extends AbstractSpan implements co.elastic @Nullable private Throwable pendingException; - private final ArrayList profilingCorrelationStackTraceIds = new ArrayList<>(); + private final ArrayList profilingCorrelationStackTraceIds = new ArrayList<>(); /** * Faas *

* If a services is executed as a serverless function (function as a service), FaaS-specific information can be collected within this object. */ - private final Faas faas = new Faas(); + private final FaasImpl faas = new FaasImpl(); private final AtomicBoolean wasActivated = new AtomicBoolean(); @Override - public Transaction getParentTransaction() { + public TransactionImpl getParentTransaction() { return this; } - public Transaction(ElasticApmTracer tracer) { + public TransactionImpl(ElasticApmTracer tracer) { super(tracer); - coreConfig = tracer.getConfig(CoreConfiguration.class); + coreConfig = tracer.getConfig(CoreConfigurationImpl.class); spanConfig = tracer.getConfig(SpanConfiguration.class); } - public Transaction startRoot(long epochMicros, Sampler sampler, Baggage baggage) { + public TransactionImpl startRoot(long epochMicros, Sampler sampler, BaggageImpl baggage) { this.baggage = baggage; traceContext.asRootSpan(sampler); onTransactionStart(epochMicros); return this; } - public Transaction start( + public TransactionImpl start( @Nullable C parent, HeaderGetter headerGetter, long epochMicros, Sampler sampler, - Baggage baseBaggage + BaggageImpl baseBaggage ) { if (parent == null) { return startRoot(epochMicros, sampler, baseBaggage); } - Baggage.Builder baggageBuilder = baseBaggage.toBuilder(); + BaggageImpl.Builder baggageBuilder = baseBaggage.toBuilder(); W3CBaggagePropagation.parse(parent, headerGetter, baggageBuilder); this.baggage = baggageBuilder.build(); - CoreConfiguration.TraceContinuationStrategy traceContinuationStrategy = coreConfig.getTraceContinuationStrategy(); + CoreConfigurationImpl.TraceContinuationStrategy traceContinuationStrategy = coreConfig.getTraceContinuationStrategy(); boolean restartTrace = false; if (traceContinuationStrategy.equals(RESTART)) { restartTrace = true; @@ -186,7 +187,7 @@ private void onTransactionStart(long epochMicros) { onAfterStart(); } - public Transaction startNoop() { + public TransactionImpl startNoop() { this.name.append("noop"); this.noop = true; onAfterStart(); @@ -194,7 +195,7 @@ public Transaction startNoop() { } @Override - public Transaction activate() { + public TransactionImpl activate() { // why first the get() and then the getAndSet() here? get() is a cheap operation (volatile read) // while getAndSet() is an atomic operation with the corresponding performance penalty // therefore we only pay the price of the atomic operation on the first activation @@ -214,7 +215,7 @@ private void onFirstActivation() { } @Override - public TransactionContext getContext() { + public TransactionContextImpl getContext() { return context; } @@ -224,7 +225,7 @@ public TransactionContext getContext() { * @return the transaction context * @see #getContext() */ - public TransactionContext getContextEnsureVisibility() { + public TransactionContextImpl getContextEnsureVisibility() { synchronized (this) { return context; } @@ -239,7 +240,7 @@ public String getResult() { } @Override - public Transaction withResultIfUnset(@Nullable String result) { + public TransactionImpl withResultIfUnset(@Nullable String result) { if (this.result == null) { this.result = result; } @@ -247,7 +248,7 @@ public Transaction withResultIfUnset(@Nullable String result) { } @Override - public Transaction withResult(@Nullable String result) { + public TransactionImpl withResult(@Nullable String result) { this.result = result; return this; } @@ -267,7 +268,7 @@ public void beforeEnd(long epochMicros) { if (outcomeNotSet()) { // set outcome from HTTP status if not already set - Response response = getContext().getResponse(); + ResponseImpl response = getContext().getResponse(); Outcome outcome; int httpStatus = response.getStatusCode(); @@ -295,7 +296,7 @@ public SpanCount getSpanCount() { return spanCount; } - public void captureDroppedSpan(Span span) { + public void captureDroppedSpan(SpanImpl span) { if (span.isSampled()) { spanCount.getDropped().incrementAndGet(); } @@ -349,7 +350,7 @@ public void resetState() { } private void recycleProfilingCorrelationStackTraceIds() { - for (Id toRecycle : profilingCorrelationStackTraceIds) { + for (IdImpl toRecycle : profilingCorrelationStackTraceIds) { tracer.recycleProfilingCorrelationStackTraceId(toRecycle); } if (profilingCorrelationStackTraceIds.size() > 100) { @@ -441,7 +442,7 @@ public String getFrameworkVersion() { *

* If a services is executed as a serverless function (function as a service), FaaS-specific information can be collected within this object. */ - public Faas getFaas() { + public FaasImpl getFaas() { return faas; } @@ -468,7 +469,7 @@ public CharSequence getNameForSerialization() { } @Override - protected Transaction thiz() { + protected TransactionImpl thiz() { return this; } @@ -569,8 +570,8 @@ public Throwable getPendingTransactionException() { return this.pendingException; } - public void addProfilerCorrelationStackTrace(Id idToCopy) { - Id id = tracer.createProfilingCorrelationStackTraceId(); + public void addProfilerCorrelationStackTrace(IdImpl idToCopy) { + IdImpl id = tracer.createProfilingCorrelationStackTraceId(); id.copyFrom(idToCopy); synchronized (profilingCorrelationStackTraceIds) { this.profilingCorrelationStackTraceIds.add(id); @@ -581,7 +582,7 @@ public void addProfilerCorrelationStackTrace(Id idToCopy) { * Returns the list of stacktrace-IDs from the profiler associated with this transaction * To protect agains concurrent modifications, consumers must synchronize on the returned list. */ - public List getProfilingCorrelationStackTraceIds() { + public List getProfilingCorrelationStackTraceIds() { return profilingCorrelationStackTraceIds; } } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/UniqueSpanLinkArrayList.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/UniqueSpanLinkArrayList.java index 54a76845b8..28c91c13ed 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/UniqueSpanLinkArrayList.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/UniqueSpanLinkArrayList.java @@ -24,16 +24,16 @@ import java.util.Set; /** - * A {@link TraceContext} list that enforces uniqueness for the purpose of span links storage. - * We cannot naturally use {@link Set} implementations because {@link TraceContext#equals} is comparing own ID with other's ID. This is + * A {@link TraceContextImpl} list that enforces uniqueness for the purpose of span links storage. + * We cannot naturally use {@link Set} implementations because {@link TraceContextImpl#equals} is comparing own ID with other's ID. This is * inappropriate for span links, which we consider equal if their parent IDs are equal. * So instead, we use a limited subclass of {@link ArrayList} that maintains a parent ID cache for equality checks. * As a side benefit, this gives us the ability to iterate over span links based on index and avoid the related iterator allocation, which * we wouldn't have if using a {@link Set}. */ -public class UniqueSpanLinkArrayList extends ArrayList { +public class UniqueSpanLinkArrayList extends ArrayList { - private final Set parentIdSet = new HashSet<>(); + private final Set parentIdSet = new HashSet<>(); @Override public boolean retainAll(Collection c) { @@ -41,12 +41,12 @@ public boolean retainAll(Collection c) { } @Override - public TraceContext set(int index, TraceContext traceContext) { + public TraceContextImpl set(int index, TraceContextImpl traceContext) { throw new UnsupportedOperationException(); } @Override - public boolean add(TraceContext traceContext) { + public boolean add(TraceContextImpl traceContext) { if (parentIdSet.add(traceContext.getParentId())) { return super.add(traceContext); } @@ -54,12 +54,12 @@ public boolean add(TraceContext traceContext) { } @Override - public void add(int index, TraceContext traceContext) { + public void add(int index, TraceContextImpl traceContext) { throw new UnsupportedOperationException(); } @Override - public TraceContext remove(int index) { + public TraceContextImpl remove(int index) { throw new UnsupportedOperationException(); } @@ -75,12 +75,12 @@ public void clear() { } @Override - public boolean addAll(Collection c) { + public boolean addAll(Collection c) { throw new UnsupportedOperationException(); } @Override - public boolean addAll(int index, Collection c) { + public boolean addAll(int index, Collection c) { throw new UnsupportedOperationException(); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/ApmServerLogAppender.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/ApmServerLogAppender.java index 97074fe210..a8ffe69a9d 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/ApmServerLogAppender.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/ApmServerLogAppender.java @@ -47,7 +47,7 @@ public class ApmServerLogAppender extends AbstractAppender { private static ApmServerLogAppender INSTANCE; @Nullable - private volatile LoggingConfiguration config; + private volatile LoggingConfigurationImpl config; @Nullable private volatile Reporter reporter; @@ -105,12 +105,12 @@ public LifecycleListener getInitListener() { return new AbstractLifecycleListener() { @Override public void init(Tracer tracer) throws Exception { - initStreaming(tracer.getConfig(LoggingConfiguration.class), tracer.require(ElasticApmTracer.class).getReporter()); + initStreaming(tracer.getConfig(LoggingConfigurationImpl.class), tracer.require(ElasticApmTracer.class).getReporter()); } }; } - private void initStreaming(LoggingConfiguration config, Reporter reporter) { + private void initStreaming(LoggingConfigurationImpl config, Reporter reporter) { if (isAgentInitialized()) { throw new IllegalStateException("streaming already initialized"); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/Log4j2ConfigurationFactory.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/Log4j2ConfigurationFactory.java index e5da6fe806..54007e47fe 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/Log4j2ConfigurationFactory.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/Log4j2ConfigurationFactory.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.bci.ElasticApmAgent; import co.elastic.apm.agent.common.util.SystemStandardOutputLogger; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.AutoDetectedServiceInfo; import co.elastic.apm.agent.tracer.configuration.ByteValue; import co.elastic.apm.agent.report.ApmServerReporter; @@ -46,15 +46,15 @@ import java.net.URI; import java.util.List; -import static co.elastic.apm.agent.logging.LoggingConfiguration.AGENT_HOME_PLACEHOLDER; -import static co.elastic.apm.agent.logging.LoggingConfiguration.DEFAULT_LOG_FILE; -import static co.elastic.apm.agent.logging.LoggingConfiguration.DEPRECATED_LOG_FILE_KEY; -import static co.elastic.apm.agent.logging.LoggingConfiguration.DEPRECATED_LOG_LEVEL_KEY; -import static co.elastic.apm.agent.logging.LoggingConfiguration.LOG_FILE_KEY; -import static co.elastic.apm.agent.logging.LoggingConfiguration.LOG_FORMAT_FILE_KEY; -import static co.elastic.apm.agent.logging.LoggingConfiguration.LOG_FORMAT_SOUT_KEY; -import static co.elastic.apm.agent.logging.LoggingConfiguration.LOG_LEVEL_KEY; -import static co.elastic.apm.agent.logging.LoggingConfiguration.SYSTEM_OUT; +import static co.elastic.apm.agent.logging.LoggingConfigurationImpl.AGENT_HOME_PLACEHOLDER; +import static co.elastic.apm.agent.logging.LoggingConfigurationImpl.DEFAULT_LOG_FILE; +import static co.elastic.apm.agent.logging.LoggingConfigurationImpl.DEPRECATED_LOG_FILE_KEY; +import static co.elastic.apm.agent.logging.LoggingConfigurationImpl.DEPRECATED_LOG_LEVEL_KEY; +import static co.elastic.apm.agent.logging.LoggingConfigurationImpl.LOG_FILE_KEY; +import static co.elastic.apm.agent.logging.LoggingConfigurationImpl.LOG_FORMAT_FILE_KEY; +import static co.elastic.apm.agent.logging.LoggingConfigurationImpl.LOG_FORMAT_SOUT_KEY; +import static co.elastic.apm.agent.logging.LoggingConfigurationImpl.LOG_LEVEL_KEY; +import static co.elastic.apm.agent.logging.LoggingConfigurationImpl.SYSTEM_OUT; public class Log4j2ConfigurationFactory extends ConfigurationFactory { @@ -156,7 +156,7 @@ Configuration getConfiguration() { private Level getLogLevel() { String rawLogLevelValue = getValue(LOG_LEVEL_KEY, sources, getValue(DEPRECATED_LOG_LEVEL_KEY, sources, Level.INFO.toString())); - LogLevel logLevel = LoggingConfiguration.mapLogLevel(new EnumValueConverter<>(LogLevel.class).convert(rawLogLevelValue)); + LogLevel logLevel = LoggingConfigurationImpl.mapLogLevel(new EnumValueConverter<>(LogLevel.class).convert(rawLogLevelValue)); return Level.valueOf(logLevel.toString()); } @@ -186,7 +186,7 @@ private LayoutComponentBuilder createLayout(ConfigurationBuilder builder, String logFile, LayoutComponentBuilder layout) { - ByteValue size = ByteValue.of(getValue("log_file_size", sources, LoggingConfiguration.DEFAULT_MAX_SIZE)); + ByteValue size = ByteValue.of(getValue("log_file_size", sources, LoggingConfigurationImpl.DEFAULT_MAX_SIZE)); AppenderComponentBuilder appender = builder.newAppender("rolling", "RollingFile") .addAttribute("fileName", logFile) diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/LoggingConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/LoggingConfigurationImpl.java similarity index 98% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/logging/LoggingConfiguration.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/logging/LoggingConfigurationImpl.java index 3f17505f61..3ae8e4dfd9 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/LoggingConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/logging/LoggingConfigurationImpl.java @@ -24,6 +24,7 @@ import co.elastic.apm.agent.tracer.configuration.ByteValue; import co.elastic.apm.agent.tracer.configuration.ByteValueConverter; import co.elastic.apm.agent.tracer.configuration.LogEcsReformatting; +import co.elastic.apm.agent.tracer.configuration.LoggingConfiguration; import co.elastic.apm.agent.tracer.configuration.WildcardMatcherValueConverter; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; @@ -65,7 +66,7 @@ * so that the documentation gets generated for the options in this class. *

*/ -public class LoggingConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.agent.tracer.configuration.LoggingConfiguration { +public class LoggingConfigurationImpl extends ConfigurationOptionProvider implements LoggingConfiguration { public static final String SYSTEM_OUT = "System.out"; static final String LOG_LEVEL_KEY = "log_level"; @@ -349,7 +350,7 @@ private static void setLogLevel(@Nullable LogLevel level) { } } else { // it should be safe to obtain a logger here - LoggerFactory.getLogger(LoggingConfiguration.class).warn("Unexpected type of LoggerContextFactory - {}, " + + LoggerFactory.getLogger(LoggingConfigurationImpl.class).warn("Unexpected type of LoggerContextFactory - {}, " + "cannot update logging level", contextFactory); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricRegistry.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricRegistry.java index 9c1cdeb285..5c1ee1febe 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricRegistry.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricRegistry.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.metrics; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; @@ -46,7 +46,7 @@ public class MetricRegistry { private static final Logger logger = LoggerFactory.getLogger(MetricRegistry.class); private final WriterReaderPhaser phaser = new WriterReaderPhaser(); - private final ReporterConfiguration reporterConfiguration; + private final ReporterConfigurationImpl reporterConfiguration; private final Set metricsProviders = Collections.newSetFromMap(new ConcurrentHashMap()); private final int metricSetLimit; @@ -72,7 +72,7 @@ public void addMetricValue(String metric, Labels labels, double value) { } }; - public MetricRegistry(ReporterConfiguration reporterConfiguration, MetricsConfiguration metricsConfiguration) { + public MetricRegistry(ReporterConfigurationImpl reporterConfiguration, MetricsConfigurationImpl metricsConfiguration) { this.reporterConfiguration = reporterConfiguration; this.metricSetLimit = metricsConfiguration.getMetricSetLimit(); } @@ -90,7 +90,7 @@ public void addMetricsProvider(MetricsProvider provider) { * Tags can be used to create different graphs based for each value of a specific tag name, using a terms aggregation. * Note that there will be a {@link MetricSet} created for each distinct set of labels. * @param metric this supplier will be called for every reporting cycle - * ({@link co.elastic.apm.agent.report.ReporterConfiguration#metricsInterval metrics_interval)}) + * ({@link ReporterConfigurationImpl#metricsInterval metrics_interval)}) * @see #add(String, Labels, DoubleSupplier) */ public void addUnlessNan(String name, Labels labels, DoubleSupplier metric) { @@ -111,7 +111,7 @@ public void addUnlessNan(String name, Labels labels, DoubleSupplier metric) { * Tags can be used to create different graphs based for each value of a specific tag name, using a terms aggregation. * Note that there will be a {@link MetricSet} created for each distinct set of labels. * @param metric this supplier will be called for every reporting cycle - * ({@link co.elastic.apm.agent.report.ReporterConfiguration#metricsInterval metrics_interval)}) + * ({@link ReporterConfigurationImpl#metricsInterval metrics_interval)}) * @see #add(String, Labels, DoubleSupplier) */ public void addUnlessNegative(String name, Labels labels, DoubleSupplier metric) { @@ -131,7 +131,7 @@ public void addUnlessNegative(String name, Labels labels, DoubleSupplier metric) * Tags can be used to create different graphs based for each value of a specific tag name, using a terms aggregation. * Note that there will be a {@link MetricSet} created for each distinct set of labels. * @param metric this supplier will be called for every reporting cycle - * ({@link co.elastic.apm.agent.report.ReporterConfiguration#metricsInterval metrics_interval)}) + * ({@link ReporterConfigurationImpl#metricsInterval metrics_interval)}) */ public void add(String name, Labels labels, DoubleSupplier metric) { if (isDisabled(name)) { diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricSet.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricSet.java index 8bb1bc6f85..414d3efa88 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricSet.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/MetricSet.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.metrics; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.tracer.pooling.Recyclable; @@ -32,7 +33,7 @@ * A metric set is a collection of metrics which have the same labels. *

* A metric set corresponds to one document per - * {@link co.elastic.apm.agent.report.ReporterConfiguration#metricsInterval metrics_interval} in Elasticsearch. + * {@link ReporterConfigurationImpl#metricsInterval metrics_interval} in Elasticsearch. * An alternative would be to have one document per metric but having one document for all metrics with the same labels saves disk space. *

* Example of some serialized metric sets: diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetrics.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetrics.java index 3413f95f8a..346f4e13b2 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetrics.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetrics.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.tracer.Tracer; @@ -116,11 +116,11 @@ public AgentOverheadMetrics() { @Override public void start(Tracer tracer) throws Exception { MetricRegistry metricRegistry = tracer.require(ElasticApmTracer.class).getMetricRegistry(); - MetricsConfiguration config = tracer.getConfig(MetricsConfiguration.class); + MetricsConfigurationImpl config = tracer.getConfig(MetricsConfigurationImpl.class); bindTo(metricRegistry, config); } - void bindTo(MetricRegistry metricRegistry, MetricsConfiguration config) { + void bindTo(MetricRegistry metricRegistry, MetricsConfigurationImpl config) { boolean overheadMetricsEnabled = config.isOverheadMetricsEnabled(); cpuOverheadMetricEnabled = !metricRegistry.isDisabled(CPU_OVERHEAD_METRIC) && overheadMetricsEnabled; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetrics.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetrics.java index e946bb90e1..fb1e069348 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetrics.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetrics.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricCollector; import co.elastic.apm.agent.metrics.MetricRegistry; @@ -77,7 +77,7 @@ public class AgentReporterMetrics implements ReporterMonitor { private final AtomicDouble maxQueueSize = new AtomicDouble(0.0); private final AtomicDouble minQueueSize = new AtomicDouble(0.0); - public AgentReporterMetrics(final MetricRegistry registry, MetricsConfiguration configuration) { + public AgentReporterMetrics(final MetricRegistry registry, MetricsConfigurationImpl configuration) { this.metricRegistry = registry; boolean allEnabled = configuration.isReporterHealthMetricsEnabled(); this.totalEventsMetricEnabled = allEnabled && !registry.isDisabled(TOTAL_EVENTS_METRIC); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectHandle.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectHandleImpl.java similarity index 67% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectHandle.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectHandleImpl.java index c66afae82d..fc1e59e04e 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectHandle.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectHandleImpl.java @@ -20,12 +20,12 @@ import javax.annotation.Nullable; -public class ObjectHandle implements co.elastic.apm.agent.tracer.pooling.ObjectHandle, co.elastic.apm.agent.sdk.internal.pooling.ObjectHandle { +public class ObjectHandleImpl implements co.elastic.apm.agent.tracer.pooling.ObjectHandle, co.elastic.apm.agent.sdk.internal.pooling.ObjectHandle { - public static class Allocator implements co.elastic.apm.agent.tracer.pooling.Allocator> { + public static class Allocator implements co.elastic.apm.agent.tracer.pooling.Allocator> { @Nullable - private ObjectPool> pool; + private ObservableObjectPool> pool; private final co.elastic.apm.agent.tracer.pooling.Allocator delegate; @@ -33,29 +33,29 @@ public Allocator(co.elastic.apm.agent.tracer.pooling.Allocator delegate) { this.delegate = delegate; } - public void setPool(@Nullable ObjectPool> pool) { + public void setPool(@Nullable ObservableObjectPool> pool) { this.pool = pool; } @Override - public ObjectHandle createInstance() { + public ObjectHandleImpl createInstance() { if (pool == null) { throw new IllegalStateException("Pool has not been initialized!"); } - return new ObjectHandle<>(pool, delegate.createInstance()); + return new ObjectHandleImpl<>(pool, delegate.createInstance()); } } - public static final Resetter> NOOP_RESETTER = new Resetter>() { + public static final Resetter> NOOP_RESETTER = new Resetter>() { @Override - public void recycle(ObjectHandle object) { + public void recycle(ObjectHandleImpl object) { } }; - private final ObjectPool> owner; + private final ObservableObjectPool> owner; private final T pooledObject; - public ObjectHandle(ObjectPool> owner, T pooledObject) { + public ObjectHandleImpl(ObservableObjectPool> owner, T pooledObject) { this.owner = owner; this.pooledObject = pooledObject; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPoolFactory.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPoolFactoryImpl.java similarity index 54% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPoolFactory.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPoolFactoryImpl.java index 748d9d71e4..e3bf9d2297 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPoolFactory.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPoolFactoryImpl.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.objectpool; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.objectpool.impl.QueueBasedObjectPool; import co.elastic.apm.agent.sdk.internal.pooling.ObjectPooling; import co.elastic.apm.agent.tracer.pooling.Allocator; @@ -31,28 +31,28 @@ import java.util.concurrent.Callable; -import static co.elastic.apm.agent.objectpool.ObjectHandle.NOOP_RESETTER; +import static co.elastic.apm.agent.objectpool.ObjectHandleImpl.NOOP_RESETTER; -public class ObjectPoolFactory implements co.elastic.apm.agent.tracer.pooling.ObjectPoolFactory, ObjectPooling.ObjectPoolFactory { +public class ObjectPoolFactoryImpl implements co.elastic.apm.agent.tracer.pooling.ObjectPoolFactory, ObjectPooling.ObjectPoolFactory { private static final int DEFAULT_RESOURCE_POOL_SIZE = Math.max(16, Runtime.getRuntime().availableProcessors() * 2); @Override - public ObjectPool createRecyclableObjectPool(int maxCapacity, Allocator allocator) { + public ObservableObjectPool createRecyclableObjectPool(int maxCapacity, Allocator allocator) { return QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue((maxCapacity)), false, allocator); } @Override - public ObjectPool> createHandlePool(Allocator allocator) { - ObjectHandle.Allocator handleAlloc = new ObjectHandle.Allocator(allocator); - QueueBasedObjectPool> result = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue>((DEFAULT_RESOURCE_POOL_SIZE)), false, handleAlloc, NOOP_RESETTER); + public ObservableObjectPool> createHandlePool(Allocator allocator) { + ObjectHandleImpl.Allocator handleAlloc = new ObjectHandleImpl.Allocator(allocator); + QueueBasedObjectPool> result = QueueBasedObjectPool.of(new MpmcAtomicArrayQueue>((DEFAULT_RESOURCE_POOL_SIZE)), false, handleAlloc, NOOP_RESETTER); handleAlloc.setPool(result); return result; } @Override - public ObjectPool> createHandlePool(final Callable allocator) { + public ObservableObjectPool> createHandlePool(final Callable allocator) { return createHandlePool(new Allocator() { @Override public T createInstance() { @@ -65,38 +65,38 @@ public T createInstance() { }); } - public ObjectPool createTransactionPool(int maxCapacity, final ElasticApmTracer tracer) { - return createRecyclableObjectPool(maxCapacity, new Allocator() { + public ObservableObjectPool createTransactionPool(int maxCapacity, final ElasticApmTracer tracer) { + return createRecyclableObjectPool(maxCapacity, new Allocator() { @Override - public Transaction createInstance() { - return new Transaction(tracer); + public TransactionImpl createInstance() { + return new TransactionImpl(tracer); } }); } - public ObjectPool createSpanPool(int maxCapacity, final ElasticApmTracer tracer) { - return createRecyclableObjectPool(maxCapacity, new Allocator() { + public ObservableObjectPool createSpanPool(int maxCapacity, final ElasticApmTracer tracer) { + return createRecyclableObjectPool(maxCapacity, new Allocator() { @Override - public Span createInstance() { - return new Span(tracer); + public SpanImpl createInstance() { + return new SpanImpl(tracer); } }); } - public ObjectPool createErrorPool(int maxCapacity, final ElasticApmTracer tracer) { - return createRecyclableObjectPool(maxCapacity, new Allocator() { + public ObservableObjectPool createErrorPool(int maxCapacity, final ElasticApmTracer tracer) { + return createRecyclableObjectPool(maxCapacity, new Allocator() { @Override - public ErrorCapture createInstance() { - return new ErrorCapture(tracer); + public ErrorCaptureImpl createInstance() { + return new ErrorCaptureImpl(tracer); } }); } - public ObjectPool createSpanLinkPool(int maxCapacity, final ElasticApmTracer tracer) { - return createRecyclableObjectPool(maxCapacity, new Allocator() { + public ObservableObjectPool createSpanLinkPool(int maxCapacity, final ElasticApmTracer tracer) { + return createRecyclableObjectPool(maxCapacity, new Allocator() { @Override - public TraceContext createInstance() { - return TraceContext.with64BitId(tracer); + public TraceContextImpl createInstance() { + return TraceContextImpl.with64BitId(tracer); } }); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPool.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObservableObjectPool.java similarity index 87% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPool.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObservableObjectPool.java index 0296b7fb0f..475763d4cf 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObjectPool.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/ObservableObjectPool.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.objectpool; -public interface ObjectPool extends co.elastic.apm.agent.tracer.pooling.ObjectPool, co.elastic.apm.agent.sdk.internal.pooling.ObjectPool { +public interface ObservableObjectPool extends co.elastic.apm.agent.tracer.pooling.ObjectPool, co.elastic.apm.agent.sdk.internal.pooling.ObjectPool { /** * @return number of available objects in pool diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/AbstractObjectPool.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/AbstractObjectPool.java index 4348d64d68..8630baf455 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/AbstractObjectPool.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/objectpool/impl/AbstractObjectPool.java @@ -18,14 +18,14 @@ */ package co.elastic.apm.agent.objectpool.impl; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; import co.elastic.apm.agent.objectpool.Resetter; import co.elastic.apm.agent.tracer.pooling.Allocator; import javax.annotation.Nullable; import java.util.concurrent.atomic.AtomicInteger; -public abstract class AbstractObjectPool implements ObjectPool { +public abstract class AbstractObjectPool implements ObservableObjectPool { protected final Allocator allocator; protected final Resetter resetter; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/AbstractIntakeApiHandler.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/AbstractIntakeApiHandler.java index 750364da06..5fea031483 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/AbstractIntakeApiHandler.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/AbstractIntakeApiHandler.java @@ -40,7 +40,7 @@ public class AbstractIntakeApiHandler { private static final Logger logger = LoggerFactory.getLogger(AbstractIntakeApiHandler.class); private static final Object WAIT_LOCK = new Object(); - protected final ReporterConfiguration reporterConfiguration; + protected final ReporterConfigurationImpl reporterConfiguration; protected final DslJsonSerializer.Writer payloadSerializer; protected final ApmServerClient apmServerClient; protected Deflater deflater; @@ -55,7 +55,7 @@ public class AbstractIntakeApiHandler { private volatile boolean healthy = true; private long requestStartedNanos; - protected AbstractIntakeApiHandler(ReporterConfiguration reporterConfiguration, DslJsonSerializer payloadSerializer, ApmServerClient apmServerClient) { + protected AbstractIntakeApiHandler(ReporterConfigurationImpl reporterConfiguration, DslJsonSerializer payloadSerializer, ApmServerClient apmServerClient) { this.reporterConfiguration = reporterConfiguration; this.payloadSerializer = payloadSerializer.newWriter(); this.apmServerClient = apmServerClient; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerClient.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerClient.java index 1bc971d72f..9c9d198c0c 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerClient.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerClient.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.report; import co.elastic.apm.agent.common.util.Version; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.configuration.ServerlessConfigurationImpl; import co.elastic.apm.agent.report.ssl.SslUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -76,9 +76,9 @@ public class ApmServerClient { private static final Version VERSION_8_6 = Version.of("8.6.0"); private static final Version VERSION_8_7_1 = Version.of("8.7.1"); - private final ReporterConfiguration reporterConfiguration; + private final ReporterConfigurationImpl reporterConfiguration; - private final ServerlessConfiguration serverlessConfiguration; + private final ServerlessConfigurationImpl serverlessConfiguration; @Nullable private volatile List serverUrls; @Nullable @@ -89,10 +89,10 @@ public class ApmServerClient { private final String userAgent; public ApmServerClient(ConfigurationRegistry configs) { - this.reporterConfiguration = configs.getConfig(ReporterConfiguration.class); + this.reporterConfiguration = configs.getConfig(ReporterConfigurationImpl.class); this.healthChecker = new ApmServerHealthChecker(this); - this.serverlessConfiguration = configs.getConfig(ServerlessConfiguration.class); - this.userAgent = getUserAgent(configs.getConfig(CoreConfiguration.class)); + this.serverlessConfiguration = configs.getConfig(ServerlessConfigurationImpl.class); + this.userAgent = getUserAgent(configs.getConfig(CoreConfigurationImpl.class)); } public void start() { @@ -418,7 +418,7 @@ public interface ConnectionHandler { T withConnection(HttpURLConnection connection) throws IOException; } - private static String getUserAgent(CoreConfiguration coreConfiguration) { + private static String getUserAgent(CoreConfigurationImpl coreConfiguration) { StringBuilder userAgent = new StringBuilder(); userAgent.append("apm-agent-java/").append(VersionUtils.getAgentVersion()); String serviceName = coreConfiguration.getServiceName(); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerReporter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerReporter.java index 37e84b2fc4..8b8aabfc93 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerReporter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ApmServerReporter.java @@ -18,11 +18,11 @@ */ package co.elastic.apm.agent.report; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.objectpool.ObjectPoolFactory; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; +import co.elastic.apm.agent.objectpool.ObjectPoolFactoryImpl; import co.elastic.apm.agent.report.disruptor.ExponentionallyIncreasingSleepingWaitStrategy; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import co.elastic.apm.agent.sdk.logging.Logger; @@ -44,24 +44,24 @@ import java.util.concurrent.locks.LockSupport; /** - * This reporter asynchronously reports {@link Transaction}s to the APM server + * This reporter asynchronously reports {@link TransactionImpl}s to the APM server *

- * It uses a Disruptor/ring buffer to decouple the {@link Transaction} producing threads from the thread that actually sends the payload + * It uses a Disruptor/ring buffer to decouple the {@link TransactionImpl} producing threads from the thread that actually sends the payload *

*/ public class ApmServerReporter implements Reporter { private static final Logger logger = LoggerFactory.getLogger(ApmServerReporter.class); - private static final EventTranslatorOneArg TRANSACTION_EVENT_TRANSLATOR = new EventTranslatorOneArg() { + private static final EventTranslatorOneArg TRANSACTION_EVENT_TRANSLATOR = new EventTranslatorOneArg() { @Override - public void translateTo(ReportingEvent event, long sequence, Transaction t) { + public void translateTo(ReportingEvent event, long sequence, TransactionImpl t) { event.setTransaction(t); } }; - private static final EventTranslatorOneArg SPAN_EVENT_TRANSLATOR = new EventTranslatorOneArg() { + private static final EventTranslatorOneArg SPAN_EVENT_TRANSLATOR = new EventTranslatorOneArg() { @Override - public void translateTo(ReportingEvent event, long sequence, Span s) { + public void translateTo(ReportingEvent event, long sequence, SpanImpl s) { event.setSpan(s); } }; @@ -85,9 +85,9 @@ public void translateTo(ReportingEvent event, long sequence) { event.setWakeupEvent(); } }; - private static final EventTranslatorOneArg ERROR_EVENT_TRANSLATOR = new EventTranslatorOneArg() { + private static final EventTranslatorOneArg ERROR_EVENT_TRANSLATOR = new EventTranslatorOneArg() { @Override - public void translateTo(ReportingEvent event, long sequence, ErrorCapture error) { + public void translateTo(ReportingEvent event, long sequence, ErrorCaptureImpl error) { event.setError(error); } }; @@ -133,16 +133,16 @@ public void translateTo(ReportingEvent event, long sequence, byte[] bytes) { private final PartialTransactionReporter partialTransactionReporter; - private final CoreConfiguration coreConfiguration; + private final CoreConfigurationImpl coreConfiguration; public ApmServerReporter(boolean dropTransactionIfQueueFull, - ReporterConfiguration reporterConfiguration, - CoreConfiguration coreConfiguration, + ReporterConfigurationImpl reporterConfiguration, + CoreConfigurationImpl coreConfiguration, ReportingEventHandler reportingEventHandler, ReporterMonitor monitor, ApmServerClient apmServer, DslJsonSerializer serializer, - ObjectPoolFactory poolFactory + ObjectPoolFactoryImpl poolFactory ) { this.dropTransactionIfQueueFull = dropTransactionIfQueueFull; @@ -168,14 +168,14 @@ public void start() { } @Override - public void reportPartialTransaction(Transaction transaction) { + public void reportPartialTransaction(TransactionImpl transaction) { if (!coreConfiguration.isContextPropagationOnly()) { partialTransactionReporter.reportPartialTransaction(transaction); } } @Override - public void report(Transaction transaction) { + public void report(TransactionImpl transaction) { if (!tryAddEventToRingBuffer(transaction, TRANSACTION_EVENT_TRANSLATOR, ReportingEvent.ReportingEventType.TRANSACTION)) { transaction.decrementReferences(); } @@ -185,7 +185,7 @@ public void report(Transaction transaction) { } @Override - public void report(Span span) { + public void report(SpanImpl span) { if (!tryAddEventToRingBuffer(span, SPAN_EVENT_TRANSLATOR, ReportingEvent.ReportingEventType.SPAN)) { span.decrementReferences(); } @@ -287,7 +287,7 @@ public void close() { } @Override - public void report(ErrorCapture error) { + public void report(ErrorCaptureImpl error) { if (!tryAddEventToRingBuffer(error, ERROR_EVENT_TRANSLATOR, ReportingEvent.ReportingEventType.ERROR)) { error.recycle(); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/IntakeV2ReportingEventHandler.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/IntakeV2ReportingEventHandler.java index 72ea93cb44..2264b34138 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/IntakeV2ReportingEventHandler.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/IntakeV2ReportingEventHandler.java @@ -60,7 +60,7 @@ public class IntakeV2ReportingEventHandler extends AbstractIntakeApiHandler impl private long reported; private long dropped; - public IntakeV2ReportingEventHandler(ReporterConfiguration reporterConfiguration, ProcessorEventHandler processorEventHandler, + public IntakeV2ReportingEventHandler(ReporterConfigurationImpl reporterConfiguration, ProcessorEventHandler processorEventHandler, DslJsonSerializer payloadSerializer, ApmServerClient apmServerClient) { super(reporterConfiguration, payloadSerializer, apmServerClient); this.processorEventHandler = processorEventHandler; diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/PartialTransactionReporter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/PartialTransactionReporter.java index 0a74c09b9c..e88e5d603b 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/PartialTransactionReporter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/PartialTransactionReporter.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.report; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.objectpool.ObjectPool; -import co.elastic.apm.agent.objectpool.ObjectPoolFactory; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; +import co.elastic.apm.agent.objectpool.ObjectPoolFactoryImpl; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import co.elastic.apm.agent.report.serialize.SerializationConstants; import co.elastic.apm.agent.sdk.logging.Logger; @@ -37,11 +37,11 @@ class PartialTransactionReporter { private final ApmServerClient apmServer; - private final ObjectPool writerPool; + private final ObservableObjectPool writerPool; private volatile boolean extensionSupportsPartialTransactions = true; - public PartialTransactionReporter(ApmServerClient apmServer, final DslJsonSerializer payloadSerializer, ObjectPoolFactory poolFactory) { + public PartialTransactionReporter(ApmServerClient apmServer, final DslJsonSerializer payloadSerializer, ObjectPoolFactoryImpl poolFactory) { this.apmServer = apmServer; writerPool = poolFactory.createRecyclableObjectPool(WRITER_POOL_SIZE, new Allocator() { @Override @@ -51,7 +51,7 @@ public DslJsonSerializer.Writer createInstance() { }); } - public void reportPartialTransaction(Transaction transaction) { + public void reportPartialTransaction(TransactionImpl transaction) { if (!extensionSupportsPartialTransactions) { return; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/Reporter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/Reporter.java index 777a8d82ef..10974dbd9b 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/Reporter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/Reporter.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.report; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import com.dslplatform.json.JsonWriter; import java.io.Closeable; @@ -30,13 +30,13 @@ public interface Reporter extends Closeable { void start(); - void reportPartialTransaction(Transaction transaction); + void reportPartialTransaction(TransactionImpl transaction); - void report(Transaction transaction); + void report(TransactionImpl transaction); - void report(Span span); + void report(SpanImpl span); - void report(ErrorCapture error); + void report(ErrorCaptureImpl error); void reportMetrics(JsonWriter jsonWriter); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterConfiguration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterConfigurationImpl.java similarity index 97% rename from apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterConfiguration.java rename to apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterConfigurationImpl.java index 5a7965c317..cf6149b27d 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterConfiguration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterConfigurationImpl.java @@ -20,6 +20,7 @@ import co.elastic.apm.agent.tracer.configuration.ByteValue; import co.elastic.apm.agent.tracer.configuration.ByteValueConverter; +import co.elastic.apm.agent.tracer.configuration.ReporterConfiguration; import co.elastic.apm.agent.tracer.configuration.TimeDuration; import co.elastic.apm.agent.tracer.configuration.TimeDurationValueConverter; import co.elastic.apm.agent.common.util.WildcardMatcher; @@ -37,7 +38,7 @@ import static co.elastic.apm.agent.tracer.configuration.RangeValidator.isNotInRange; -public class ReporterConfiguration extends ConfigurationOptionProvider implements co.elastic.apm.agent.tracer.configuration.ReporterConfiguration { +public class ReporterConfigurationImpl extends ConfigurationOptionProvider implements ReporterConfiguration { public static final String REPORTER_CATEGORY = "Reporter"; public static final URL LOCAL_APM_SERVER_URL = UrlValueConverter.INSTANCE.convert("http://127.0.0.1:8200"); @@ -226,8 +227,8 @@ public String getApiKey() { /** * Provides the combined output of two config options - {@code server_url} and {@code server_urls}, with precedence - * for the singular form. If {@link ReporterConfiguration#serverUrl} is set with an empty string and - * {@link ReporterConfiguration#serverUrls} is not set, this method is expected to provide an empty list. + * for the singular form. If {@link ReporterConfigurationImpl#serverUrl} is set with an empty string and + * {@link ReporterConfigurationImpl#serverUrls} is not set, this method is expected to provide an empty list. * * Algorithm: * 1. if the server_url value is set, then: diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterFactory.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterFactory.java index de15fb9b0b..b5e32623eb 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterFactory.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReporterFactory.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.report; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.objectpool.ObjectPoolFactory; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.objectpool.ObjectPoolFactoryImpl; import co.elastic.apm.agent.report.processor.ProcessorEventHandler; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import org.stagemonitor.configuration.ConfigurationRegistry; @@ -32,17 +32,17 @@ public Reporter createReporter(ConfigurationRegistry configurationRegistry, ApmServerClient apmServerClient, DslJsonSerializer payloadSerializer, ReporterMonitor monitor, - ObjectPoolFactory poolFactory) { + ObjectPoolFactoryImpl poolFactory) { - ReporterConfiguration reporterConfiguration = configurationRegistry.getConfig(ReporterConfiguration.class); - CoreConfiguration coreConfig = configurationRegistry.getConfig(CoreConfiguration.class); + ReporterConfigurationImpl reporterConfiguration = configurationRegistry.getConfig(ReporterConfigurationImpl.class); + CoreConfigurationImpl coreConfig = configurationRegistry.getConfig(CoreConfigurationImpl.class); ReportingEventHandler reportingEventHandler = getReportingEventHandler(configurationRegistry, reporterConfiguration, payloadSerializer, apmServerClient); return new ApmServerReporter(true, reporterConfiguration, coreConfig, reportingEventHandler, monitor, apmServerClient, payloadSerializer, poolFactory); } @Nonnull private ReportingEventHandler getReportingEventHandler(ConfigurationRegistry configurationRegistry, - ReporterConfiguration reporterConfiguration, + ReporterConfigurationImpl reporterConfiguration, DslJsonSerializer payloadSerializer, ApmServerClient apmServerClient) { ProcessorEventHandler processorEventHandler = ProcessorEventHandler.loadProcessors(configurationRegistry); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReportingEvent.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReportingEvent.java index 1547b2cff4..62158bc664 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReportingEvent.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/ReportingEvent.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.report; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import com.dslplatform.json.JsonWriter; import javax.annotation.Nullable; @@ -39,14 +39,14 @@ public class ReportingEvent { @Nullable - private Transaction transaction; + private TransactionImpl transaction; @Nullable private ReportingEventType type; @Nullable - private ErrorCapture error; + private ErrorCaptureImpl error; @Nullable - private Span span; + private SpanImpl span; @Nullable private JsonWriter jsonWriter; @Nullable @@ -71,11 +71,11 @@ public void resetState() { } @Nullable - public Transaction getTransaction() { + public TransactionImpl getTransaction() { return transaction; } - public void setTransaction(Transaction transaction) { + public void setTransaction(TransactionImpl transaction) { this.transaction = transaction; this.type = TRANSACTION; } @@ -96,21 +96,21 @@ public ReportingEventType getType() { } @Nullable - public ErrorCapture getError() { + public ErrorCaptureImpl getError() { return error; } @Nullable - public Span getSpan() { + public SpanImpl getSpan() { return span; } - public void setError(ErrorCapture error) { + public void setError(ErrorCaptureImpl error) { this.error = error; this.type = ERROR; } - public void setSpan(Span span) { + public void setSpan(SpanImpl span) { this.span = span; this.type = SPAN; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/processor/Processor.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/processor/Processor.java index ca9e4ae23d..a4535edc46 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/processor/Processor.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/processor/Processor.java @@ -18,12 +18,12 @@ */ package co.elastic.apm.agent.report.processor; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.stagemonitor.configuration.ConfigurationRegistry; /** - * A processor is executed right before a event (a {@link Transaction} or {@link ErrorCapture}) gets reported. + * A processor is executed right before a event (a {@link TransactionImpl} or {@link ErrorCaptureImpl}) gets reported. *

* You can use this for example to sanitize certain information. *

@@ -34,16 +34,16 @@ public interface Processor { /** - * This method is executed before the provided {@link Transaction} is reported. + * This method is executed before the provided {@link TransactionImpl} is reported. * * @param transaction The transaction to process. */ - void processBeforeReport(Transaction transaction); + void processBeforeReport(TransactionImpl transaction); /** - * This method is executed before the provided {@link ErrorCapture} is reported. + * This method is executed before the provided {@link ErrorCaptureImpl} is reported. * * @param error The error to process. */ - void processBeforeReport(ErrorCapture error); + void processBeforeReport(ErrorCaptureImpl error); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonSerializer.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonSerializer.java index a14b296bb3..490599efdd 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonSerializer.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/DslJsonSerializer.java @@ -18,53 +18,55 @@ */ package co.elastic.apm.agent.report.serialize; -import co.elastic.apm.agent.impl.context.AbstractContext; -import co.elastic.apm.agent.impl.context.CloudOrigin; -import co.elastic.apm.agent.impl.context.Db; -import co.elastic.apm.agent.impl.context.Destination; +import co.elastic.apm.agent.impl.context.AbstractContextImpl; +import co.elastic.apm.agent.impl.context.BodyCaptureImpl; +import co.elastic.apm.agent.impl.context.CloudOriginImpl; +import co.elastic.apm.agent.impl.context.DbImpl; +import co.elastic.apm.agent.impl.context.DestinationImpl; import co.elastic.apm.agent.impl.context.Headers; -import co.elastic.apm.agent.impl.context.Http; -import co.elastic.apm.agent.impl.context.Message; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.context.ServiceOrigin; -import co.elastic.apm.agent.impl.context.ServiceTarget; -import co.elastic.apm.agent.impl.context.Socket; -import co.elastic.apm.agent.impl.context.SpanContext; -import co.elastic.apm.agent.impl.context.TransactionContext; -import co.elastic.apm.agent.impl.context.Url; -import co.elastic.apm.agent.impl.context.User; -import co.elastic.apm.agent.impl.error.ErrorCapture; +import co.elastic.apm.agent.impl.context.HttpImpl; +import co.elastic.apm.agent.impl.context.MessageImpl; +import co.elastic.apm.agent.impl.context.RequestImpl; +import co.elastic.apm.agent.impl.context.ResponseImpl; +import co.elastic.apm.agent.impl.context.ServiceOriginImpl; +import co.elastic.apm.agent.impl.context.ServiceTargetImpl; +import co.elastic.apm.agent.impl.context.SocketImpl; +import co.elastic.apm.agent.impl.context.SpanContextImpl; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; +import co.elastic.apm.agent.impl.context.UrlImpl; +import co.elastic.apm.agent.impl.context.UserImpl; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.impl.metadata.Agent; import co.elastic.apm.agent.impl.metadata.CloudProviderInfo; import co.elastic.apm.agent.impl.metadata.Framework; import co.elastic.apm.agent.impl.metadata.Language; import co.elastic.apm.agent.impl.metadata.MetaData; import co.elastic.apm.agent.impl.metadata.NameAndIdField; -import co.elastic.apm.agent.impl.metadata.Node; +import co.elastic.apm.agent.impl.metadata.NodeImpl; import co.elastic.apm.agent.impl.metadata.ProcessInfo; import co.elastic.apm.agent.impl.metadata.RuntimeInfo; -import co.elastic.apm.agent.impl.metadata.Service; +import co.elastic.apm.agent.impl.metadata.ServiceImpl; import co.elastic.apm.agent.impl.metadata.SystemInfo; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import co.elastic.apm.agent.impl.transaction.Composite; import co.elastic.apm.agent.impl.transaction.DroppedSpanStats; -import co.elastic.apm.agent.impl.transaction.Faas; -import co.elastic.apm.agent.impl.transaction.FaasTrigger; -import co.elastic.apm.agent.impl.transaction.Id; +import co.elastic.apm.agent.impl.transaction.FaasImpl; +import co.elastic.apm.agent.impl.transaction.FaasTriggerImpl; +import co.elastic.apm.agent.impl.transaction.IdImpl; import co.elastic.apm.agent.impl.transaction.OTelSpanKind; -import co.elastic.apm.agent.impl.transaction.Span; import co.elastic.apm.agent.impl.transaction.SpanCount; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.impl.transaction.StackFrame; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.tracer.metrics.Labels; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.sdk.internal.collections.LongList; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; +import co.elastic.apm.agent.tracer.metrics.DslJsonUtil; +import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.tracer.pooling.Recyclable; import co.elastic.apm.agent.tracer.metrics.DslJsonUtil; import com.dslplatform.json.BoolConverter; @@ -78,6 +80,7 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -103,7 +106,7 @@ public class DslJsonSerializer { private static final List excludedStackFramesPrefixes = Arrays.asList("java.lang.reflect.", "com.sun.", "sun.", "jdk.internal."); - private final StacktraceConfiguration stacktraceConfiguration; + private final StacktraceConfigurationImpl stacktraceConfiguration; private final ApmServerClient apmServerClient; private final Future metaData; @@ -111,7 +114,7 @@ public class DslJsonSerializer { private byte[] serializedMetaData; private boolean serializedActivationMethod; - public DslJsonSerializer(StacktraceConfiguration stacktraceConfiguration, ApmServerClient apmServerClient, final Future metaData) { + public DslJsonSerializer(StacktraceConfigurationImpl stacktraceConfiguration, ApmServerClient apmServerClient, final Future metaData) { this.stacktraceConfiguration = stacktraceConfiguration; this.apmServerClient = apmServerClient; this.metaData = metaData; @@ -182,7 +185,7 @@ private static void serializeGlobalLabels(ArrayList globalLabelKeys, Arr } } - private static void serializeService(final Service service, final StringBuilder replaceBuilder, final JsonWriter jw, boolean supportsAgentActivationMethod) { + private static void serializeService(final ServiceImpl service, final StringBuilder replaceBuilder, final JsonWriter jw, boolean supportsAgentActivationMethod) { DslJsonUtil.writeFieldName("service", jw); jw.writeByte(JsonWriter.OBJECT_START); @@ -205,7 +208,7 @@ private static void serializeService(final Service service, final StringBuilder serializeFramework(framework, replaceBuilder, jw); } - final Node node = service.getNode(); + final NodeImpl node = service.getNode(); if (node != null && node.hasContents()) { serializeNode(node, replaceBuilder, jw); } @@ -219,7 +222,7 @@ private static void serializeService(final Service service, final StringBuilder jw.writeByte(JsonWriter.OBJECT_END); } - private static void serializeService(@Nullable final CharSequence serviceName, @Nullable final CharSequence serviceVersion, @Nullable ServiceTarget serviceTarget, final StringBuilder replaceBuilder, final JsonWriter jw) { + private static void serializeService(@Nullable final CharSequence serviceName, @Nullable final CharSequence serviceVersion, @Nullable ServiceTargetImpl serviceTarget, final StringBuilder replaceBuilder, final JsonWriter jw) { boolean hasServiceTarget = (serviceTarget != null && serviceTarget.hasContent()); if (serviceName == null && !hasServiceTarget) { return; @@ -302,7 +305,7 @@ private static void serializeFramework(final Framework framework, final StringBu jw.writeByte(COMMA); } - private static void serializeNode(final Node node, final StringBuilder replaceBuilder, final JsonWriter jw) { + private static void serializeNode(final NodeImpl node, final StringBuilder replaceBuilder, final JsonWriter jw) { DslJsonUtil.writeFieldName("node", jw); jw.writeByte(JsonWriter.OBJECT_START); writeLastField("configured_name", node.getName(), replaceBuilder, jw); @@ -771,7 +774,7 @@ public void blockUntilReady() throws Exception { DslJsonSerializer.this.waitForMetadata(); } - public void serializeTransactionNdJson(Transaction transaction) { + public void serializeTransactionNdJson(TransactionImpl transaction) { jw.writeByte(JsonWriter.OBJECT_START); writeFieldName("transaction"); serializeTransaction(transaction); @@ -779,7 +782,7 @@ public void serializeTransactionNdJson(Transaction transaction) { jw.writeByte(NEW_LINE); } - public void serializeSpanNdJson(Span span) { + public void serializeSpanNdJson(SpanImpl span) { jw.writeByte(JsonWriter.OBJECT_START); writeFieldName("span"); serializeSpan(span); @@ -787,7 +790,7 @@ public void serializeSpanNdJson(Span span) { jw.writeByte(NEW_LINE); } - public void serializeErrorNdJson(ErrorCapture error) { + public void serializeErrorNdJson(ErrorCaptureImpl error) { jw.writeByte(JsonWriter.OBJECT_START); writeFieldName("error"); serializeError(error); @@ -861,7 +864,7 @@ public void serializeLogNdJson(byte[] bytesLog) { jw.writeByte(NEW_LINE); } - private void serializeError(ErrorCapture errorCapture) { + private void serializeError(ErrorCaptureImpl errorCapture) { jw.writeByte(JsonWriter.OBJECT_START); writeTimestamp(errorCapture.getTimestamp()); @@ -876,7 +879,7 @@ private void serializeError(ErrorCapture errorCapture) { jw.writeByte(JsonWriter.OBJECT_END); } - private void serializeErrorTransactionInfo(ErrorCapture.TransactionInfo errorTransactionInfo) { + private void serializeErrorTransactionInfo(ErrorCaptureImpl.TransactionInfo errorTransactionInfo) { writeFieldName("transaction"); jw.writeByte(JsonWriter.OBJECT_START); writeField("name", errorTransactionInfo.getName()); @@ -913,7 +916,7 @@ private void recursiveSerializeException(@Nullable Throwable exception) { jw.writeByte(JsonWriter.OBJECT_END); } - public String toJsonString(final Transaction transaction) { + public String toJsonString(final TransactionImpl transaction) { jw.reset(); serializeTransaction(transaction); final String s = jw.toString(); @@ -921,7 +924,7 @@ public String toJsonString(final Transaction transaction) { return s; } - public String toJsonString(Span span) { + public String toJsonString(SpanImpl span) { jw.reset(); serializeSpan(span); final String s = jw.toString(); @@ -929,7 +932,7 @@ public String toJsonString(Span span) { return s; } - public String toJsonString(final ErrorCapture error) { + public String toJsonString(final ErrorCaptureImpl error) { jw.reset(); serializeError(error); final String s = jw.toString(); @@ -958,8 +961,8 @@ private void serializeFramework(final String frameworkName, final @Nullable Stri jw.writeByte(COMMA); } - private void serializeTransaction(final Transaction transaction) { - TraceContext traceContext = transaction.getTraceContext(); + private void serializeTransaction(final TransactionImpl transaction) { + TraceContextImpl traceContext = transaction.getTraceContext(); jw.writeByte(OBJECT_START); writeTimestamp(transaction.getTimestamp()); @@ -985,7 +988,7 @@ private void serializeTransaction(final Transaction transaction) { jw.writeByte(OBJECT_END); } - private void serializeTraceContext(TraceContext traceContext, boolean serializeTransactionId) { + private void serializeTraceContext(TraceContextImpl traceContext, boolean serializeTransactionId) { // errors might only have an id writeNonLastIdField("id", traceContext.getId()); if (!traceContext.getTraceId().isEmpty()) { @@ -1000,8 +1003,8 @@ private void serializeTraceContext(TraceContext traceContext, boolean serializeT } } - private void serializeSpan(final Span span) { - TraceContext traceContext = span.getTraceContext(); + private void serializeSpan(final SpanImpl span) { + TraceContextImpl traceContext = span.getTraceContext(); jw.writeByte(OBJECT_START); writeField("name", span.getNameForSerialization()); writeTimestamp(span.getTimestamp()); @@ -1032,7 +1035,7 @@ private void serializeSpan(final Span span) { jw.writeByte(OBJECT_END); } - private void serializeSpanLinks(List spanLinks) { + private void serializeSpanLinks(List spanLinks) { if (!spanLinks.isEmpty()) { writeFieldName("links"); jw.writeByte(ARRAY_START); @@ -1040,7 +1043,7 @@ private void serializeSpanLinks(List spanLinks) { if (i > 0) { jw.writeByte(COMMA); } - TraceContext traceContext = spanLinks.get(i); + TraceContextImpl traceContext = spanLinks.get(i); jw.writeByte(OBJECT_START); writeNonLastIdField("trace_id", traceContext.getTraceId()); writeIdField("span_id", traceContext.getParentId()); @@ -1051,22 +1054,37 @@ private void serializeSpanLinks(List spanLinks) { } } - private void serializeOTel(Span span) { - serializeOtel(span, Collections.emptyList()); + private void serializeOTel(SpanImpl span) { + serializeOtel(span, Collections.emptyList(), requestBodyToString(span.getContext().getHttp().getRequestBody())); + } + + @Nullable + private CharSequence requestBodyToString(BodyCaptureImpl requestBody) { + //TODO: perform proper, charset aware conversion to string + ByteBuffer buffer = requestBody.getBody(); + if (buffer == null || buffer.position() == 0) { + return null; + } + buffer.flip(); + StringBuilder result = new StringBuilder(); + while (buffer.hasRemaining()) { + result.append((char) buffer.get()); + } + return result; } - private void serializeOTel(Transaction transaction) { - List profilingCorrelationStackTraceIds = transaction.getProfilingCorrelationStackTraceIds(); + private void serializeOTel(TransactionImpl transaction) { + List profilingCorrelationStackTraceIds = transaction.getProfilingCorrelationStackTraceIds(); synchronized (profilingCorrelationStackTraceIds) { - serializeOtel(transaction, profilingCorrelationStackTraceIds); + serializeOtel(transaction, profilingCorrelationStackTraceIds, null); } } - private void serializeOtel(AbstractSpan span, List profilingStackTraceIds) { + private void serializeOtel(AbstractSpanImpl span, List profilingStackTraceIds, @Nullable CharSequence httpRequestBody) { OTelSpanKind kind = span.getOtelKind(); Map attributes = span.getOtelAttributes(); - boolean hasAttributes = !attributes.isEmpty() || !profilingStackTraceIds.isEmpty(); + boolean hasAttributes = !attributes.isEmpty() || !profilingStackTraceIds.isEmpty() || httpRequestBody != null; boolean hasKind = kind != null; if (hasKind || hasAttributes) { writeFieldName("otel"); @@ -1116,6 +1134,13 @@ private void serializeOtel(AbstractSpan span, List profilingStackTraceIds } jw.writeByte(ARRAY_END); } + if (httpRequestBody != null) { + if (!isFirstAttrib) { + jw.writeByte(COMMA); + } + writeFieldName("http.request.body.content"); + jw.writeString(httpRequestBody); + } jw.writeByte(OBJECT_END); } @@ -1146,7 +1171,7 @@ private void serializeComposite(Composite composite) { jw.writeByte(COMMA); } - private void serializeServiceNameWithFramework(@Nullable final Transaction transaction, final TraceContext traceContext, final ServiceOrigin serviceOrigin) { + private void serializeServiceNameWithFramework(@Nullable final TransactionImpl transaction, final TraceContextImpl traceContext, final ServiceOriginImpl serviceOrigin) { String serviceName = traceContext.getServiceName(); String serviceVersion = traceContext.getServiceVersion(); boolean isFrameworkNameNotNull = transaction != null && transaction.getFrameworkName() != null; @@ -1166,7 +1191,7 @@ private void serializeServiceNameWithFramework(@Nullable final Transaction trans } } - private void serializeServiceOrigin(final ServiceOrigin serviceOrigin) { + private void serializeServiceOrigin(final ServiceOriginImpl serviceOrigin) { writeFieldName("origin"); jw.writeByte(OBJECT_START); if (null != serviceOrigin.getId()) { @@ -1180,7 +1205,7 @@ private void serializeServiceOrigin(final ServiceOrigin serviceOrigin) { jw.writeByte(COMMA); } - private void serializeCloudOrigin(final CloudOrigin cloudOrigin) { + private void serializeCloudOrigin(final CloudOriginImpl cloudOrigin) { writeFieldName("cloud"); jw.writeByte(OBJECT_START); @@ -1216,7 +1241,7 @@ private void serializeCloudOrigin(final CloudOrigin cloudOrigin) { * * @param span serialized span */ - private void serializeSpanType(Span span) { + private void serializeSpanType(SpanImpl span) { writeFieldName("type"); String type = span.getType(); if (type != null) { @@ -1342,7 +1367,7 @@ private void serializeStackTraceElement(StackFrame frame, StringBuilder replaceB jw.writeByte(OBJECT_END); } - private void serializeSpanContext(SpanContext context, TraceContext traceContext) { + private void serializeSpanContext(SpanContextImpl context, TraceContextImpl traceContext) { writeFieldName("context"); jw.writeByte(OBJECT_START); @@ -1359,7 +1384,7 @@ private void serializeSpanContext(SpanContext context, TraceContext traceContext jw.writeByte(COMMA); } - private void serializeDestination(Destination destination, @Nullable CharSequence resource) { + private void serializeDestination(DestinationImpl destination, @Nullable CharSequence resource) { if (destination.hasContent() || resource != null) { writeFieldName("destination"); jw.writeByte(OBJECT_START); @@ -1406,7 +1431,7 @@ private void serializeService(boolean hasCloudContent, CharSequence resource) { } } - private void serializeDestinationCloud(boolean isCloudHasContent, Destination.Cloud cloud) { + private void serializeDestinationCloud(boolean isCloudHasContent, DestinationImpl.CloudImpl cloud) { if (isCloudHasContent) { writeFieldName("cloud"); jw.writeByte(OBJECT_START); @@ -1415,7 +1440,7 @@ private void serializeDestinationCloud(boolean isCloudHasContent, Destination.Cl } } - private void serializeMessageContext(final Message message) { + private void serializeMessageContext(final MessageImpl message) { if (message.hasContent()) { writeFieldName("message"); jw.writeByte(OBJECT_START); @@ -1463,7 +1488,7 @@ private void serializeMessageHeaders(Headers headers) { } } - private void serializeFaas(final Faas faas) { + private void serializeFaas(final FaasImpl faas) { if (faas.hasContent()) { writeFieldName("faas"); jw.writeByte(OBJECT_START); @@ -1478,7 +1503,7 @@ private void serializeFaas(final Faas faas) { } } - private void serializeFaasTrigger(final FaasTrigger trigger) { + private void serializeFaasTrigger(final FaasTriggerImpl trigger) { if (trigger.hasContent()) { writeFieldName("trigger"); jw.writeByte(OBJECT_START); @@ -1489,7 +1514,7 @@ private void serializeFaasTrigger(final FaasTrigger trigger) { } } - private void serializeDbContext(final Db db) { + private void serializeDbContext(final DbImpl db) { if (db.hasContent()) { writeFieldName("db"); jw.writeByte(OBJECT_START); @@ -1519,7 +1544,7 @@ private void serializeDbContext(final Db db) { } } - private void serializeHttpContext(final Http http) { + private void serializeHttpContext(final HttpImpl http) { if (http.hasContent()) { writeFieldName("http"); jw.writeByte(OBJECT_START); @@ -1574,7 +1599,7 @@ private void serializeDroppedSpanStats(final DroppedSpanStats droppedSpanStats) jw.writeByte(COMMA); } - private void serializeContext(@Nullable final Transaction transaction, final TransactionContext context, TraceContext traceContext) { + private void serializeContext(@Nullable final TransactionImpl transaction, final TransactionContextImpl context, TraceContextImpl traceContext) { writeFieldName("context"); jw.writeByte(OBJECT_START); serializeServiceNameWithFramework(transaction, traceContext, context.getServiceOrigin()); @@ -1602,7 +1627,7 @@ private void serializeContext(@Nullable final Transaction transaction, final Tra } // visible for testing - void serializeLabels(AbstractContext context) { + void serializeLabels(AbstractContextImpl context) { if (context.hasLabels()) { serializeStringKeyScalarValueMap(context.getLabelIterator(), replaceBuilder, jw, false, apmServerClient.supportsNonStringLabels()); } else { @@ -1611,7 +1636,7 @@ void serializeLabels(AbstractContext context) { } } - private void serializeResponse(final Response response) { + private void serializeResponse(final ResponseImpl response) { if (response.hasContent()) { writeFieldName("response"); jw.writeByte(OBJECT_START); @@ -1625,7 +1650,7 @@ private void serializeResponse(final Response response) { } } - private void serializeRequest(final Request request) { + private void serializeRequest(final RequestImpl request) { if (request.hasContent()) { writeFieldName("request"); jw.writeByte(OBJECT_START); @@ -1660,7 +1685,7 @@ private void serializeRequest(final Request request) { } // visible for testing - void serializeUrl(final Url url) { + void serializeUrl(final UrlImpl url) { jw.writeByte(OBJECT_START); writeField("full", url.getFull()); writeField("hostname", url.getHostname()); @@ -1682,7 +1707,7 @@ void serializeUrl(final Url url) { jw.writeByte(OBJECT_END); } - private void serializeSocket(final Socket socket) { + private void serializeSocket(final SocketImpl socket) { writeFieldName("socket"); jw.writeByte(OBJECT_START); writeLastField("remote_address", socket.getRemoteAddress()); @@ -1740,7 +1765,7 @@ private void serializePotentiallyMultiValuedEntry(String key, @Nullable Object v } } - private void serializeUser(final User user) { + private void serializeUser(final UserImpl user) { writeFieldName("user"); jw.writeByte(OBJECT_START); writeField("domain", user.getDomain()); @@ -1834,12 +1859,12 @@ private void writeFieldName(final String fieldName) { DslJsonUtil.writeFieldName(fieldName, jw); } - private void writeNonLastIdField(String fieldName, Id id) { + private void writeNonLastIdField(String fieldName, IdImpl id) { writeIdField(fieldName, id); jw.writeByte(COMMA); } - private void writeIdField(String fieldName, Id id) { + private void writeIdField(String fieldName, IdImpl id) { writeFieldName(fieldName); jw.writeByte(JsonWriter.QUOTE); id.writeAsHex(jw); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistryReporter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistryReporter.java index 04327f4f0f..565f74b0ec 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistryReporter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/MetricRegistryReporter.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.report.serialize; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.service.ServiceInfo; import co.elastic.apm.agent.tracer.AbstractLifecycleListener; @@ -26,7 +27,6 @@ import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.MetricSet; import co.elastic.apm.agent.report.Reporter; -import co.elastic.apm.agent.report.ReporterConfiguration; import com.dslplatform.json.JsonWriter; import java.util.List; @@ -49,7 +49,7 @@ public MetricRegistryReporter(ElasticApmTracer tracer) { @Override public void start(Tracer tracer) { - long intervalMs = tracer.getConfig(ReporterConfiguration.class).getMetricsIntervalMs(); + long intervalMs = tracer.getConfig(ReporterConfigurationImpl.class).getMetricsIntervalMs(); if (intervalMs > 0) { tracer.require(ElasticApmTracer.class) .getSharedSingleThreadedPool() diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/SerializationConstants.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/SerializationConstants.java index bd927d1b8f..b036d7cc52 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/SerializationConstants.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/report/serialize/SerializationConstants.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.report.serialize; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.tracer.metrics.DslJsonUtil; import javax.annotation.Nullable; @@ -43,7 +43,7 @@ private SerializationConstants(int maxLongStringValueLength) { this.maxLongStringValueLength = maxLongStringValueLength; } - public static void init(CoreConfiguration coreConfiguration) { + public static void init(CoreConfigurationImpl coreConfiguration) { INSTANCE = new SerializationConstants(coreConfiguration.getLongFieldMaxLength()); } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentation.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentation.java index 5d2477c282..ed3efebec5 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentation.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentation.java @@ -18,13 +18,13 @@ */ package co.elastic.apm.agent.tracemethods; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.sdk.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; import co.elastic.apm.agent.matcher.MethodMatcher; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.sdk.logging.Logger; @@ -59,11 +59,11 @@ public class TraceMethodInstrumentation extends ElasticApmInstrumentation { private final MethodMatcher methodMatcher; - private final CoreConfiguration config; + private final CoreConfigurationImpl config; public TraceMethodInstrumentation(Tracer tracer, MethodMatcher methodMatcher) { this.methodMatcher = methodMatcher; - config = tracer.getConfig(CoreConfiguration.class); + config = tracer.getConfig(CoreConfigurationImpl.class); } @Override @@ -135,7 +135,7 @@ public static class TraceMethodAdvice { private static final long traceMethodThresholdMicros; static { - CoreConfiguration config = tracer.getConfig(CoreConfiguration.class); + CoreConfigurationImpl config = tracer.getConfig(CoreConfigurationImpl.class); traceMethodThresholdMicros = config.getTraceMethodsDurationThreshold().getMicros(); } @@ -143,9 +143,9 @@ public static class TraceMethodAdvice { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object onMethodEnter(@Advice.Origin Class clazz, @SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature String signature) { - AbstractSpan span = null; - ElasticContext activeContext = tracer.currentContext(); - final AbstractSpan parentSpan = tracer.getActive(); + AbstractSpanImpl span = null; + TraceStateImpl activeContext = tracer.currentContext(); + final AbstractSpanImpl parentSpan = tracer.getActive(); if (parentSpan == null) { span = tracer.startRootTransaction(PrivilegedActionUtils.getClassLoader(clazz)); if (span != null) { @@ -167,11 +167,11 @@ public static Object onMethodEnter(@Advice.Origin Class clazz, @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void onMethodExit(@Advice.Enter @Nullable Object spanObj, @Advice.Thrown @Nullable Throwable t) { - AbstractSpan span = (AbstractSpan) spanObj; + AbstractSpanImpl span = (AbstractSpanImpl) spanObj; if (span != null) { span.captureException(t); final long endTime = span.getTraceContext().getClock().getEpochMicros(); - if (span instanceof Span) { + if (span instanceof SpanImpl) { long durationMicros = endTime - span.getTimestamp(); if (traceMethodThresholdMicros > 0 && durationMicros < traceMethodThresholdMicros && t == null) { span.requestDiscarding(); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/ProfilerSharedMemoryWriter.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/ProfilerSharedMemoryWriter.java index 259fb7687a..ae5dbb285f 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/ProfilerSharedMemoryWriter.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/ProfilerSharedMemoryWriter.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.universalprofiling; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.otel.UniversalProfilingCorrelation; @@ -80,7 +80,7 @@ private static void memoryStoreStoreBarrier() { writeForMemoryBarrier = 42; } - static void updateThreadCorrelationStorage(@Nullable AbstractSpan newSpan) { + static void updateThreadCorrelationStorage(@Nullable AbstractSpanImpl newSpan) { try { ByteBuffer tls = UniversalProfilingCorrelation.getCurrentThreadStorage(true, TLS_STORAGE_SIZE); // tls might be null if unsupported or something went wrong on initialization @@ -91,7 +91,7 @@ static void updateThreadCorrelationStorage(@Nullable AbstractSpan newSpan) { tls.putChar(TLS_MINOR_VERSION_OFFSET, (char) 1); if (newSpan != null) { - Transaction tx = newSpan.getParentTransaction(); + TransactionImpl tx = newSpan.getParentTransaction(); tls.put(TLS_TRACE_PRESENT_OFFSET, (byte) 1); tls.put(TLS_TRACE_FLAGS_OFFSET, newSpan.getTraceContext().getFlags()); tls.position(TLS_TRACE_ID_OFFSET); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/SpanProfilingSamplesCorrelator.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/SpanProfilingSamplesCorrelator.java index 90d6b36981..c471d1282a 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/SpanProfilingSamplesCorrelator.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/SpanProfilingSamplesCorrelator.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.universalprofiling; -import co.elastic.apm.agent.impl.transaction.Id; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.IdImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.report.Reporter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -43,7 +43,7 @@ public class SpanProfilingSamplesCorrelator { * However, this is highly unlikely (see birthday problem) and even if * it were to happen, the only consequences would be a potentially incorrect correlation for the two colliding transactions. */ - private final ConcurrentHashMap transactionsById = new ConcurrentHashMap<>(); + private final ConcurrentHashMap transactionsById = new ConcurrentHashMap<>(); private final Reporter reporter; @@ -89,17 +89,17 @@ public void setSpanBufferDurationNanos(long nanos) { spanBufferDurationNanos = nanos; } - public void onTransactionStart(Transaction transaction) { + public void onTransactionStart(TransactionImpl transaction) { if (transaction.isSampled()) { transactionsById.put(transaction.getTraceContext().getId(), transaction); } } - public void stopCorrelating(Transaction transaction) { + public void stopCorrelating(TransactionImpl transaction) { transactionsById.remove(transaction.getTraceContext().getId()); } - public void reportOrBufferTransaction(Transaction transaction) { + public void reportOrBufferTransaction(TransactionImpl transaction) { if (!transactionsById.containsKey(transaction.getTraceContext().getId())) { // transaction is not being correlated, e.g. because it was not sampled // therefore no need to buffer it @@ -130,8 +130,8 @@ public void reportOrBufferTransaction(Transaction transaction) { } public synchronized void correlate( - Id traceId, Id transactionId, Id stackTraceId, int count) { - Transaction tx = transactionsById.get(transactionId); + IdImpl traceId, IdImpl transactionId, IdImpl stackTraceId, int count) { + TransactionImpl tx = transactionsById.get(transactionId); if (tx != null) { // this branch should be true practically always unless there was a collision in transactionsById // nonetheless for the unlikely case that it happens, we at least prevent wrongly adding data to another transaction @@ -182,7 +182,7 @@ public synchronized void shutdownAndFlushAll() { private static class BufferedTransaction implements MoveableEvent { - Transaction transaction; + TransactionImpl transaction; long endNanoTimestamp; @Override @@ -198,9 +198,9 @@ public void clear() { endNanoTimestamp = -1; } - public static final EventTranslatorTwoArg TRANSLATOR = new EventTranslatorTwoArg() { + public static final EventTranslatorTwoArg TRANSLATOR = new EventTranslatorTwoArg() { @Override - public void translateTo(BufferedTransaction event, long sequence, Transaction transaction, Long timestamp) { + public void translateTo(BufferedTransaction event, long sequence, TransactionImpl transaction, Long timestamp) { event.transaction = transaction; event.endNanoTimestamp = timestamp; } diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/UniversalProfilingIntegration.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/UniversalProfilingIntegration.java index accfe2b8d2..2fc3226bf0 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/UniversalProfilingIntegration.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/universalprofiling/UniversalProfilingIntegration.java @@ -18,15 +18,15 @@ */ package co.elastic.apm.agent.universalprofiling; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.UniversalProfilingConfiguration; import co.elastic.apm.agent.impl.ActivationListener; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.metadata.SystemInfo; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; -import co.elastic.apm.agent.impl.transaction.Id; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.IdImpl; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.util.ExecutorUtils; @@ -42,7 +42,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.time.Duration; import java.util.Random; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -77,13 +76,13 @@ public class UniversalProfilingIntegration { private ActivationListener activationListener = new ActivationListener() { @Override - public void beforeActivate(AbstractSpan span) { + public void beforeActivate(AbstractSpanImpl span) { ProfilerSharedMemoryWriter.updateThreadCorrelationStorage(span); } @Override - public void afterDeactivate(@Nullable AbstractSpan deactivatedSpan) { - ElasticContext currentContext = tracer.currentContext(); + public void afterDeactivate(@Nullable AbstractSpanImpl deactivatedSpan) { + TraceStateImpl currentContext = tracer.currentContext(); ProfilerSharedMemoryWriter.updateThreadCorrelationStorage(currentContext.getSpan()); } }; @@ -103,7 +102,7 @@ public void start(ElasticApmTracer tracer) { socketPath = openProfilerSocket(config.getSocketDir()); - CoreConfiguration coreConfig = tracer.getConfig(CoreConfiguration.class); + CoreConfigurationImpl coreConfig = tracer.getConfig(CoreConfigurationImpl.class); ByteBuffer processCorrelationStorage = ProfilerSharedMemoryWriter.generateProcessCorrelationStorage( coreConfig.getServiceName(), coreConfig.getEnvironment(), socketPath); UniversalProfilingCorrelation.setProcessStorage(processCorrelationStorage); @@ -158,7 +157,7 @@ public void stop() { } } - public void afterTransactionStart(Transaction startedTransaction) { + public void afterTransactionStart(TransactionImpl startedTransaction) { if (correlator != null) { correlator.onTransactionStart(startedTransaction); } @@ -174,7 +173,7 @@ public void afterTransactionStart(Transaction startedTransaction) { * * @param endedTransaction the transaction to be reported */ - public void correlateAndReport(Transaction endedTransaction) { + public void correlateAndReport(TransactionImpl endedTransaction) { if (correlator != null) { correlator.reportOrBufferTransaction(endedTransaction); } else { @@ -182,7 +181,7 @@ public void correlateAndReport(Transaction endedTransaction) { } } - public void drop(Transaction endedTransaction) { + public void drop(TransactionImpl endedTransaction) { if (correlator != null) { correlator.stopCorrelating(endedTransaction); } @@ -249,9 +248,9 @@ private void handleMessage(ProfilerRegistrationMessage message) { correlator.setSpanBufferDurationNanos(delayMillis * 1_000_000L); } - private final Id tempTraceId = Id.new128BitId(); - private final Id tempSpanId = Id.new64BitId(); - private final Id tempStackTraceId = Id.new128BitId(); + private final IdImpl tempTraceId = IdImpl.new128BitId(); + private final IdImpl tempSpanId = IdImpl.new64BitId(); + private final IdImpl tempStackTraceId = IdImpl.new128BitId(); private void handleMessage(TraceCorrelationMessage message) { tempTraceId.fromBytes(message.getTraceId(), 0); tempSpanId.fromBytes(message.getLocalRootSpanId(), 0); diff --git a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/ThreadDump.java b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/ThreadDump.java index 999c9a6d79..dfee46f2c7 100644 --- a/apm-agent-core/src/main/java/co/elastic/apm/agent/util/ThreadDump.java +++ b/apm-agent-core/src/main/java/co/elastic/apm/agent/util/ThreadDump.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.util; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.tracer.AbstractLifecycleListener; @@ -45,7 +45,7 @@ public class ThreadDump extends AbstractLifecycleListener { @Override public void start(Tracer tracer) throws Exception { - long threadDumpInterval = tracer.getConfig(CoreConfiguration.class).getThreadDumpInterval(); + long threadDumpInterval = tracer.getConfig(CoreConfigurationImpl.class).getThreadDumpInterval(); if (threadDumpInterval <= 0) { return; } diff --git a/apm-agent-core/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.internal.pooling.ObjectPooling$ObjectPoolFactory b/apm-agent-core/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.internal.pooling.ObjectPooling$ObjectPoolFactory index d860744b17..cc1ef54dd3 100644 --- a/apm-agent-core/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.internal.pooling.ObjectPooling$ObjectPoolFactory +++ b/apm-agent-core/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.internal.pooling.ObjectPooling$ObjectPoolFactory @@ -1 +1 @@ -co.elastic.apm.agent.objectpool.ObjectPoolFactory +co.elastic.apm.agent.objectpool.ObjectPoolFactoryImpl diff --git a/apm-agent-core/src/main/resources/META-INF/services/org.stagemonitor.configuration.ConfigurationOptionProvider b/apm-agent-core/src/main/resources/META-INF/services/org.stagemonitor.configuration.ConfigurationOptionProvider index 878419acfb..a3d0ed31db 100644 --- a/apm-agent-core/src/main/resources/META-INF/services/org.stagemonitor.configuration.ConfigurationOptionProvider +++ b/apm-agent-core/src/main/resources/META-INF/services/org.stagemonitor.configuration.ConfigurationOptionProvider @@ -1,10 +1,10 @@ co.elastic.apm.agent.impl.TracerConfiguration -co.elastic.apm.agent.configuration.CoreConfiguration -co.elastic.apm.agent.report.ReporterConfiguration -co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration -co.elastic.apm.agent.logging.LoggingConfiguration +co.elastic.apm.agent.configuration.CoreConfigurationImpl +co.elastic.apm.agent.report.ReporterConfigurationImpl +co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl +co.elastic.apm.agent.logging.LoggingConfigurationImpl co.elastic.apm.agent.impl.circuitbreaker.CircuitBreakerConfiguration -co.elastic.apm.agent.configuration.MetricsConfiguration -co.elastic.apm.agent.configuration.ServerlessConfiguration +co.elastic.apm.agent.configuration.MetricsConfigurationImpl +co.elastic.apm.agent.configuration.ServerlessConfigurationImpl co.elastic.apm.agent.configuration.SpanConfiguration co.elastic.apm.agent.configuration.UniversalProfilingConfiguration diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/AbstractInstrumentationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/AbstractInstrumentationTest.java index c6dda2d014..f48781dee4 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/AbstractInstrumentationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/AbstractInstrumentationTest.java @@ -20,13 +20,13 @@ import co.elastic.apm.agent.bci.ElasticApmAgent; import co.elastic.apm.agent.collections.WeakConcurrentProviderImpl; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpanConfiguration; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.Tracer; import co.elastic.apm.agent.impl.TracerInternalApiUtils; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import co.elastic.apm.agent.report.ApmServerClient; import net.bytebuddy.agent.ByteBuddyAgent; @@ -49,7 +49,7 @@ public abstract class AbstractInstrumentationTest { /** * Set to a valid path in order to make byte buddy dump instrumented classes. - * We cannot use the {@link co.elastic.apm.agent.configuration.CoreConfiguration#bytecodeDumpPath} config because + * We cannot use the {@link CoreConfigurationImpl#bytecodeDumpPath} config because * the way it works is by setting the related byte buddy system property, which is set statically, and since we use * Mockito for agent configs, byte buddy gets loaded early and this property gets set before our configuration * can be applied. @@ -99,7 +99,7 @@ protected void disableRecyclingValidation() { validateRecycling = false; } - public static Tracer getTracer() { + public static ElasticApmTracer getTracer() { return tracer; } @@ -150,8 +150,8 @@ public final void cleanUp() { * @param name transaction name * @return root transaction */ - protected Transaction startTestRootTransaction(String name) { - Transaction transaction = tracer.startRootTransaction(null); + protected TransactionImpl startTestRootTransaction(String name) { + TransactionImpl transaction = tracer.startRootTransaction(null); assertThat(transaction).isNotNull(); @@ -168,7 +168,7 @@ protected Transaction startTestRootTransaction(String name) { * * @return root transaction */ - protected Transaction startTestRootTransaction() { + protected TransactionImpl startTestRootTransaction() { return startTestRootTransaction("test root transaction"); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/MockReporter.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/MockReporter.java index 6fe269b495..8a332e39cb 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/MockReporter.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/MockReporter.java @@ -18,15 +18,15 @@ */ package co.elastic.apm.agent; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; -import co.elastic.apm.agent.impl.context.Destination; -import co.elastic.apm.agent.impl.error.ErrorCapture; +import co.elastic.apm.agent.impl.context.DestinationImpl; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.impl.metadata.MetaData; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.report.IntakeV2ReportingEventHandler; import co.elastic.apm.agent.report.Reporter; @@ -96,17 +96,17 @@ public class MockReporter implements Reporter { */ private boolean gcWhenAssertingRecycling; - private final List transactions = Collections.synchronizedList(new ArrayList<>()); + private final List transactions = Collections.synchronizedList(new ArrayList<>()); - private final List partialTransactions = Collections.synchronizedList(new ArrayList<>()); - private final List spans = Collections.synchronizedList(new ArrayList<>()); - private final List errors = Collections.synchronizedList(new ArrayList<>()); + private final List partialTransactions = Collections.synchronizedList(new ArrayList<>()); + private final List spans = Collections.synchronizedList(new ArrayList<>()); + private final List errors = Collections.synchronizedList(new ArrayList<>()); private final List bytes = new CopyOnWriteArrayList<>(); private final List logs = Collections.synchronizedList(new ArrayList<>()); private final ObjectMapper objectMapper; private final boolean verifyJsonSchema; - private Consumer partialTransactionHandler; + private Consumer partialTransactionHandler; private boolean closed; @@ -197,7 +197,7 @@ public void start() { } @Override - public synchronized void reportPartialTransaction(Transaction transaction) { + public synchronized void reportPartialTransaction(TransactionImpl transaction) { if (closed) { return; } @@ -209,12 +209,12 @@ public synchronized void reportPartialTransaction(Transaction transaction) { } } - public void setPartialTransactionHandler(Consumer transactionHandler) { + public void setPartialTransactionHandler(Consumer transactionHandler) { this.partialTransactionHandler = transactionHandler; } @Override - public synchronized void report(Transaction transaction) { + public synchronized void report(TransactionImpl transaction) { if (closed) { return; } @@ -237,7 +237,7 @@ public synchronized void report(Transaction transaction) { } @Override - public synchronized void report(Span span) { + public synchronized void report(SpanImpl span) { if (closed) { return; } @@ -266,7 +266,7 @@ public synchronized void report(Span span) { } - private void verifySpanType(Span span) { + private void verifySpanType(SpanImpl span) { String type = span.getType(); assertThat(type) .describedAs("span type is mandatory") @@ -299,11 +299,11 @@ private void verifySpanType(Span span) { } - private void verifyDestinationFields(Span span) { + private void verifyDestinationFields(SpanImpl span) { if (!span.isExit()) { return; } - Destination destination = span.getContext().getDestination(); + DestinationImpl destination = span.getContext().getDestination(); if (checkDestinationAddress && !SPAN_TYPES_WITHOUT_ADDRESS.contains(span.getSubtype())) { // see if this span's subtype is not supported for its type Collection unsupportedSubtypes = SPAN_SUBTYPES_WITHOUT_ADDRESS.getOrDefault(span.getType(), Collections.emptySet()); @@ -316,7 +316,7 @@ private void verifyDestinationFields(Span span) { } } - private void verifyServiceTarget(Span span) { + private void verifyServiceTarget(SpanImpl span) { if (!span.isExit() || !checkServiceTarget) { return; } @@ -335,7 +335,7 @@ private void verifyServiceTarget(Span span) { * * @param transaction transaction to serialize */ - public void verifyTransactionSchema(Transaction transaction) { + public void verifyTransactionSchema(TransactionImpl transaction) { verifyJsonSchemas(dsl -> dsl.toJsonString(transaction), si -> si.transactionSchema, si -> si.transactionSchemaPath); } @@ -344,7 +344,7 @@ public void verifyTransactionSchema(Transaction transaction) { * * @param span span to serialize */ - public void verifySpanSchema(Span span) { + public void verifySpanSchema(SpanImpl span) { verifyJsonSchemas(dsl -> dsl.toJsonString(span), si -> si.spanSchema, si -> si.spanSchemaPath); } @@ -353,7 +353,7 @@ public void verifySpanSchema(Span span) { * * @param error error to serialize */ - public void verifyErrorSchema(ErrorCapture error) { + public void verifyErrorSchema(ErrorCaptureImpl error) { verifyJsonSchemas(dsl -> dsl.toJsonString(error), si -> si.errorSchema, si -> si.errorSchemaPath); } @@ -416,11 +416,11 @@ private JsonNode asJson(String jsonContent) { } } - public synchronized List getTransactions() { + public synchronized List getTransactions() { return Collections.unmodifiableList(transactions); } - public synchronized List getPartialTransactions() { + public synchronized List getPartialTransactions() { return Collections.unmodifiableList(partialTransactions); } @@ -428,14 +428,14 @@ public synchronized int getNumReportedTransactions() { return transactions.size(); } - public synchronized Transaction getFirstTransaction() { + public synchronized TransactionImpl getFirstTransaction() { assertThat(transactions) .describedAs("at least one transaction expected, none have been reported (yet)") .isNotEmpty(); return transactions.get(0); } - public Transaction getFirstTransaction(long timeoutMs) { + public TransactionImpl getFirstTransaction(long timeoutMs) { awaitUntilAsserted(timeoutMs, () -> assertThat(getTransactions()).isNotEmpty()); return getFirstTransaction(); } @@ -450,12 +450,12 @@ public void assertNoTransaction(long timeoutMs) { awaitUntilTimeout(timeoutMs, this::assertNoTransaction); } - public Span getFirstSpan(long timeoutMs) { + public SpanImpl getFirstSpan(long timeoutMs) { awaitUntilAsserted(timeoutMs, () -> assertThat(getSpans()).isNotEmpty()); return getFirstSpan(); } - public ErrorCapture getFirstError(long timeoutMs) { + public ErrorCaptureImpl getFirstError(long timeoutMs) { awaitUntilAsserted(timeoutMs, () -> assertThat(getErrors()).isNotEmpty()); return getFirstError(); } @@ -501,7 +501,7 @@ public void awaitLogsCount(int count) { } @Override - public synchronized void report(ErrorCapture error) { + public synchronized void report(ErrorCaptureImpl error) { if (closed) { return; } @@ -537,14 +537,14 @@ public boolean flush() { return true; } - public synchronized Span getFirstSpan() { + public synchronized SpanImpl getFirstSpan() { assertThat(spans) .describedAs("at least one span expected, none have been reported") .isNotEmpty(); return spans.get(0); } - public synchronized List getSpans() { + public synchronized List getSpans() { return Collections.unmodifiableList(spans); } @@ -561,11 +561,11 @@ public synchronized List getLogs() { .collect(Collectors.toList()); } - public Span getSpanByName(String name) { - Optional optional = getSpans().stream().filter(s -> s.getNameAsString().equals(name)).findAny(); + public SpanImpl getSpanByName(String name) { + Optional optional = getSpans().stream().filter(s -> s.getNameAsString().equals(name)).findAny(); assertThat(optional) .withFailMessage("No span with name '%s' found in reported spans %s", name, - getSpans().stream().map(Span::getNameAsString).collect(Collectors.toList())) + getSpans().stream().map(SpanImpl::getNameAsString).collect(Collectors.toList())) .isPresent(); return optional.get(); } @@ -574,7 +574,7 @@ public synchronized int getNumReportedSpans() { return spans.size(); } - public synchronized List getErrors() { + public synchronized List getErrors() { return Collections.unmodifiableList(errors); } @@ -586,7 +586,7 @@ public synchronized int getNumReportedLogs() { return logs.size(); } - public synchronized ErrorCapture getFirstError() { + public synchronized ErrorCaptureImpl getFirstError() { assertThat(errors) .describedAs("at least one error expected, none have been reported") .isNotEmpty(); @@ -631,13 +631,13 @@ public synchronized void resetWithoutRecycling() { } /** - * Calls {@link AbstractSpan#decrementReferences()} for all reported transactions and spans to emulate the references being decremented + * Calls {@link AbstractSpanImpl#decrementReferences()} for all reported transactions and spans to emulate the references being decremented * after reporting to the APM Server. * See {@link IntakeV2ReportingEventHandler#writeEvent(ReportingEvent)} */ public synchronized void decrementReferences() { - transactions.forEach(Transaction::decrementReferences); - spans.forEach(Span::decrementReferences); + transactions.forEach(TransactionImpl::decrementReferences); + spans.forEach(SpanImpl::decrementReferences); } /** @@ -646,18 +646,18 @@ public synchronized void decrementReferences() { */ public synchronized void assertRecycledAfterDecrementingReferences() { - List transactions = getTransactions(); - List transactionsToFlush = transactions.stream() + List transactions = getTransactions(); + List transactionsToFlush = transactions.stream() .filter(t -> !hasEmptyTraceContext(t)) .collect(Collectors.toList()); - List spans = getSpans(); - List spansToFlush = spans.stream() + List spans = getSpans(); + List spansToFlush = spans.stream() .filter(s -> !hasEmptyTraceContext(s)) .collect(Collectors.toList()); - transactionsToFlush.forEach(Transaction::decrementReferences); - spansToFlush.forEach(Span::decrementReferences); + transactionsToFlush.forEach(TransactionImpl::decrementReferences); + spansToFlush.forEach(SpanImpl::decrementReferences); if (gcWhenAssertingRecycling) { System.gc(); @@ -691,7 +691,7 @@ public synchronized void assertRecycledAfterDecrementingReferences() { // errors are recycled directly because they have no reference counter - errors.forEach(ErrorCapture::recycle); + errors.forEach(ErrorCaptureImpl::recycle); } /** @@ -739,7 +739,7 @@ public void awaitUntilTimeout(long timeoutMs, ThrowingRunnable runnable) { } } - private static boolean hasEmptyTraceContext(AbstractSpan item) { + private static boolean hasEmptyTraceContext(AbstractSpanImpl item) { return item.getTraceContext().getId().isEmpty(); } @@ -794,7 +794,7 @@ private enum SchemaInstance { this.errorSchemaPath = errorSchema; ConfigurationRegistry spyConfig = SpyConfiguration.createSpyConfig(); - StacktraceConfiguration stacktraceConfiguration = spyConfig.getConfig(StacktraceConfiguration.class); + StacktraceConfigurationImpl stacktraceConfiguration = spyConfig.getConfig(StacktraceConfigurationImpl.class); Future metaData = MetaData.create(spyConfig, null); ApmServerClient client = mock(ApmServerClient.class); @@ -805,7 +805,7 @@ private enum SchemaInstance { doReturn(isLatest).when(client).supportsNonStringLabels(); doReturn(isLatest).when(client).supportsLogsEndpoint(); - SerializationConstants.init(spyConfig.getConfig(CoreConfiguration.class)); + SerializationConstants.init(spyConfig.getConfig(CoreConfigurationImpl.class)); this.serializer = new DslJsonSerializer(stacktraceConfiguration, client, metaData).newWriter(); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/TransactionUtils.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/TransactionUtils.java index 637915aea1..f1212d257e 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/TransactionUtils.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/TransactionUtils.java @@ -18,13 +18,13 @@ */ package co.elastic.apm.agent; -import co.elastic.apm.agent.impl.baggage.Baggage; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.TransactionContext; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; +import co.elastic.apm.agent.impl.context.RequestImpl; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; import co.elastic.apm.agent.impl.sampling.ConstantSampler; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import java.util.ArrayList; @@ -32,15 +32,15 @@ public class TransactionUtils { - public static void fillTransaction(Transaction t) { - t.startRoot((long) 0, ConstantSampler.of(true), Baggage.EMPTY) + public static void fillTransaction(TransactionImpl t) { + t.startRoot((long) 0, ConstantSampler.of(true), BaggageImpl.EMPTY) .withName("GET /api/types") .withType("request") .withResult("success") .withOutcome(Outcome.SUCCESS); - TransactionContext context = t.getContext(); - Request request = context.getRequest(); + TransactionContextImpl context = t.getContext(); + RequestImpl request = context.getRequest(); request.withHttpVersion("1.1"); request.withMethod("POST"); request.withBodyBuffer().append("Hello World"); @@ -77,10 +77,10 @@ public static void fillTransaction(Transaction t) { context.addCustom("some_other_value", "foo bar"); } - public static List getSpans(Transaction t) { - List spans = new ArrayList<>(); - Span span = new Span(MockTracer.create()) - .start(TraceContext.fromParent(), t, Baggage.EMPTY, -1) + public static List getSpans(TransactionImpl t) { + List spans = new ArrayList<>(); + SpanImpl span = new SpanImpl(MockTracer.create()) + .start(TraceContextImpl.fromParent(), t, BaggageImpl.EMPTY, -1) .withName("SELECT FROM product_types") .withType("db") .withSubtype("postgresql") @@ -95,21 +95,21 @@ public static List getSpans(Transaction t) { span.addLabel("framework", "some-framework"); spans.add(span); - spans.add(new Span(MockTracer.create()) - .start(TraceContext.fromParent(), t, Baggage.EMPTY, -1) + spans.add(new SpanImpl(MockTracer.create()) + .start(TraceContextImpl.fromParent(), t, BaggageImpl.EMPTY, -1) .withName("GET /api/types") .withType("request")); - spans.add(new Span(MockTracer.create()) - .start(TraceContext.fromParent(), t, Baggage.EMPTY, -1) + spans.add(new SpanImpl(MockTracer.create()) + .start(TraceContextImpl.fromParent(), t, BaggageImpl.EMPTY, -1) .withName("GET /api/types") .withType("request")); - spans.add(new Span(MockTracer.create()) - .start(TraceContext.fromParent(), t, Baggage.EMPTY, -1) + spans.add(new SpanImpl(MockTracer.create()) + .start(TraceContextImpl.fromParent(), t, BaggageImpl.EMPTY, -1) .withName("GET /api/types") .withType("request")); - span = new Span(MockTracer.create()) - .start(TraceContext.fromParent(), t, Baggage.EMPTY, -1) + span = new SpanImpl(MockTracer.create()) + .start(TraceContextImpl.fromParent(), t, BaggageImpl.EMPTY, -1) .appendToName("GET ") .appendToName("test.elastic.co") .withType("ext") diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java index 53e2954672..a82ef60852 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/bci/InstrumentationTest.java @@ -20,10 +20,10 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.bytebuddy.Instrumented; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.sdk.DynamicTransformer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; @@ -79,14 +79,14 @@ class InstrumentationTest { private ElasticApmTracer tracer; private ConfigurationRegistry configurationRegistry; - private CoreConfiguration coreConfig; + private CoreConfigurationImpl coreConfig; private String privateString; @BeforeEach void setup() { tracer = MockTracer.createRealTracer(); configurationRegistry = tracer.getConfigurationRegistry(); - coreConfig = configurationRegistry.getConfig(CoreConfiguration.class); + coreConfig = configurationRegistry.getConfig(CoreConfigurationImpl.class); } @AfterEach @@ -476,7 +476,7 @@ void testAdviceWithAgentParameterType() { } @Nullable - public AbstractSpan getSpanFromThreadLocal() { + public AbstractSpanImpl getSpanFromThreadLocal() { return null; } @@ -989,7 +989,7 @@ public static class AgentTypeReturnInstrumentation extends ElasticApmInstrumenta public static class AdviceClass { @Advice.OnMethodEnter(inline = false) - public static Span onEnter() { + public static SpanImpl onEnter() { return null; } } @@ -1020,7 +1020,7 @@ public static Object onEnter() { } @Advice.OnMethodExit(inline = false) - private static void onExit(@Advice.Enter Span span) { + private static void onExit(@Advice.Enter SpanImpl span) { } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/collections/ReferencedCountedConcurrentHashMapTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/collections/ReferencedCountedConcurrentHashMapTest.java index 4cfd423d29..8dfabb7e9e 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/collections/ReferencedCountedConcurrentHashMapTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/collections/ReferencedCountedConcurrentHashMapTest.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.collections; import co.elastic.apm.agent.MockTracer; -import co.elastic.apm.agent.impl.context.AbstractContext; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.AbstractContextImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -132,7 +132,7 @@ void execute(WeakMap map, Object key, TestSpan value) { void clear() { WeakMap map = WeakConcurrentProviderImpl.createWeakReferenceCountedMap(); - List> list = new ArrayList<>(); + List> list = new ArrayList<>(); for (int i = 0; i < 5; i++) { TestSpan span = new TestSpan(); list.add(span); @@ -153,7 +153,7 @@ void weakMapDecrementOnStaleKeyGC() { key = new Object(); TestSpan span = new TestSpan(); - WeakMap> map = WeakConcurrentProviderImpl.createWeakReferenceCountedMap(); + WeakMap> map = WeakConcurrentProviderImpl.createWeakReferenceCountedMap(); map.put(key, span); @@ -173,15 +173,15 @@ void weakMapDecrementOnStaleKeyGC() { } - private void checkRefCount(List> spans, int expected) { + private void checkRefCount(List> spans, int expected) { spans.forEach(span -> checkRefCount(span, expected)); } - private void checkRefCount(AbstractSpan span, int expected) { + private void checkRefCount(AbstractSpanImpl span, int expected) { assertThat(span.getReferenceCount()).isEqualTo(expected); } - private static class TestSpan extends AbstractSpan { + private static class TestSpan extends AbstractSpanImpl { public TestSpan() { super(MockTracer.create()); @@ -189,12 +189,12 @@ public TestSpan() { @Nullable @Override - public Transaction getParentTransaction() { + public TransactionImpl getParentTransaction() { return null; } @Override - public AbstractContext getContext() { + public AbstractContextImpl getContext() { return null; } @@ -217,7 +217,7 @@ protected void recycle() { protected TestSpan thiz() { return null; } - + } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSourceTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSourceTest.java index 1346de5bba..d1dece2a7e 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSourceTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/ApmServerConfigurationSourceTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.configuration; import co.elastic.apm.agent.impl.metadata.MetaDataMock; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import co.elastic.apm.agent.sdk.logging.Logger; @@ -77,7 +77,7 @@ public void setUp() throws Exception { apmServerClient.start(List.of(new URL("http", "localhost", mockApmServer.port(), "/"))); mockLogger = mock(Logger.class); configurationSource = new ApmServerConfigurationSource( - new DslJsonSerializer(mock(StacktraceConfiguration.class), apmServerClient, MetaDataMock.create()), + new DslJsonSerializer(mock(StacktraceConfigurationImpl.class), apmServerClient, MetaDataMock.create()), apmServerClient, mockLogger ); @@ -100,7 +100,7 @@ public void testLoadRemoteConfig() throws Exception { @Test public void testRemoteConfigDisabled() { - doReturn(false).when(config.getConfig(CoreConfiguration.class)).isCentralConfigEnabled(); + doReturn(false).when(config.getConfig(CoreConfigurationImpl.class)).isCentralConfigEnabled(); configurationSource.fetchConfig(config); assertThat(configurationSource.getValue("foo")).isNull(); mockApmServer.verify(0, postRequestedFor(urlEqualTo("/config/v1/agents"))); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/CoreConfigurationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/CoreConfigurationTest.java index a1ea6cab6c..8ba2257a4b 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/CoreConfigurationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/CoreConfigurationTest.java @@ -32,7 +32,7 @@ class CoreConfigurationTest { @Test void testWithoutDisabledAndEnabledInstrumentations() { - CoreConfiguration config = getCoreConfiguration("", ""); + CoreConfigurationImpl config = getCoreConfiguration("", ""); assertThat(config.isInstrumentationEnabled("foo")).isTrue(); assertThat(config.isInstrumentationEnabled(Collections.singletonList("foo"))).isTrue(); assertThat(config.isInstrumentationEnabled(Arrays.asList("foo", "bar"))).isTrue(); @@ -40,7 +40,7 @@ void testWithoutDisabledAndEnabledInstrumentations() { @Test void testWithDisabledInstrumentations() { - CoreConfiguration config = getCoreConfiguration("", "foo"); + CoreConfigurationImpl config = getCoreConfiguration("", "foo"); assertThat(config.isInstrumentationEnabled("foo")).isFalse(); assertThat(config.isInstrumentationEnabled("bar")).isTrue(); assertThat(config.isInstrumentationEnabled(Collections.singletonList("foo"))).isFalse(); @@ -50,7 +50,7 @@ void testWithDisabledInstrumentations() { @Test void testWithEnabledInstrumentations() { - CoreConfiguration config = getCoreConfiguration("foo", ""); + CoreConfigurationImpl config = getCoreConfiguration("foo", ""); assertThat(config.isInstrumentationEnabled("foo")).isTrue(); assertThat(config.isInstrumentationEnabled("bar")).isFalse(); assertThat(config.isInstrumentationEnabled(Collections.singletonList("foo"))).isTrue(); @@ -60,7 +60,7 @@ void testWithEnabledInstrumentations() { @Test void testWithDisabledAndEnabledInstrumentations() { - CoreConfiguration config = getCoreConfiguration("foo", "foo"); + CoreConfigurationImpl config = getCoreConfiguration("foo", "foo"); assertThat(config.isInstrumentationEnabled("foo")).isFalse(); assertThat(config.isInstrumentationEnabled("bar")).isFalse(); assertThat(config.isInstrumentationEnabled(Collections.singletonList("foo"))).isFalse(); @@ -70,20 +70,20 @@ void testWithDisabledAndEnabledInstrumentations() { @Test void testWithEnabledInstrumentationsButDisabledExperimentalInstrumentations() { - CoreConfiguration config = getCoreConfiguration("experimental", ""); + CoreConfigurationImpl config = getCoreConfiguration("experimental", ""); assertThat(config.isInstrumentationEnabled("experimental")).isFalse(); assertThat(config.isInstrumentationEnabled(Collections.singletonList("experimental"))).isFalse(); } @Test void testWithEnabledInstrumentationsAndEnabledExperimentalInstrumentations() { - CoreConfiguration config = ConfigurationRegistry.builder() - .addOptionProvider(new CoreConfiguration()) + CoreConfigurationImpl config = ConfigurationRegistry.builder() + .addOptionProvider(new CoreConfigurationImpl()) .addConfigSource(SimpleSource.forTest("enable_instrumentations", "experimental")) .addConfigSource(SimpleSource.forTest("disable_instrumentations", "")) .addConfigSource(SimpleSource.forTest("enable_experimental_instrumentations", "true")) .build() - .getConfig(CoreConfiguration.class); + .getConfig(CoreConfigurationImpl.class); assertThat(config.isInstrumentationEnabled("experimental")).isTrue(); assertThat(config.isInstrumentationEnabled(Collections.singletonList("experimental"))).isTrue(); @@ -93,30 +93,30 @@ void testWithEnabledInstrumentationsAndEnabledExperimentalInstrumentations() { @Test void testLegacyDefaultDisabledInstrumentation() { - CoreConfiguration config = getCoreConfiguration("", "incubating"); + CoreConfigurationImpl config = getCoreConfiguration("", "incubating"); assertThat(config.isInstrumentationEnabled("experimental")).isFalse(); assertThat(config.isInstrumentationEnabled(Collections.singletonList("experimental"))).isFalse(); } @Test void testPreventBroadElasticApmExclusionFromInstrumentation() { - CoreConfiguration coreConfig = ConfigurationRegistry.builder() - .addOptionProvider(new CoreConfiguration()) + CoreConfigurationImpl coreConfig = ConfigurationRegistry.builder() + .addOptionProvider(new CoreConfigurationImpl()) .addConfigSource(SimpleSource.forTest("classes_excluded_from_instrumentation", "co.elastic.apm.*, co.elastic.*, foo.bar.*")) .build() - .getConfig(CoreConfiguration.class); + .getConfig(CoreConfigurationImpl.class); assertThat(coreConfig.getClassesExcludedFromInstrumentation()) .containsExactly(WildcardMatcher.valueOf("foo.bar.*")); } - private static CoreConfiguration getCoreConfiguration(String enabledInstrumentations, String disabledInstrumentations) { + private static CoreConfigurationImpl getCoreConfiguration(String enabledInstrumentations, String disabledInstrumentations) { ConfigurationRegistry configurationRegistry = ConfigurationRegistry.builder() - .addOptionProvider(new CoreConfiguration()) + .addOptionProvider(new CoreConfigurationImpl()) .addConfigSource(SimpleSource.forTest("enable_instrumentations", enabledInstrumentations)) .addConfigSource(SimpleSource.forTest("disable_instrumentations", disabledInstrumentations)) .build(); - return configurationRegistry.getConfig(CoreConfiguration.class); + return configurationRegistry.getConfig(CoreConfigurationImpl.class); } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/StartupInfoTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/StartupInfoTest.java index aed7cba9db..e099f8e0d2 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/StartupInfoTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/configuration/StartupInfoTest.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.tracer.configuration.TimeDuration; import co.elastic.apm.agent.tracer.configuration.TimeDurationValueConverter; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.logging.LoggingConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.logging.LoggingConfigurationImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import co.elastic.apm.agent.sdk.logging.Logger; @@ -45,13 +45,13 @@ class StartupInfoTest { @BeforeEach void setUp() { - LoggingConfiguration.init(List.of(), ""); + LoggingConfigurationImpl.init(List.of(), ""); config = new TestConfig(); this.configurationRegistry = ConfigurationRegistry.builder() .addOptionProvider(config) - .addOptionProvider(new CoreConfiguration()) - .addOptionProvider(new StacktraceConfiguration()) + .addOptionProvider(new CoreConfigurationImpl()) + .addOptionProvider(new StacktraceConfigurationImpl()) .addConfigSource(new SimpleSource().add("duration", "1")) .build(); startupInfo = new StartupInfo(); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/DiscardSpanTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/DiscardSpanTest.java index f646f480e5..5099a0dce7 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/DiscardSpanTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/DiscardSpanTest.java @@ -20,9 +20,9 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -50,10 +50,10 @@ void cleanupAndCheck() { @Test void testContextPropagatingSpansAreNonDiscardable() { - Transaction transaction = tracer.startRootTransaction(null); + TransactionImpl transaction = tracer.startRootTransaction(null); assertThat(transaction).isNotNull(); try { - Span span = transaction.createSpan().requestDiscarding(); + SpanImpl span = transaction.createSpan().requestDiscarding(); try { span.propagateContext(new HashMap<>(), TextHeaderMapAccessor.INSTANCE, null); assertThat(span.isDiscardable()).isFalse(); @@ -71,10 +71,10 @@ void testContextPropagatingSpansAreNonDiscardable() { @Test void testErrorCapturingMakesSpansNonDiscardable() { - Transaction transaction = tracer.startRootTransaction(null); + TransactionImpl transaction = tracer.startRootTransaction(null); assertThat(transaction).isNotNull(); try { - Span span = transaction.createSpan(); + SpanImpl span = transaction.createSpan(); try { span.requestDiscarding().appendToName("non-discardable").captureException(new Exception()); assertThat(span.isDiscardable()).isFalse(); @@ -84,7 +84,7 @@ void testErrorCapturingMakesSpansNonDiscardable() { } finally { transaction.end(); } - assertThat(reporter.getSpans().stream().map(Span::getNameAsString)).containsExactly("non-discardable"); + assertThat(reporter.getSpans().stream().map(SpanImpl::getNameAsString)).containsExactly("non-discardable"); assertThat(transaction.getSpanCount().getTotal()).hasValue(1); assertThat(transaction.getSpanCount().getDropped()).hasValue(0); @@ -93,12 +93,12 @@ void testErrorCapturingMakesSpansNonDiscardable() { @Test void testParentsOfContextPropagatingSpansAreNonDiscardable() { - Transaction transaction = tracer.startRootTransaction(null); + TransactionImpl transaction = tracer.startRootTransaction(null); assertThat(transaction).isNotNull(); try { - Span parentSpan = transaction.createSpan().requestDiscarding(); + SpanImpl parentSpan = transaction.createSpan().requestDiscarding(); try { - Span contextPropagatingSpan = parentSpan.createSpan(); + SpanImpl contextPropagatingSpan = parentSpan.createSpan(); try { contextPropagatingSpan.propagateContext(new HashMap<>(), TextHeaderMapAccessor.INSTANCE, null); assertThat(contextPropagatingSpan.isDiscardable()).isFalse(); @@ -120,8 +120,8 @@ void testParentsOfContextPropagatingSpansAreNonDiscardable() { @Test void testDiscardSpanLimit() { - doReturn(2).when(tracer.getConfigurationRegistry().getConfig(CoreConfiguration.class)).getTransactionMaxSpans(); - Transaction transaction = tracer.startRootTransaction(null); + doReturn(2).when(tracer.getConfigurationRegistry().getConfig(CoreConfigurationImpl.class)).getTransactionMaxSpans(); + TransactionImpl transaction = tracer.startRootTransaction(null); assertThat(transaction).isNotNull(); try { transaction.createSpan().appendToName("1st").end(); @@ -131,7 +131,7 @@ void testDiscardSpanLimit() { } finally { transaction.end(); } - assertThat(reporter.getSpans().stream().map(Span::getNameAsString)).containsExactly("1st", "2nd"); + assertThat(reporter.getSpans().stream().map(SpanImpl::getNameAsString)).containsExactly("1st", "2nd"); assertThat(transaction.getSpanCount().getTotal()).hasValue(4); assertThat(transaction.getSpanCount().getDropped()).hasValue(2); assertThat(transaction.getSpanCount().getReported()).hasValue(2); @@ -139,13 +139,13 @@ void testDiscardSpanLimit() { @Test void testDiscardSpanLimitNesting() { - doReturn(2).when(tracer.getConfigurationRegistry().getConfig(CoreConfiguration.class)).getTransactionMaxSpans(); - Transaction transaction = tracer.startRootTransaction(null); + doReturn(2).when(tracer.getConfigurationRegistry().getConfig(CoreConfigurationImpl.class)).getTransactionMaxSpans(); + TransactionImpl transaction = tracer.startRootTransaction(null); assertThat(transaction).isNotNull(); try { - Span first = transaction.createSpan().appendToName("1st"); + SpanImpl first = transaction.createSpan().appendToName("1st"); try { - Span second = first.createSpan().appendToName("2nd"); + SpanImpl second = first.createSpan().appendToName("2nd"); try { second.createSpan().appendToName("exceeds limit").end(); } finally { @@ -157,7 +157,7 @@ void testDiscardSpanLimitNesting() { } finally { transaction.end(); } - assertThat(reporter.getSpans().stream().map(Span::getNameAsString)).containsExactly("2nd", "1st"); + assertThat(reporter.getSpans().stream().map(SpanImpl::getNameAsString)).containsExactly("2nd", "1st"); assertThat(transaction.getSpanCount().getTotal()).hasValue(3); assertThat(transaction.getSpanCount().getDropped()).hasValue(1); assertThat(transaction.getSpanCount().getReported()).hasValue(2); @@ -165,15 +165,15 @@ void testDiscardSpanLimitNesting() { @Test void testDiscardSpanLimitNesting2() { - doReturn(2).when(tracer.getConfigurationRegistry().getConfig(CoreConfiguration.class)).getTransactionMaxSpans(); - Transaction transaction = tracer.startRootTransaction(null); + doReturn(2).when(tracer.getConfigurationRegistry().getConfig(CoreConfigurationImpl.class)).getTransactionMaxSpans(); + TransactionImpl transaction = tracer.startRootTransaction(null); assertThat(transaction).isNotNull(); try { - Span first = transaction.createSpan().appendToName("1st"); + SpanImpl first = transaction.createSpan().appendToName("1st"); try { - Span second = first.createSpan().requestDiscarding().appendToName("discarded 1"); + SpanImpl second = first.createSpan().requestDiscarding().appendToName("discarded 1"); try { - Span exceedsLimit1 = second.createSpan().requestDiscarding().appendToName("exceeds limit 1"); + SpanImpl exceedsLimit1 = second.createSpan().requestDiscarding().appendToName("exceeds limit 1"); try { assertThat(exceedsLimit1.isSampled()).isFalse(); } finally { @@ -191,7 +191,7 @@ void testDiscardSpanLimitNesting2() { } finally { transaction.end(); } - assertThat(reporter.getSpans().stream().map(Span::getNameAsString)).containsExactly("1st", "2nd"); + assertThat(reporter.getSpans().stream().map(SpanImpl::getNameAsString)).containsExactly("1st", "2nd"); assertThat(transaction.getSpanCount().getTotal()).hasValue(5); assertThat(transaction.getSpanCount().getDropped()).hasValue(3); assertThat(transaction.getSpanCount().getReported()).hasValue(2); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilderTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilderTest.java index 137fec21e1..2400286107 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilderTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerBuilderTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -36,22 +36,22 @@ class ElasticApmTracerBuilderTest { @AfterEach void tearDown() { - System.clearProperty("elastic.apm." + CoreConfiguration.CONFIG_FILE); + System.clearProperty("elastic.apm." + CoreConfigurationImpl.CONFIG_FILE); } @Test void testConfigFileLocation(@TempDir Path tempDir) throws IOException { Path file = Files.createFile(tempDir.resolve("elastic-apm-test.properties")); Files.write(file, List.of("instrument=false")); - System.setProperty("elastic.apm." + CoreConfiguration.CONFIG_FILE, file.toString()); + System.setProperty("elastic.apm." + CoreConfigurationImpl.CONFIG_FILE, file.toString()); ConfigurationRegistry configurationRegistry = new ElasticApmTracerBuilder().build().getConfigurationRegistry(); - CoreConfiguration config = configurationRegistry.getConfig(CoreConfiguration.class); + CoreConfigurationImpl config = configurationRegistry.getConfig(CoreConfigurationImpl.class); // tests that changing non-dynamic properties also works assertThat(config.isInstrument()).isFalse(); - configurationRegistry.getString(CoreConfiguration.CONFIG_FILE); - assertThat(configurationRegistry.getString(CoreConfiguration.CONFIG_FILE)).isEqualTo(file.toString()); + configurationRegistry.getString(CoreConfigurationImpl.CONFIG_FILE); + assertThat(configurationRegistry.getString(CoreConfigurationImpl.CONFIG_FILE)).isEqualTo(file.toString()); } @Test @@ -62,7 +62,7 @@ void testTempAttacherPropertiesFile(@TempDir Path tempDir) throws Exception { List configSources = ElasticApmTracerBuilder.getConfigSources("c=" + file.toAbsolutePath(), false); ConfigurationRegistry configurationRegistry = new ElasticApmTracerBuilder(configSources).build().getConfigurationRegistry(); - CoreConfiguration config = configurationRegistry.getConfig(CoreConfiguration.class); + CoreConfigurationImpl config = configurationRegistry.getConfig(CoreConfigurationImpl.class); assertThat(config.isInstrument()).isFalse(); } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerShutdownTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerShutdownTest.java index f0f71f165c..385900e4aa 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerShutdownTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerShutdownTest.java @@ -53,10 +53,10 @@ void testUsingSharedPoolOnShutdown() { @Test void testTracerStateIsRunningInTaskSubmittedInShutdownHook() { - AtomicReference tracerStateInShutdownHook = new AtomicReference<>(); + AtomicReference tracerStateInShutdownHook = new AtomicReference<>(); tracerImpl.addShutdownHook(() -> tracerImpl.getSharedSingleThreadedPool().submit(() -> tracerStateInShutdownHook.set(tracerImpl.getState()))); tracerImpl.stop(); reporter.awaitUntilAsserted(() -> assertThat(tracerStateInShutdownHook.get()).isNotNull()); - assertThat(tracerStateInShutdownHook.get()).isEqualTo(Tracer.TracerState.RUNNING); + assertThat(tracerStateInShutdownHook.get()).isEqualTo(ElasticApmTracer.TracerState.RUNNING); } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java index 6ef0970c47..3dc3775f92 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/ElasticApmTracerTest.java @@ -21,20 +21,17 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.configuration.AutoDetectedServiceInfo; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.*; import co.elastic.apm.agent.impl.baggage.BaggageContext; import co.elastic.apm.agent.tracer.service.ServiceInfo; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.configuration.source.ConfigSources; -import co.elastic.apm.agent.impl.baggage.Baggage; -import co.elastic.apm.agent.impl.error.ErrorCapture; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.impl.sampling.ConstantSampler; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import co.elastic.apm.agent.report.ApmServerClient; @@ -110,10 +107,10 @@ void cleanupAndCheck() { @Test void testThreadLocalStorage() { - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try (Scope scope = transaction.activateInScope()) { assertThat(tracerImpl.currentTransaction()).isSameAs(transaction); - Span span = tracerImpl.getActive().createSpan(); + SpanImpl span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { assertThat(tracerImpl.currentTransaction()).isSameAs(transaction); assertThat(tracerImpl.getActive()).isSameAs(span); @@ -128,14 +125,14 @@ void testThreadLocalStorage() { @Test void testNestedSpan() { - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try (Scope scope = transaction.activateInScope()) { assertThat(tracerImpl.currentTransaction()).isSameAs(transaction); - Span span = tracerImpl.getActive().createSpan(); + SpanImpl span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { assertThat(tracerImpl.getActive()).isSameAs(span); assertThat(span.isChildOf(transaction)).isTrue(); - Span nestedSpan = tracerImpl.getActive().createSpan(); + SpanImpl nestedSpan = tracerImpl.getActive().createSpan(); try (Scope nestedSpanScope = nestedSpan.activateInScope()) { assertThat(tracerImpl.getActive()).isSameAs(nestedSpan); assertThat(nestedSpan.isChildOf(span)).isTrue(); @@ -152,11 +149,11 @@ void testNestedSpan() { @Test void testDisableStacktraces() { - doReturn(-1L).when(tracerImpl.getConfig(StacktraceConfiguration.class)).getSpanStackTraceMinDurationMs(); + doReturn(-1L).when(tracerImpl.getConfig(StacktraceConfigurationImpl.class)).getSpanStackTraceMinDurationMs(); - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try (Scope scope = transaction.activateInScope()) { - Span span = tracerImpl.getActive().createSpan(); + SpanImpl span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { span.end(); } @@ -167,10 +164,10 @@ void testDisableStacktraces() { @Test void testEnableStacktraces() throws InterruptedException { - doReturn(0L).when(tracerImpl.getConfig(StacktraceConfiguration.class)).getSpanStackTraceMinDurationMs(); - Transaction transaction = startTestRootTransaction(); + doReturn(0L).when(tracerImpl.getConfig(StacktraceConfigurationImpl.class)).getSpanStackTraceMinDurationMs(); + TransactionImpl transaction = startTestRootTransaction(); try (Scope scope = transaction.activateInScope()) { - Span span = tracerImpl.getActive().createSpan(); + SpanImpl span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { Thread.sleep(10); stackTraceEndSpan(span); @@ -184,17 +181,17 @@ void testEnableStacktraces() throws InterruptedException { && stackTraceElement.getClassName().equals(ElasticApmTracerTest.class.getName()))).hasSize(1); } - private static void stackTraceEndSpan(Span span) { + private static void stackTraceEndSpan(SpanImpl span) { // dummy method used just to verify that the captured stack trace contains it span.end(); } @Test void testDisableStacktracesForFastSpans() { - doReturn(100L).when(tracerImpl.getConfig(StacktraceConfiguration.class)).getSpanStackTraceMinDurationMs(); - Transaction transaction = startTestRootTransaction(); + doReturn(100L).when(tracerImpl.getConfig(StacktraceConfigurationImpl.class)).getSpanStackTraceMinDurationMs(); + TransactionImpl transaction = startTestRootTransaction(); try (Scope scope = transaction.activateInScope()) { - Span span = tracerImpl.getActive().createSpan(); + SpanImpl span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { span.end(); } @@ -206,10 +203,10 @@ void testDisableStacktracesForFastSpans() { @Test void testEnableStacktracesForSlowSpans() throws InterruptedException { - doReturn(1L).when(tracerImpl.getConfig(StacktraceConfiguration.class)).getSpanStackTraceMinDurationMs(); - Transaction transaction = startTestRootTransaction(); + doReturn(1L).when(tracerImpl.getConfig(StacktraceConfigurationImpl.class)).getSpanStackTraceMinDurationMs(); + TransactionImpl transaction = startTestRootTransaction(); try (Scope scope = transaction.activateInScope()) { - Span span = tracerImpl.getActive().createSpan(); + SpanImpl span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { Thread.sleep(10); span.end(); @@ -220,7 +217,7 @@ void testEnableStacktracesForSlowSpans() throws InterruptedException { } @Nullable - private Transaction startTestRootTransaction() { + private TransactionImpl startTestRootTransaction() { return tracerImpl.startRootTransaction(getClass().getClassLoader()); } @@ -228,7 +225,7 @@ private Transaction startTestRootTransaction() { void testRecordException() { tracerImpl.captureAndReportException(new Exception("test"), getClass().getClassLoader()); assertThat(reporter.getErrors()).hasSize(1); - ErrorCapture error = reporter.getFirstError(); + ErrorCaptureImpl error = reporter.getFirstError(); assertThat(error.getException()).isNotNull(); assertThat(error.getTraceContext().hasContent()).isTrue(); assertThat(error.getTraceContext().getTraceId().isEmpty()).isTrue(); @@ -243,7 +240,7 @@ void testDoesNotRecordIgnoredExceptions() { .map(WildcardMatcher::valueOf) .collect(Collectors.toList()); - doReturn(wildcardList).when(config.getConfig(CoreConfiguration.class)).getIgnoreExceptions(); + doReturn(wildcardList).when(config.getConfig(CoreConfigurationImpl.class)).getIgnoreExceptions(); tracerImpl.captureAndReportException(new DummyException1(), getClass().getClassLoader()); tracerImpl.captureAndReportException(new DummyException2(), getClass().getClassLoader()); @@ -252,9 +249,9 @@ void testDoesNotRecordIgnoredExceptions() { @Test void testTransactionNameGrouping() { - doReturn(List.of(WildcardMatcher.valueOf("GET /foo/*/bar"))).when(config.getConfig(CoreConfiguration.class)).getTransactionNameGroups(); + doReturn(List.of(WildcardMatcher.valueOf("GET /foo/*/bar"))).when(config.getConfig(CoreConfigurationImpl.class)).getTransactionNameGroups(); - Transaction transaction = tracerImpl.startRootTransaction(null).appendToName("GET ").appendToName("/foo/42/bar"); + TransactionImpl transaction = tracerImpl.startRootTransaction(null).appendToName("GET ").appendToName("/foo/42/bar"); try (Scope scope = transaction.activateInScope()) { transaction.captureException(new RuntimeException("Test error capturing")); } @@ -292,7 +289,7 @@ void testRecordExceptionWithTraceNotSampled() { } private void innerRecordExceptionWithTrace(boolean sampled) { - Transaction transaction = tracerImpl.startRootTransaction(ConstantSampler.of(sampled), -1, null); + TransactionImpl transaction = tracerImpl.startRootTransaction(ConstantSampler.of(sampled), -1, null); transaction.withType("request"); try (Scope scope = transaction.activateInScope()) { transaction.getContext().getRequest() @@ -302,10 +299,10 @@ private void innerRecordExceptionWithTrace(boolean sampled) { .withPathname("/foo"); tracerImpl.currentTransaction().captureException(new Exception("from transaction")); - Span span = transaction.createSpan().activate(); + SpanImpl span = transaction.createSpan().activate(); span.captureException(new Exception("from span")); - List errors = reporter.getErrors(); + List errors = reporter.getErrors(); assertThat(errors).hasSize(2); // 1st one is from transaction @@ -320,12 +317,12 @@ private void innerRecordExceptionWithTrace(boolean sampled) { transaction.end(); } - private ErrorCapture validateSingleError(AbstractSpan span, boolean sampled, Transaction correspondingTransaction) { + private ErrorCaptureImpl validateSingleError(AbstractSpanImpl span, boolean sampled, TransactionImpl correspondingTransaction) { assertThat(reporter.getErrors()).hasSize(1); return validateError(reporter.getFirstError(), span, sampled, correspondingTransaction); } - private ErrorCapture validateError(ErrorCapture error, AbstractSpan span, boolean sampled, Transaction transaction) { + private ErrorCaptureImpl validateError(ErrorCaptureImpl error, AbstractSpanImpl span, boolean sampled, TransactionImpl transaction) { assertThat(error.getTraceContext().isChildOf(span.getTraceContext())) .describedAs("error trace context [%s] should be a child of span trace context [%s]", error.getTraceContext(), span.getTraceContext()) .isTrue(); @@ -340,17 +337,17 @@ private ErrorCapture validateError(ErrorCapture error, AbstractSpan span, boo @Test void testEnableDropSpans() { setupWithCustomConfig(conf -> { - doReturn(1).when(conf.getConfig(CoreConfiguration.class)).getTransactionMaxSpans(); + doReturn(1).when(config.getConfig(CoreConfigurationImpl.class)).getTransactionMaxSpans(); }); - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try (Scope scope = transaction.activateInScope()) { - Span span = tracerImpl.getActive().createSpan(); + SpanImpl span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { assertThat(tracerImpl.getActive()).isSameAs(span); //ensure ActiveStack limit is not reached assertThat(span.isSampled()).isTrue(); span.end(); } - Span span2 = tracerImpl.getActive().createSpan(); + SpanImpl span2 = tracerImpl.getActive().createSpan(); try (Scope spanScope = span2.activateInScope()) { assertThat(span2.isSampled()).isFalse(); span2.end(); @@ -366,7 +363,7 @@ void testEnableDropSpans() { @Test void testActivationStackOverflow() { - doReturn(2).when(config.getConfig(CoreConfiguration.class)).getTransactionMaxSpans(); + doReturn(2).when(config.getConfig(CoreConfigurationImpl.class)).getTransactionMaxSpans(); ElasticApmTracer tracer = new ElasticApmTracerBuilder() .configurationRegistry(config) @@ -376,18 +373,18 @@ void testActivationStackOverflow() { .buildAndStart(); doWithNestedBaggageActivations(() -> { - Transaction transaction = tracer.startRootTransaction(getClass().getClassLoader()); + TransactionImpl transaction = tracer.startRootTransaction(getClass().getClassLoader()); assertThat(tracer.getActive()).isNull(); try (Scope scope = transaction.activateInScope()) { assertThat(tracer.getActive()).isEqualTo(transaction); - Span child1 = transaction.createSpan(); + SpanImpl child1 = transaction.createSpan(); try (Scope childScope = child1.activateInScope()) { assertThat(tracer.getActive()).isEqualTo(child1); - Span grandchild1 = child1.createSpan(); + SpanImpl grandchild1 = child1.createSpan(); try (Scope grandchildScope = grandchild1.activateInScope()) { // latter activation should not be applied due to activation stack overflow assertThat(tracer.getActive()).isEqualTo(child1); - Span ggc = grandchild1.createSpan(); + SpanImpl ggc = grandchild1.createSpan(); try (Scope ggcScope = ggc.activateInScope()) { assertThat(tracer.getActive()).isEqualTo(child1); ggc.end(); @@ -398,10 +395,10 @@ void testActivationStackOverflow() { child1.end(); } assertThat(tracer.getActive()).isEqualTo(transaction); - Span child2 = transaction.createSpan(); + SpanImpl child2 = transaction.createSpan(); try (Scope childScope = child2.activateInScope()) { assertThat(tracer.getActive()).isEqualTo(child2); - Span grandchild2 = child2.createSpan(); + SpanImpl grandchild2 = child2.createSpan(); try (Scope grandchildScope = grandchild2.activateInScope()) { // latter activation should not be applied due to activation stack overflow assertThat(tracer.getActive()).isEqualTo(child2); @@ -419,7 +416,7 @@ void testActivationStackOverflow() { assertThat(reporter.getSpans()).hasSize(2); } - private void doWithNestedBaggageActivations(Runnable r, Tracer tracer, int nestedCount) { + private void doWithNestedBaggageActivations(Runnable r, ElasticApmTracer tracer, int nestedCount) { if (nestedCount == 0) { r.run(); return; @@ -438,11 +435,11 @@ void testPause() { @Test void testPauseMidTransaction() { - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try (Scope scope = transaction.activateInScope()) { assertThat(tracerImpl.currentTransaction()).isSameAs(transaction); tracerImpl.pause(); - Span span = tracerImpl.getActive().createSpan(); + SpanImpl span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { span.withName("test"); assertThat(span.getNameAsString()).isEqualTo("test"); @@ -450,7 +447,7 @@ void testPauseMidTransaction() { assertThat(span.isChildOf(transaction)).isTrue(); span.end(); } - Span span2 = tracerImpl.getActive().createSpan(); + SpanImpl span2 = tracerImpl.getActive().createSpan(); try (Scope spanScope = span2.activateInScope()) { span2.withName("test2"); assertThat(span2.getNameAsString()).isEqualTo("test2"); @@ -480,12 +477,12 @@ void testSamplingNone_dropUnsampled() throws IOException { void testSamplingNone(boolean keepUnsampled) throws IOException { - config.getConfig(CoreConfiguration.class).getSampleRate().update(0.0, SpyConfiguration.CONFIG_SOURCE_NAME); - Transaction transaction = startTestRootTransaction().withType("request"); + config.getConfig(CoreConfigurationImpl.class).getSampleRate().update(0.0, SpyConfiguration.CONFIG_SOURCE_NAME); + TransactionImpl transaction = startTestRootTransaction().withType("request"); try (Scope scope = transaction.activateInScope()) { transaction.setUser("1", "jon.doe@example.com", "jondoe", "domain"); - Span span = tracerImpl.getActive().createSpan(); + SpanImpl span = tracerImpl.getActive().createSpan(); try (Scope spanScope = span.activateInScope()) { span.end(); } @@ -519,8 +516,8 @@ void testSamplingNone(boolean keepUnsampled) throws IOException { @Test void testTransactionWithParentReference() { - final Map headerMap = Map.of(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); - final Transaction transaction = tracerImpl.startChildTransaction(headerMap, TextHeaderMapAccessor.INSTANCE, ConstantSampler.of(false), 0, null); + final Map headerMap = Map.of(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); + final TransactionImpl transaction = tracerImpl.startChildTransaction(headerMap, TextHeaderMapAccessor.INSTANCE, ConstantSampler.of(false), 0, null); // the traced flag in the header overrides the sampler assertThat(transaction.isSampled()).isTrue(); assertThat(transaction.getTraceContext().getParentId().toString()).isEqualTo("b9c7c989f97918e1"); @@ -532,8 +529,8 @@ void testTransactionWithParentReference() { @Test void testTimestamps() { - final Transaction transaction = tracerImpl.startChildTransaction(new HashMap<>(), TextHeaderMapAccessor.INSTANCE, ConstantSampler.of(true), 0, null); - final Span span = transaction.createSpan(10); + final TransactionImpl transaction = tracerImpl.startChildTransaction(new HashMap<>(), TextHeaderMapAccessor.INSTANCE, ConstantSampler.of(true), 0, null); + final SpanImpl span = transaction.createSpan(10); span.end(20); transaction.end(30); @@ -546,8 +543,8 @@ void testTimestamps() { @Test void testTimestampSanitization() { - final Transaction transaction = tracerImpl.startChildTransaction(new HashMap<>(), TextHeaderMapAccessor.INSTANCE, ConstantSampler.of(true), 10, null); - final Span span = transaction.createSpan(20); + final TransactionImpl transaction = tracerImpl.startChildTransaction(new HashMap<>(), TextHeaderMapAccessor.INSTANCE, ConstantSampler.of(true), 10, null); + final SpanImpl span = transaction.createSpan(20); span.end(10); transaction.end(5); @@ -560,7 +557,7 @@ void testTimestampSanitization() { @Test void testStartSpanAfterTransactionHasEnded() { - final Transaction transaction = startTestRootTransaction(); + final TransactionImpl transaction = startTestRootTransaction(); assertThat(transaction).isNotNull(); transaction.incrementReferences(); transaction.end(); @@ -568,7 +565,7 @@ void testStartSpanAfterTransactionHasEnded() { try (Scope transactionScope = transaction.activateInScope()) { assertThat(tracerImpl.getActive()).isEqualTo(transaction); - final Span span = tracerImpl.startSpan(transaction, Baggage.EMPTY, -1); + final SpanImpl span = tracerImpl.startSpan(transaction, BaggageImpl.EMPTY, -1); assertThat(span).isNotNull(); try (Scope scope = span.activateInScope()) { assertThat(tracerImpl.currentTransaction()).isNotNull(); @@ -584,7 +581,7 @@ void testStartSpanAfterTransactionHasEnded() { @Test void testActivateDeactivateTwice() { - final Transaction transaction = startTestRootTransaction(); + final TransactionImpl transaction = startTestRootTransaction(); assertThat(tracerImpl.currentTransaction()).isNull(); tracerImpl.activate(transaction); assertThat(tracerImpl.currentTransaction()).isEqualTo(transaction); @@ -601,12 +598,12 @@ void testActivateDeactivateTwice() { @Test void testEmptyContextActivation() { - final Transaction transaction = startTestRootTransaction(); + final TransactionImpl transaction = startTestRootTransaction(); assertThat(tracerImpl.currentContext().getTransaction()).isNull(); tracerImpl.activate(transaction); assertThat(tracerImpl.currentContext().getTransaction()).isEqualTo(transaction); - EmptyElasticContext empty = new EmptyElasticContext(tracerImpl); + EmptyTraceState empty = new EmptyTraceState(tracerImpl); empty.activate(); assertThat(tracerImpl.currentContext().getTransaction()).isNull(); @@ -671,7 +668,7 @@ void testNotOverrideServiceNameWhenDefaultServiceNameConfigured() { startTestRootTransaction().end(); - CoreConfiguration coreConfig = localConfig.getConfig(CoreConfiguration.class); + CoreConfigurationImpl coreConfig = localConfig.getConfig(CoreConfigurationImpl.class); assertThat(AutoDetectedServiceInfo.autoDetect(System.getProperties(), System.getenv())) .isEqualTo(ServiceInfo.of(coreConfig.getServiceName())); @@ -684,8 +681,8 @@ void testNotOverrideServiceNameWhenDefaultServiceNameConfigured() { } } - private static void checkServiceInfo(Transaction transaction, ServiceInfo expected) { - TraceContext traceContext = transaction.getTraceContext(); + private static void checkServiceInfo(TransactionImpl transaction, ServiceInfo expected) { + TraceContextImpl traceContext = transaction.getTraceContext(); assertThat(traceContext.getServiceName()).isEqualTo(expected.getServiceName()); assertThat(traceContext.getServiceVersion()).isEqualTo(expected.getServiceVersion()); } @@ -724,33 +721,33 @@ void testNotOverrideServiceVersionWhenServiceVersionConfigured() { @Test void testCaptureExceptionAndGetErrorId() { - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); String errorId = transaction.captureExceptionAndGetErrorId(new Exception("test")); transaction.end(); assertThat(transaction.getOutcome()).isEqualTo(Outcome.FAILURE); assertThat(reporter.getErrors()).hasSize(1); assertThat(errorId).isNotNull(); - ErrorCapture error = reporter.getFirstError(); + ErrorCaptureImpl error = reporter.getFirstError(); assertThat(error.getTraceContext().getId().toString()).isEqualTo(errorId); } @Test void testCaptureExceptionWithTransactionName() { - Transaction transaction = startTestRootTransaction().withName("My Transaction"); + TransactionImpl transaction = startTestRootTransaction().withName("My Transaction"); try (Scope scope = transaction.activateInScope()) { transaction.captureException(new Exception("test")); transaction.end(); } assertThat(reporter.getErrors()).hasSize(1); - ErrorCapture error = reporter.getFirstError(); + ErrorCaptureImpl error = reporter.getFirstError(); assertThat(error.getTransactionInfo().getName().toString()).isEqualTo("My Transaction"); } @Test void testContextWrapping() { - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try (Scope scope = transaction.activateInScope()) { assertThat(tracerImpl.currentContext()) @@ -785,7 +782,7 @@ void testUnknownConfiguration() { } - private static final class TestContext extends ElasticContext { + private static final class TestContext extends TraceStateImpl { private TestContext() { super(null); @@ -793,12 +790,12 @@ private TestContext() { @Nullable @Override - public AbstractSpan getSpan() { + public AbstractSpanImpl getSpan() { return null; } @Override - public Baggage getBaggage() { + public BaggageImpl getBaggage() { return null; } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/LifecycleTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/LifecycleTest.java index ddf693bd5e..36ed3365f9 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/LifecycleTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/LifecycleTest.java @@ -34,9 +34,9 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import static co.elastic.apm.agent.impl.Tracer.TracerState.PAUSED; -import static co.elastic.apm.agent.impl.Tracer.TracerState.RUNNING; -import static co.elastic.apm.agent.impl.Tracer.TracerState.STOPPED; +import static co.elastic.apm.agent.impl.ElasticApmTracer.TracerState.PAUSED; +import static co.elastic.apm.agent.impl.ElasticApmTracer.TracerState.RUNNING; +import static co.elastic.apm.agent.impl.ElasticApmTracer.TracerState.STOPPED; import static org.assertj.core.api.Assertions.assertThat; public class LifecycleTest { diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/SpanTypeBreakdownTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/SpanTypeBreakdownTest.java index d8147bdf33..b8892047db 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/SpanTypeBreakdownTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/SpanTypeBreakdownTest.java @@ -20,12 +20,12 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.sampling.ConstantSampler; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricSet; import co.elastic.apm.agent.metrics.Timer; @@ -78,7 +78,7 @@ void testBreakdown_noSpans() { */ @Test void testBreakdown_disabled() { - doReturn(false).when(tracer.getConfig(CoreConfiguration.class)).isBreakdownMetricsEnabled(); + doReturn(false).when(tracer.getConfig(CoreConfigurationImpl.class)).isBreakdownMetricsEnabled(); createTransaction() .end(30); tracer.getMetricRegistry().flipPhaseAndReport(metricSets -> { @@ -94,7 +94,7 @@ void testBreakdown_disabled() { */ @Test void testBreakdown_singleDbSpan() { - final Transaction transaction = createTransaction(); + final TransactionImpl transaction = createTransaction(); transaction.createSpan(10).withType("db").withSubtype("mysql").end(20); transaction.end(30); @@ -114,7 +114,7 @@ void testBreakdown_singleDbSpan() { @Test void testBreakdown_singleDbSpan_breakdownMetricsDisabled() { tracer = MockTracer.createRealTracer(reporter, SpyConfiguration.createSpyConfig(SimpleSource.forTest("disable_metrics", "span.self_time"))); - final Transaction transaction = createTransaction(); + final TransactionImpl transaction = createTransaction(); transaction.createSpan(10).withType("db").withSubtype("mysql").end(20); transaction.end(30); @@ -132,7 +132,7 @@ void testBreakdown_singleDbSpan_breakdownMetricsDisabled() { */ @Test void testBreakdown_singleAppSpan() { - final Transaction transaction = createTransaction(); + final TransactionImpl transaction = createTransaction(); transaction.createSpan(10).withType("app").end(20); transaction.end(30); @@ -150,9 +150,9 @@ void testBreakdown_singleAppSpan() { */ @Test void testBreakdown_concurrentDbSpans_fullyOverlapping() { - final Transaction transaction = createTransaction(); - final Span span1 = transaction.createSpan(10).withType("db").withSubtype("mysql"); - final Span span2 = transaction.createSpan(10).withType("db").withSubtype("mysql"); + final TransactionImpl transaction = createTransaction(); + final SpanImpl span1 = transaction.createSpan(10).withType("db").withSubtype("mysql"); + final SpanImpl span2 = transaction.createSpan(10).withType("db").withSubtype("mysql"); span1.end(20); span2.end(20); transaction.end(30); @@ -173,9 +173,9 @@ void testBreakdown_concurrentDbSpans_fullyOverlapping() { */ @Test void testBreakdown_concurrentDbSpans_partiallyOverlapping() { - final Transaction transaction = createTransaction(); - final Span span1 = transaction.createSpan(10).withType("db").withSubtype("mysql"); - final Span span2 = transaction.createSpan(15).withType("db").withSubtype("mysql"); + final TransactionImpl transaction = createTransaction(); + final SpanImpl span1 = transaction.createSpan(10).withType("db").withSubtype("mysql"); + final SpanImpl span2 = transaction.createSpan(15).withType("db").withSubtype("mysql"); span1.end(20); span2.end(25); transaction.end(30); @@ -196,7 +196,7 @@ void testBreakdown_concurrentDbSpans_partiallyOverlapping() { */ @Test void testBreakdown_serialDbSpans_notOverlapping_withoutGap() { - final Transaction transaction = createTransaction(); + final TransactionImpl transaction = createTransaction(); transaction.createSpan(5).withType("db").withSubtype("mysql").end(15); transaction.createSpan(15).withType("db").withSubtype("mysql").end(25); transaction.end(30); @@ -217,7 +217,7 @@ void testBreakdown_serialDbSpans_notOverlapping_withoutGap() { */ @Test void testBreakdown_serialDbSpans_notOverlapping_withGap() { - final Transaction transaction = createTransaction(); + final TransactionImpl transaction = createTransaction(); transaction.createSpan(10).withType("db").withSubtype("mysql").end(15); transaction.createSpan(20).withType("db").withSubtype("redis").end(25); transaction.end(30); @@ -240,9 +240,9 @@ void testBreakdown_serialDbSpans_notOverlapping_withGap() { */ @Test void testBreakdown_asyncGrandchildExceedsChild() { - final Transaction transaction = createTransaction(); - final Span app = transaction.createSpan(10).withType("app"); - final Span db = app.createSpan(15).withType("db").withSubtype("mysql"); + final TransactionImpl transaction = createTransaction(); + final SpanImpl app = transaction.createSpan(10).withType("app"); + final SpanImpl db = app.createSpan(15).withType("db").withSubtype("mysql"); app.end(20); db.end(25); transaction.end(30); @@ -266,11 +266,11 @@ void testBreakdown_asyncGrandchildExceedsChild() { */ @Test void testBreakdown_asyncGrandchildExceedsChildAndTransaction() { - final Transaction transaction = createTransaction(); - final Span app = transaction.createSpan(10).withType("app"); + final TransactionImpl transaction = createTransaction(); + final SpanImpl app = transaction.createSpan(10).withType("app"); transaction.end(20); reporter.decrementReferences(); - final Span db = app.createSpan(20).withType("db").withSubtype("mysql"); + final SpanImpl db = app.createSpan(20).withType("db").withSubtype("mysql"); app.end(30); db.end(30); @@ -300,8 +300,8 @@ void testBreakdown_asyncGrandchildExceedsChildAndTransaction() { */ @Test void testBreakdown_singleDbSpan_exceedingParent() { - final Transaction transaction = createTransaction(); - final Span span = transaction.createSpan(10).withType("db").withSubtype("mysql"); + final TransactionImpl transaction = createTransaction(); + final SpanImpl span = transaction.createSpan(10).withType("db").withSubtype("mysql"); transaction.end(20); span.end(30); @@ -326,11 +326,11 @@ void testBreakdown_singleDbSpan_exceedingParent() { */ @Test void testBreakdown_spanStartedAfterParentEnded() { - final Transaction transaction = createTransaction() + final TransactionImpl transaction = createTransaction() .activate(); transaction.end(10); - final AbstractSpan active = tracer.getActive(); + final AbstractSpanImpl active = tracer.getActive(); assertThat(active).isSameAs(transaction); assertThat(transaction.getTraceContext().getId().isEmpty()).isFalse(); active.createSpan(20).withType("db").withSubtype("mysql").end(30); @@ -347,7 +347,7 @@ void testBreakdown_spanStartedAfterParentEnded() { @Test void testBreakdown_serviceName() { - final Transaction transaction = createTransaction(); + final TransactionImpl transaction = createTransaction(); transaction.getTraceContext().setServiceInfo("service_name", null); transaction.createSpan(11).withType("db").withSubtype("mysql").end(23); transaction.end(27); @@ -362,7 +362,7 @@ void testBreakdown_serviceName() { @Test void testBreakdown_serviceNameAndVersion() { - final Transaction transaction = createTransaction(); + final TransactionImpl transaction = createTransaction(); transaction.getTraceContext().setServiceInfo("service_name", "service_version"); transaction.createSpan(11).withType("db").withSubtype("mysql").end(23); transaction.end(27); @@ -375,7 +375,7 @@ void testBreakdown_serviceNameAndVersion() { }); } - private Transaction createTransaction() { + private TransactionImpl createTransaction() { return tracer.startRootTransaction(ConstantSampler.of(true), 0, getClass().getClassLoader()) .withName("test") .withType("request"); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/baggage/BaggageBuilderTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/baggage/BaggageBuilderTest.java index a3cc870a47..e540203fb7 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/baggage/BaggageBuilderTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/baggage/BaggageBuilderTest.java @@ -27,23 +27,23 @@ public class BaggageBuilderTest { @Test public void verifyBaggageReuseOnNoModification() { - Baggage base = Baggage.builder() + BaggageImpl base = BaggageImpl.builder() .put("foo", "bar") .build(); - Baggage newlyBuilt = base.toBuilder().build(); + BaggageImpl newlyBuilt = base.toBuilder().build(); assertThat(newlyBuilt).isSameAs(base); } @Test public void verifyBaggageBuilderPreserversOriginalBaggage() { - Baggage base = Baggage.builder() + BaggageImpl base = BaggageImpl.builder() .put("foo", "bar") .put("bar", "baz") .build(); - Baggage newlyBuilt = base.toBuilder() + BaggageImpl newlyBuilt = base.toBuilder() .put("foo", "not-bar") .build(); @@ -57,12 +57,12 @@ public void verifyBaggageBuilderPreserversOriginalBaggage() { @Test public void testEntryRemoval() { - Baggage base = Baggage.builder() + BaggageImpl base = BaggageImpl.builder() .put("foo", "bar") .put("bar", "baz") .build(); - Baggage newlyBuilt = base.toBuilder() + BaggageImpl newlyBuilt = base.toBuilder() .put("foo", null) .build(); @@ -77,12 +77,12 @@ public void testEntryRemoval() { @Test public void verifyMetadataPreserved() { - Baggage base = Baggage.builder() + BaggageImpl base = BaggageImpl.builder() .put("foo", "bar", "meta1") .put("bar", "baz", "meta2") .build(); - Baggage newlyBuilt = base.toBuilder() + BaggageImpl newlyBuilt = base.toBuilder() .put("foo", "not-bar") .put("new", "newval", "new_meta") .build(); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/baggage/W3CBaggagePropagationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/baggage/W3CBaggagePropagationTest.java index 13490f3c5b..9ca945f50c 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/baggage/W3CBaggagePropagationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/baggage/W3CBaggagePropagationTest.java @@ -42,7 +42,7 @@ public class Propagation { @Test public void testComplexValue() { - Baggage baggage = Baggage.builder() + BaggageImpl baggage = BaggageImpl.builder() .put("foo", "bar") .put("my_key!", "hello, world!?%ä=", "metadata=blub") .build(); @@ -55,7 +55,7 @@ public void testComplexValue() { } @NotNull - private Map doPropagate(Baggage baggage) { + private Map doPropagate(BaggageImpl baggage) { Map resultHeaders = new HashMap<>(); W3CBaggagePropagation.propagate(baggage, resultHeaders, TextHeaderMapAccessor.INSTANCE); @@ -68,7 +68,7 @@ private Map doPropagate(Baggage baggage) { @Test public void testEmptyBaggage() { - Baggage baggage = Baggage.builder().build(); + BaggageImpl baggage = BaggageImpl.builder().build(); Map resultHeaders = doPropagate(baggage); @@ -77,7 +77,7 @@ public void testEmptyBaggage() { @Test public void testInvalidKeysIgnored() { - Baggage baggage = Baggage.builder() + BaggageImpl baggage = BaggageImpl.builder() .put("foo", "bar") .put("bad,key", "42") .build(); @@ -92,7 +92,7 @@ public void testInvalidKeysIgnored() { @Test public void testOnlyInvalidKeys() { - Baggage baggage = Baggage.builder() + BaggageImpl baggage = BaggageImpl.builder() .put("bad,key", "42") .build(); @@ -113,7 +113,7 @@ public void testComplexValueString() { "bar=baz2" }; - Baggage.Builder resultBuilder = Baggage.builder(); + BaggageImpl.Builder resultBuilder = BaggageImpl.builder(); W3CBaggagePropagation.parse(baggageHeaders, new TextBaggageheaderGetter(), resultBuilder); assertThat(resultBuilder.build()) @@ -122,7 +122,7 @@ public void testComplexValueString() { .containsEntry("bar", "baz2", null) .containsEntry("foo", "bar2", "overridden=meta"); - Baggage.Builder utf8ResultBuilder = Baggage.builder(); + BaggageImpl.Builder utf8ResultBuilder = BaggageImpl.builder(); W3CBaggagePropagation.parse(baggageHeaders, new UTF8BaggageheaderGetter(), utf8ResultBuilder); assertThat(utf8ResultBuilder.build()).isEqualTo(resultBuilder.build()); } @@ -130,11 +130,11 @@ public void testComplexValueString() { @Test public void testNoValue() { - Baggage.Builder textResultBuilder = Baggage.builder(); + BaggageImpl.Builder textResultBuilder = BaggageImpl.builder(); W3CBaggagePropagation.parse(Collections.emptyMap(), TextHeaderMapAccessor.INSTANCE, textResultBuilder); assertThat(textResultBuilder.build()).hasSize(0); - Baggage.Builder utf8ResultBuilder = Baggage.builder(); + BaggageImpl.Builder utf8ResultBuilder = BaggageImpl.builder(); W3CBaggagePropagation.parse(Collections.emptyMap(), Utf8HeaderMapAccessor.INSTANCE, utf8ResultBuilder); assertThat(textResultBuilder.build()).hasSize(0); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/circuitbreaker/CircuitBreakerTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/circuitbreaker/CircuitBreakerTest.java index 98a6733494..5ba6a11314 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/circuitbreaker/CircuitBreakerTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/circuitbreaker/CircuitBreakerTest.java @@ -37,8 +37,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; -import static co.elastic.apm.agent.impl.Tracer.TracerState.PAUSED; -import static co.elastic.apm.agent.impl.Tracer.TracerState.RUNNING; +import static co.elastic.apm.agent.impl.ElasticApmTracer.TracerState.PAUSED; +import static co.elastic.apm.agent.impl.ElasticApmTracer.TracerState.RUNNING; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.awaitility.Awaitility.await; import static org.mockito.Mockito.doReturn; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyCaptureTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyCaptureTest.java new file mode 100644 index 0000000000..04c3ead438 --- /dev/null +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyCaptureTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.impl.context; + +import org.junit.jupiter.api.Test; + +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; + +import static co.elastic.apm.agent.testutils.assertions.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class BodyCaptureTest { + + @Test + public void testAppendTruncation() { + BodyCaptureImpl capture = new BodyCaptureImpl(); + capture.markEligibleForCapturing(); + capture.startCapture("foobar", 10); + assertThat(capture.isFull()).isFalse(); + + capture.append("123Hello World!".getBytes(StandardCharsets.UTF_8), 3, 5); + assertThat(capture.isFull()).isFalse(); + + capture.append(" from the other side".getBytes(StandardCharsets.UTF_8), 0, 20); + assertThat(capture.isFull()).isTrue(); + + ByteBuffer content = capture.getBody(); + int size = content.position(); + byte[] contentBytes = new byte[size]; + content.position(0); + content.get(contentBytes); + + assertThat(contentBytes).isEqualTo("Hello from".getBytes(StandardCharsets.UTF_8)); + } + + @Test + public void testLifecycle() { + BodyCaptureImpl capture = new BodyCaptureImpl(); + + assertThat(capture.isEligibleForCapturing()).isFalse(); + assertThat(capture.startCapture("foobar", 42)) + .isFalse(); + assertThatThrownBy(() -> capture.append((byte) 42)).isInstanceOf(IllegalStateException.class); + + capture.markEligibleForCapturing(); + assertThat(capture.isEligibleForCapturing()).isTrue(); + assertThatThrownBy(() -> capture.append((byte) 42)).isInstanceOf(IllegalStateException.class); + + assertThat(capture.startCapture("foobar", 42)) + .isTrue(); + capture.append((byte) 42); //ensure no exception thrown + + // startCapture should return true only once + assertThat(capture.startCapture("foobar", 42)) + .isFalse(); + } +} diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyProcessorTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyProcessorTest.java index 53b10837f6..e93b7f3cba 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyProcessorTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/BodyProcessorTest.java @@ -19,38 +19,38 @@ package co.elastic.apm.agent.impl.context; import co.elastic.apm.agent.MockTracer; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.stagemonitor.configuration.ConfigurationRegistry; -import static co.elastic.apm.agent.impl.context.AbstractContext.REDACTED_CONTEXT_STRING; +import static co.elastic.apm.agent.impl.context.AbstractContextImpl.REDACTED_CONTEXT_STRING; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doReturn; class BodyProcessorTest { private BodyProcessor bodyProcessor; - private CoreConfiguration config; + private CoreConfigurationImpl config; private ElasticApmTracer tracer; @BeforeEach void setUp() { ConfigurationRegistry configurationRegistry = SpyConfiguration.createSpyConfig(); bodyProcessor = new BodyProcessor(configurationRegistry); - config = configurationRegistry.getConfig(CoreConfiguration.class); + config = configurationRegistry.getConfig(CoreConfigurationImpl.class); tracer = MockTracer.create(configurationRegistry); } @Test void processBeforeReport_Transaction_EventTypeAll() { - doReturn(CoreConfiguration.EventType.ALL).when(config).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(config).getCaptureBody(); - final Transaction transaction = processTransaction(); + final TransactionImpl transaction = processTransaction(); assertThat(transaction.getContext().getRequest().getBody().toString()).isEqualTo("foo"); assertThat(transaction.getContext().getMessage().getBodyForRead().toString()).isEqualTo("bar"); @@ -58,9 +58,9 @@ void processBeforeReport_Transaction_EventTypeAll() { @Test void processBeforeReport_Transaction_EventTypeTransaction() { - doReturn(CoreConfiguration.EventType.TRANSACTIONS).when(config).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.TRANSACTIONS).when(config).getCaptureBody(); - final Transaction transaction = processTransaction(); + final TransactionImpl transaction = processTransaction(); assertThat(transaction.getContext().getRequest().getBody().toString()).isEqualTo("foo"); assertThat(transaction.getContext().getMessage().getBodyForRead().toString()).isEqualTo("bar"); @@ -68,9 +68,9 @@ void processBeforeReport_Transaction_EventTypeTransaction() { @Test void processBeforeReport_Transaction_EventTypeError() { - doReturn(CoreConfiguration.EventType.ERRORS).when(config).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ERRORS).when(config).getCaptureBody(); - final Transaction transaction = processTransaction(); + final TransactionImpl transaction = processTransaction(); assertThat(transaction.getContext().getRequest().getBody().toString()).isEqualTo(REDACTED_CONTEXT_STRING); assertThat(transaction.getContext().getMessage().getBodyForRead().toString()).isEqualTo(REDACTED_CONTEXT_STRING); @@ -78,9 +78,9 @@ void processBeforeReport_Transaction_EventTypeError() { @Test void processBeforeReport_Transaction_EventTypeOff() { - doReturn(CoreConfiguration.EventType.OFF).when(config).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.OFF).when(config).getCaptureBody(); - final Transaction transaction = processTransaction(); + final TransactionImpl transaction = processTransaction(); assertThat(transaction.getContext().getRequest().getBody().toString()).isEqualTo(REDACTED_CONTEXT_STRING); assertThat(transaction.getContext().getMessage().getBodyForRead().toString()).isEqualTo(REDACTED_CONTEXT_STRING); @@ -88,9 +88,9 @@ void processBeforeReport_Transaction_EventTypeOff() { @Test void processBeforeReport_Error_EventTypeAll() { - doReturn(CoreConfiguration.EventType.ALL).when(config).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(config).getCaptureBody(); - final ErrorCapture error = processError(); + final ErrorCaptureImpl error = processError(); assertThat(error.getContext().getRequest().getBody().toString()).isEqualTo("foo"); assertThat(error.getContext().getMessage().getBodyForRead().toString()).isEqualTo("bar"); @@ -98,9 +98,9 @@ void processBeforeReport_Error_EventTypeAll() { @Test void processBeforeReport_Error_EventTypeTransaction() { - doReturn(CoreConfiguration.EventType.TRANSACTIONS).when(config).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.TRANSACTIONS).when(config).getCaptureBody(); - final ErrorCapture error = processError(); + final ErrorCaptureImpl error = processError(); assertThat(error.getContext().getRequest().getBody().toString()).isEqualTo(REDACTED_CONTEXT_STRING); assertThat(error.getContext().getMessage().getBodyForRead().toString()).isEqualTo(REDACTED_CONTEXT_STRING); @@ -108,9 +108,9 @@ void processBeforeReport_Error_EventTypeTransaction() { @Test void processBeforeReport_Error_EventTypeError() { - doReturn(CoreConfiguration.EventType.ERRORS).when(config).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ERRORS).when(config).getCaptureBody(); - final ErrorCapture error = processError(); + final ErrorCaptureImpl error = processError(); assertThat(error.getContext().getRequest().getBody().toString()).isEqualTo("foo"); assertThat(error.getContext().getMessage().getBodyForRead().toString()).isEqualTo("bar"); @@ -118,17 +118,17 @@ void processBeforeReport_Error_EventTypeError() { @Test void processBeforeReport_Error_EventTypeOff() { - doReturn(CoreConfiguration.EventType.OFF).when(config).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.OFF).when(config).getCaptureBody(); - final ErrorCapture error = processError(); + final ErrorCaptureImpl error = processError(); assertThat(error.getContext().getRequest().getBody().toString()).isEqualTo(REDACTED_CONTEXT_STRING); assertThat(error.getContext().getMessage().getBodyForRead().toString()).isEqualTo(REDACTED_CONTEXT_STRING); } - private Transaction processTransaction() { - final Transaction transaction = new Transaction(tracer); - Request request = transaction.getContext().getRequest(); + private TransactionImpl processTransaction() { + final TransactionImpl transaction = new TransactionImpl(tracer); + RequestImpl request = transaction.getContext().getRequest(); request.withBodyBuffer().append("foo"); request.endOfBufferInput(); transaction.getContext().getMessage().withBody("bar"); @@ -136,9 +136,9 @@ private Transaction processTransaction() { return transaction; } - private ErrorCapture processError() { - final ErrorCapture error = new ErrorCapture(tracer); - Request request = error.getContext().getRequest(); + private ErrorCaptureImpl processError() { + final ErrorCaptureImpl error = new ErrorCaptureImpl(tracer); + RequestImpl request = error.getContext().getRequest(); request.withBodyBuffer().append("foo"); request.endOfBufferInput(); error.getContext().getMessage().withBody("bar"); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/DestinationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/DestinationTest.java index 93bd5c2354..a312fa73e3 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/DestinationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/DestinationTest.java @@ -56,7 +56,7 @@ void invalidPortShouldIgnore() { @Test void setAddressTwiceShouldReset() { - Destination destination = new Destination(); + DestinationImpl destination = new DestinationImpl(); assertThat(destination.withAddress("aaa").withAddress("bb").getAddress().toString()) .isEqualTo("bb"); @@ -67,7 +67,7 @@ void userAddressHavePriority() { checkAddress("user-before", d -> d.withUserAddress("user-before").withAddress("address")); checkAddress("user-after", d -> d.withAddress("user-before").withUserAddress("user-after")); - Destination emptyUserAddress = new Destination().withAddress("host").withUserAddress(""); + DestinationImpl emptyUserAddress = new DestinationImpl().withAddress("host").withUserAddress(""); assertThat(emptyUserAddress.getAddress()).isEmpty(); assertThat(emptyUserAddress.hasContent()).isFalse(); } @@ -79,17 +79,17 @@ void userPortHavePriority() { checkPort(33, d -> d.withPort(42).withUserPort(33)); checkPort(33, d -> d.withUserPort(33).withPort(42)); } - - private static void checkPort(int expected, Function operations) { - Destination destination = new Destination(); + + private static void checkPort(int expected, Function operations) { + DestinationImpl destination = new DestinationImpl(); operations.apply(destination); assertThat(destination.getPort()).isEqualTo(expected); assertThat(destination.hasContent()).isTrue(); } - private static void checkAddress(String expected, Function operations) { - Destination destination = new Destination(); + private static void checkAddress(String expected, Function operations) { + DestinationImpl destination = new DestinationImpl(); operations.apply(destination); assertThat(destination.getAddress().toString()) // call to toString required otherwise comparison fails .isEqualTo(expected); @@ -102,7 +102,7 @@ private void checkSetAddress(String input, String expectedAddress) { } private void checkSetHostAndPort(String input, String expectedHost, int expectedPort) { - Destination destination = new Destination(); + DestinationImpl destination = new DestinationImpl(); destination.withAddressPort(input); assertThat(destination.hasContent()).isTrue(); @@ -112,7 +112,7 @@ private void checkSetHostAndPort(String input, String expectedHost, int expected } private void checkInvalidHostAndPort(String input) { - Destination destination = new Destination(); + DestinationImpl destination = new DestinationImpl(); destination.withAddressPort(input); assertThat(destination.hasContent()).isFalse(); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/MessageTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/MessageTest.java index 46200a1894..eae6bd7855 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/MessageTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/MessageTest.java @@ -28,7 +28,7 @@ class MessageTest { @Test void testResetState() { - Message message = createMessage(100L, "test-body", "test-q", "test-*", Map.of("test-header", "test-value")); + MessageImpl message = createMessage(100L, "test-body", "test-q", "test-*", Map.of("test-header", "test-value")); message.resetState(); @@ -41,8 +41,8 @@ void testResetState() { @Test void testCopyFrom() { - Message firstMessage = createMessage(100L, "test-body", "test-q", "test-*", Map.of("test-header", "test-value")); - Message secondMessage = createMessage(999L, "updated-body", "updated-test-q", "updated-test-*", Map.of("updated-test-header", "updated-test-value")); + MessageImpl firstMessage = createMessage(100L, "test-body", "test-q", "test-*", Map.of("test-header", "test-value")); + MessageImpl secondMessage = createMessage(999L, "updated-body", "updated-test-q", "updated-test-*", Map.of("updated-test-header", "updated-test-value")); firstMessage.copyFrom(secondMessage); @@ -59,8 +59,8 @@ void testCopyFrom() { assertThat(firstMessageBody.toString()).isEqualTo("updated-body"); } - private Message createMessage(long age, String body, String queue, String routingKey, Map headers) { - Message message = new Message() + private MessageImpl createMessage(long age, String body, String queue, String routingKey, Map headers) { + MessageImpl message = new MessageImpl() .withAge(age) .withBody(body) .withQueue(queue) diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/SanitizingWebProcessorTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/SanitizingWebProcessorTest.java index ee573b6cbe..c00931bb75 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/SanitizingWebProcessorTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/SanitizingWebProcessorTest.java @@ -20,12 +20,12 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.configuration.SpyConfiguration; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static co.elastic.apm.agent.impl.context.AbstractContext.REDACTED_CONTEXT_STRING; +import static co.elastic.apm.agent.impl.context.AbstractContextImpl.REDACTED_CONTEXT_STRING; import static org.assertj.core.api.Assertions.assertThat; class SanitizingWebProcessorTest { @@ -39,7 +39,7 @@ void setUp() { @Test void processTransactions() { - Transaction transaction = new Transaction(MockTracer.create()); + TransactionImpl transaction = new TransactionImpl(MockTracer.create()); fillContext(transaction.getContext()); processor.processBeforeReport(transaction); @@ -49,7 +49,7 @@ void processTransactions() { @Test void processErrors() { - final ErrorCapture errorCapture = new ErrorCapture(MockTracer.create()); + final ErrorCaptureImpl errorCapture = new ErrorCaptureImpl(MockTracer.create()); fillContext(errorCapture.getContext()); processor.processBeforeReport(errorCapture); @@ -57,7 +57,7 @@ void processErrors() { assertContainsNoSensitiveInformation(errorCapture.getContext()); } - private void fillContext(TransactionContext context) { + private void fillContext(TransactionContextImpl context) { context.getRequest().addCookie("JESESSIONID", "CAFEBABE"); context.getRequest().addCookie("non-sensitive", "foo"); context.getRequest().addFormUrlEncodedParameter("cretidCard", "1234 1234 1234 1234"); @@ -70,7 +70,7 @@ private void fillContext(TransactionContext context) { context.getResponse().addHeader("Content-Length", "-1"); } - private void assertContainsNoSensitiveInformation(TransactionContext context) { + private void assertContainsNoSensitiveInformation(TransactionContextImpl context) { assertThat(context.getRequest().getCookies().get("JESESSIONID")).isEqualTo(REDACTED_CONTEXT_STRING); assertThat(context.getRequest().getCookies().get("non-sensitive")).isEqualTo("foo"); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceResourceTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceResourceTest.java index 7dfad3fd21..ed65ee8274 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceResourceTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceResourceTest.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.testutils.assertions.ServiceTargetAssert; import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.AfterAll; @@ -44,7 +44,7 @@ public class ServiceResourceTest { - private static Transaction root; + private static TransactionImpl root; @BeforeAll static void startRootTransaction() { @@ -60,7 +60,7 @@ static void endTransaction() { @ParameterizedTest @MethodSource("getTestCases") void testServiceResourceInference(JsonNode testCase) { - Span span = createSpan(testCase); + SpanImpl span = createSpan(testCase); // increment reference count to prevent recycling while test executes span.incrementReferences(); @@ -70,7 +70,7 @@ void testServiceResourceInference(JsonNode testCase) { JsonNode jsonServiceTarget = testCase.get("expected_service_target"); - ServiceTarget serviceTarget = span.getContext().getServiceTarget(); + ServiceTargetImpl serviceTarget = span.getContext().getServiceTarget(); ServiceTargetAssert testAssertion = assertThat(serviceTarget) .describedAs(getTextValueOrNull(testCase, "failure_message")); @@ -97,8 +97,8 @@ void testServiceResourceInference(JsonNode testCase) { span.decrementReferences(); } - private Span createSpan(JsonNode testCase) { - Span span = root.createSpan(); + private SpanImpl createSpan(JsonNode testCase) { + SpanImpl span = root.createSpan(); JsonNode spanJson = testCase.get("span"); span.withType(spanJson.get("type").textValue()); JsonNode subtypeJsonNode = spanJson.get("subtype"); @@ -110,7 +110,7 @@ private Span createSpan(JsonNode testCase) { } JsonNode contextJson = spanJson.get("context"); if (contextJson != null) { - SpanContext context = span.getContext(); + SpanContextImpl context = span.getContext(); JsonNode dbJson = contextJson.get("db"); if (dbJson != null) { context.getDb() @@ -119,7 +119,7 @@ private Span createSpan(JsonNode testCase) { } JsonNode messageJson = contextJson.get("message"); if (messageJson != null) { - Message message = context.getMessage(); + MessageImpl message = context.getMessage(); message.withBody(getTextValueOrNull(messageJson, "body")); JsonNode queueJson = messageJson.get("queue"); if (queueJson != null) { @@ -130,7 +130,7 @@ private Span createSpan(JsonNode testCase) { if (httpJson != null) { String urlValue = getTextValueOrNull(httpJson, "url"); if (urlValue != null) { - Url url = context.getHttp().getInternalUrl(); + UrlImpl url = context.getHttp().getInternalUrl(); try { url.fillFrom(new URI(urlValue)); } catch (URISyntaxException e) { diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceTargetTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceTargetTest.java index e04d37b7df..390fa774d6 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceTargetTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/ServiceTargetTest.java @@ -31,7 +31,7 @@ class ServiceTargetTest { @Test void createEmpty() { - ServiceTarget serviceTarget = new ServiceTarget(); + ServiceTargetImpl serviceTarget = new ServiceTargetImpl(); assertThat(serviceTarget).isEmpty(); assertThat(serviceTarget).isNotSetByUser(); assertThat(serviceTarget).hasNoName(); @@ -40,7 +40,7 @@ void createEmpty() { @Test void typeOnly() { - ServiceTarget serviceTarget = new ServiceTarget(); + ServiceTargetImpl serviceTarget = new ServiceTargetImpl(); String serviceType = "service-type"; assertThat(serviceTarget.withType(serviceType)) @@ -58,7 +58,7 @@ void typeOnly() { @Test void typeAndName() { - ServiceTarget serviceTarget = new ServiceTarget(); + ServiceTargetImpl serviceTarget = new ServiceTargetImpl(); assertThat(serviceTarget.withType("service-type").withName("service-name")) .hasType("service-type") @@ -78,7 +78,7 @@ void typeAndName() { @Test void userValuePriority_userValuesAfter() { - ServiceTarget serviceTarget = new ServiceTarget(); + ServiceTargetImpl serviceTarget = new ServiceTargetImpl(); serviceTarget.withType("type").withName("name"); assertThat(serviceTarget).hasType("type").hasName("name").isNotSetByUser(); @@ -89,7 +89,7 @@ void userValuePriority_userValuesAfter() { @Test void userValuePriority_userValuesBefore() { - ServiceTarget serviceTarget = new ServiceTarget(); + ServiceTargetImpl serviceTarget = new ServiceTargetImpl(); assertThat(serviceTarget.withUserType("user-type")).hasType("user-type").isSetByUser(); assertThat(serviceTarget.withUserName("user-name")).hasName("user-name").isSetByUser(); @@ -103,7 +103,7 @@ void userValuePriority_userValuesBefore() { @Test void userValuePriority_userValuesStillModifiable() { - ServiceTarget serviceTarget = new ServiceTarget(); + ServiceTargetImpl serviceTarget = new ServiceTargetImpl(); assertThat(serviceTarget.withUserType("user-type")).hasType("user-type").isSetByUser(); assertThat(serviceTarget.withUserName("user-name")).hasName("user-name").isSetByUser(); @@ -116,7 +116,7 @@ void userValuePriority_userValuesStillModifiable() { void emptyOrNullUserDestinationResourceIsIgnored() { // using null or empty value should allow user to empty service target Stream.of("", null).forEach(value -> { - ServiceTarget serviceTarget = new ServiceTarget(); + ServiceTargetImpl serviceTarget = new ServiceTargetImpl(); assertThat(serviceTarget.withUserName(value)) .isEmpty() .isSetByUser(); @@ -126,7 +126,7 @@ void emptyOrNullUserDestinationResourceIsIgnored() { @Test void userResourceWithoutExplicitType() { - ServiceTarget serviceTarget = new ServiceTarget(); + ServiceTargetImpl serviceTarget = new ServiceTargetImpl(); serviceTarget.withName("user-resource").withNameOnlyDestinationResource(); assertThat(serviceTarget) .hasName("user-resource") @@ -135,7 +135,7 @@ void userResourceWithoutExplicitType() { @Test void setDestinationResourceFromHostAndPort() { - ServiceTarget serviceTarget = new ServiceTarget().withType("test").withName("name"); + ServiceTargetImpl serviceTarget = new ServiceTargetImpl().withType("test").withName("name"); assertThat(serviceTarget) .describedAs("destination resource should be inferred from type an name") .hasDestinationResource("test/name"); @@ -170,29 +170,29 @@ void setDestinationResourceFromHostAndPort() { @Test void testCopy() { testCopy(st -> st.withType("type"), - ServiceTarget::getType); + ServiceTargetImpl::getType); testCopy(st -> st.withType("type").withName("name"), - ServiceTarget::getType, + ServiceTargetImpl::getType, st -> st.getName().toString()); testCopy(st -> st.withUserType("user-type").withUserName("user-resource").withNameOnlyDestinationResource(), - ServiceTarget::getType, + ServiceTargetImpl::getType, st -> st.getName().toString(), st -> st.getDestinationResource().toString(), - ServiceTarget::isSetByUser); + ServiceTargetImpl::isSetByUser); } - private void testCopy(Function setOperation, Function... getOperations) { - ServiceTarget original = new ServiceTarget(); + private void testCopy(Function setOperation, Function... getOperations) { + ServiceTargetImpl original = new ServiceTargetImpl(); setOperation.apply(original); - ServiceTarget copy = new ServiceTarget(); + ServiceTargetImpl copy = new ServiceTargetImpl(); copy.copyFrom(original); List results = new ArrayList<>(); - for (Function operation : getOperations) { + for (Function operation : getOperations) { Object resultOnOriginal = operation.apply(original); Object resultOnCopy = operation.apply(copy); assertThat(resultOnCopy).isEqualTo(resultOnOriginal); @@ -212,7 +212,7 @@ private void testCopy(Function setOperation, Funct @Test void testHostPort() { - ServiceTarget st = new ServiceTarget() + ServiceTargetImpl st = new ServiceTargetImpl() .withHostPortName("host", 99) .withNameOnlyDestinationResource(); @@ -229,7 +229,7 @@ void testHostPort() { @Test void emptyOrNullUserType() { Stream.of("", null).forEach(type -> { - ServiceTarget st = new ServiceTarget().withUserType(type).withName("name"); + ServiceTargetImpl st = new ServiceTargetImpl().withUserType(type).withName("name"); assertThat(st).hasDestinationResource("name"); }); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/TransactionContextTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/TransactionContextTest.java index 3d0456b29c..e414422a39 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/TransactionContextTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/TransactionContextTest.java @@ -27,33 +27,33 @@ class TransactionContextTest { @Test void testCopyFrom() { - TransactionContext context = createContext(); - TransactionContext copyOfContext = new TransactionContext(); + TransactionContextImpl context = createContext(); + TransactionContextImpl copyOfContext = new TransactionContextImpl(); copyOfContext.copyFrom(context); assertThat(toJson(context)).isEqualTo(toJson(copyOfContext)); } @Test void testCopyFromCopiesTags() { - TransactionContext context = new TransactionContext(); + TransactionContextImpl context = new TransactionContextImpl(); context.addLabel("foo", "bar"); - TransactionContext copyOfContext = new TransactionContext(); + TransactionContextImpl copyOfContext = new TransactionContextImpl(); copyOfContext.copyFrom(context); assertThat(copyOfContext.getLabel("foo")).isEqualTo("bar"); } @Test void testCopyFromDoNotCopyCustom() { - TransactionContext context = new TransactionContext(); + TransactionContextImpl context = new TransactionContextImpl(); context.addCustom("foo", "bar"); - TransactionContext copyOfContext = new TransactionContext(); + TransactionContextImpl copyOfContext = new TransactionContextImpl(); copyOfContext.copyFrom(context); assertThat(copyOfContext.hasCustom()).isFalse(); } - private TransactionContext createContext() { - TransactionContext context = new TransactionContext(); - Request request = context.getRequest(); + private TransactionContextImpl createContext() { + TransactionContextImpl context = new TransactionContextImpl(); + RequestImpl request = context.getRequest(); request.withHttpVersion("1.1"); request.withMethod("POST"); request.withBodyBuffer().append("Hello World"); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/UrlTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/UrlTest.java index 038589ba35..507318d77c 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/UrlTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/context/UrlTest.java @@ -33,22 +33,22 @@ class UrlTest { @Test void testResetState() { - final Url url = sampleUrl(); + final UrlImpl url = sampleUrl(); url.resetState(); - assertThat(toJson(url)).isEqualTo(toJson(new Url())); + assertThat(toJson(url)).isEqualTo(toJson(new UrlImpl())); } @Test void testCopyOf() { - final Url url = sampleUrl(); - final Url copy = new Url(); + final UrlImpl url = sampleUrl(); + final UrlImpl copy = new UrlImpl(); copy.copyFrom(url); assertThat(toJson(url)).isEqualTo(toJson(copy)); - assertThat(toJson(url)).isNotEqualTo(toJson(new Url())); + assertThat(toJson(url)).isNotEqualTo(toJson(new UrlImpl())); } - private Url sampleUrl() { - return new Url() + private UrlImpl sampleUrl() { + return new UrlImpl() .withHostname("localhost") .withPathname("/foo") .withPort(8080) @@ -59,27 +59,27 @@ private Url sampleUrl() { @Test void computeFullFromProperties() { // default port on http - assertThat(new Url().withProtocol("http") + assertThat(new UrlImpl().withProtocol("http") .withHostname("localhost") .withPort(80) .getFull().toString()).isEqualTo("http://localhost"); // non default port on http + path - assertThat(new Url().withProtocol("http") + assertThat(new UrlImpl().withProtocol("http") .withHostname("localhost") .withPort(8080) .withPathname("/hello") .getFull().toString()).isEqualTo("http://localhost:8080/hello"); // default port on https + search string - assertThat(new Url().withProtocol("https") + assertThat(new UrlImpl().withProtocol("https") .withHostname("hostname") .withPort(443) .withSearch("hello=world") .getFull().toString()).isEqualTo("https://hostname?hello=world"); // non default port on https - assertThat(new Url().withProtocol("https") + assertThat(new UrlImpl().withProtocol("https") .withHostname("hostname") .withPort(447) .getFull().toString()).isEqualTo("https://hostname:447"); @@ -100,11 +100,11 @@ void computeFullFromProperties() { "https://user:pwd@localhost:447/ https://localhost:447/ https localhost 447 / " }) void fillFromURIorURL(String uriString, String full, String protocol, String host, int port, String path, String query) throws MalformedURLException { - Url urlFromUri = new Url(); + UrlImpl urlFromUri = new UrlImpl(); URI uri = URI.create(uriString); urlFromUri.fillFrom(uri); - Url urlFromUrl = new Url(); + UrlImpl urlFromUrl = new UrlImpl(); urlFromUrl.fillFrom(uri.toURL()); Stream.of(urlFromUri, urlFromUrl).forEach(url -> { @@ -123,7 +123,7 @@ void fillFromURIorURL(String uriString, String full, String protocol, String hos "http://user:password@localhost/path?query=help http://localhost/path?query=help" }) void withFull(String input, String expected) { - Url url = new Url(); + UrlImpl url = new UrlImpl(); url.withFull(input); assertThat(url.getFull().toString()).isEqualTo(expected); @@ -141,7 +141,7 @@ void withFull(String input, String expected) { @Test void getFullUpdatesFullWhenRequired() { - Url url = new Url(); + UrlImpl url = new UrlImpl(); StringBuilder full = url.getFull(); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/MetaDataMock.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/MetaDataMock.java index 6de3f37f85..c42132697a 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/MetaDataMock.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/MetaDataMock.java @@ -33,7 +33,7 @@ public class MetaDataMock { * * @return a mock future, already containing the medata info */ - public static Future create(ProcessInfo process, Service service, SystemInfo system, @Nullable CloudProviderInfo cloudProviderInfo, + public static Future create(ProcessInfo process, ServiceImpl service, SystemInfo system, @Nullable CloudProviderInfo cloudProviderInfo, Map globalLabels, @Nullable FaaSMetaDataExtension faaSMetaDataExtension) { return create(new MetaData(process, service, system, cloudProviderInfo, globalLabels, faaSMetaDataExtension)); } @@ -46,7 +46,7 @@ public static Future create(ProcessInfo process, Service service, Syst public static Future create() { return create(new MetaData( new ProcessInfo("test-process"), - new Service(), + new ServiceImpl(), new SystemInfo("x64", "localhost", null, "platform"), null, Collections.emptyMap(), @@ -64,7 +64,7 @@ public static Future create(MetaData value) { public static MetaData createDefaultMock() { return spy(new MetaData( new ProcessInfo("test-process"), - new Service(), + new ServiceImpl(), new SystemInfo("x64", "localhost", null, "platform"), null, Collections.emptyMap(), diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/MetaDataTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/MetaDataTest.java index 7ff614d91b..25c2c9e9f0 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/MetaDataTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/MetaDataTest.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.impl.metadata; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.configuration.ServerlessConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.util.CustomEnvVariables; import org.junit.jupiter.api.BeforeAll; @@ -38,9 +38,9 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import static co.elastic.apm.agent.configuration.CoreConfiguration.CloudProvider.AUTO; -import static co.elastic.apm.agent.configuration.CoreConfiguration.CloudProvider.AWS; -import static co.elastic.apm.agent.configuration.CoreConfiguration.CloudProvider.NONE; +import static co.elastic.apm.agent.configuration.CoreConfigurationImpl.CloudProvider.AUTO; +import static co.elastic.apm.agent.configuration.CoreConfigurationImpl.CloudProvider.AWS; +import static co.elastic.apm.agent.configuration.CoreConfigurationImpl.CloudProvider.NONE; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.Mockito.doReturn; @@ -48,20 +48,20 @@ class MetaDataTest extends CustomEnvVariables { private static ConfigurationRegistry config; - private static CoreConfiguration coreConfiguration; - private static ServerlessConfiguration serverlessConfiguration; + private static CoreConfigurationImpl coreConfiguration; + private static ServerlessConfigurationImpl serverlessConfiguration; @Nullable - private static CoreConfiguration.CloudProvider currentCloudProvider; + private static CoreConfigurationImpl.CloudProvider currentCloudProvider; @BeforeAll static void setup() { config = SpyConfiguration.createSpyConfig(); - coreConfiguration = config.getConfig(CoreConfiguration.class); - serverlessConfiguration = config.getConfig(ServerlessConfiguration.class); + coreConfiguration = config.getConfig(CoreConfigurationImpl.class); + serverlessConfiguration = config.getConfig(ServerlessConfigurationImpl.class); // calling the blocking method directly, so we can start tests only after proper discovery CloudProviderInfo cloudProviderInfo = CloudMetadataProvider.fetchAndParseCloudProviderInfo(AUTO, 1000); if (cloudProviderInfo != null) { - currentCloudProvider = CoreConfiguration.CloudProvider.valueOf(cloudProviderInfo.getProvider().toUpperCase()); + currentCloudProvider = CoreConfigurationImpl.CloudProvider.valueOf(cloudProviderInfo.getProvider().toUpperCase()); } } @@ -83,7 +83,7 @@ void testCloudProvider_NONE_and_configured_hostname() throws InterruptedExceptio void testCloudProvider_ForAWSLambda_fromEnvVariables() throws Exception { MetaData awsLambdaMetaData = createAwsLambdaMetaData(); - Service service = awsLambdaMetaData.getService(); + ServiceImpl service = awsLambdaMetaData.getService(); assertThat(Objects.requireNonNull(service.getRuntime()).getName()).isEqualTo("lambda-execution"); assertThat(Objects.requireNonNull(service.getNode()).getName()).isEqualTo("lambda-log-stream"); Framework framework = service.getFramework(); @@ -106,7 +106,7 @@ void testCloudProvider_ForAWSLambda_fromConfiguration() throws Exception { doReturn("test-service-version").when(coreConfiguration).getServiceVersion(); MetaData awsLambdaMetaData = createAwsLambdaMetaData(); - Service service = awsLambdaMetaData.getService(); + ServiceImpl service = awsLambdaMetaData.getService(); assertThat(service.getName()).isEqualTo("test-service"); assertThat(service.getVersion()).isEqualTo("test-service-version"); assertThat(Objects.requireNonNull(service.getNode()).getName()).isEqualTo("test-service-node-name"); @@ -135,8 +135,8 @@ private MetaData createAwsLambdaMetaData() throws Exception { } @ParameterizedTest - @EnumSource(value = CoreConfiguration.CloudProvider.class, names = {"AWS", "GCP", "AZURE"}) - void testCloudProvider_SingleProvider(CoreConfiguration.CloudProvider provider) throws InterruptedException, ExecutionException, TimeoutException { + @EnumSource(value = CoreConfigurationImpl.CloudProvider.class, names = {"AWS", "GCP", "AZURE"}) + void testCloudProvider_SingleProvider(CoreConfigurationImpl.CloudProvider provider) throws InterruptedException, ExecutionException, TimeoutException { doReturn(provider).when(coreConfiguration).getCloudProvider(); Future metaDataFuture = MetaData.create(config, null); // In AWS we may need two timeouts - one for the API token and one for the metadata itself @@ -179,11 +179,11 @@ void testCloudProvider_AUTO() throws InterruptedException, ExecutionException, T verifyMetaData(metaData, AUTO); } - private void verifyMetaData(MetaData metaData, CoreConfiguration.CloudProvider cloudProvider) { + private void verifyMetaData(MetaData metaData, CoreConfigurationImpl.CloudProvider cloudProvider) { verifyMetaData(metaData, cloudProvider, null); } - private void verifyMetaData(MetaData metaData, CoreConfiguration.CloudProvider cloudProvider, @Nullable String configuredHostname) { + private void verifyMetaData(MetaData metaData, CoreConfigurationImpl.CloudProvider cloudProvider, @Nullable String configuredHostname) { assertThat(metaData.getService()).isNotNull(); assertThat(metaData.getProcess()).isNotNull(); SystemInfo system = metaData.getSystem(); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/SystemInfoTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/SystemInfoTest.java index c107d7a267..7740915c01 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/SystemInfoTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/metadata/SystemInfoTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.metadata; -import co.elastic.apm.agent.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.configuration.ServerlessConfigurationImpl; import co.elastic.apm.agent.util.CustomEnvVariables; import org.junit.jupiter.api.Test; @@ -34,11 +34,11 @@ public class SystemInfoTest extends CustomEnvVariables { private static final SystemInfo systemInfo; private static final boolean isWindows; - private static final ServerlessConfiguration serverlessConfiguration; + private static final ServerlessConfigurationImpl serverlessConfiguration; static { - serverlessConfiguration = config.getConfig(ServerlessConfiguration.class); + serverlessConfiguration = config.getConfig(ServerlessConfigurationImpl.class); systemInfo = SystemInfo.create("hostname", 0, serverlessConfiguration); isWindows = SystemInfo.isWindows(systemInfo.getPlatform()); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/sampling/ProbabilitySamplerTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/sampling/ProbabilitySamplerTest.java index 216c593d11..aa49f1d0e9 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/sampling/ProbabilitySamplerTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/sampling/ProbabilitySamplerTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.sampling; -import co.elastic.apm.agent.impl.transaction.Id; +import co.elastic.apm.agent.impl.transaction.IdImpl; import co.elastic.apm.agent.impl.transaction.TraceState; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -58,7 +58,7 @@ void headerCaching(double rate) { @Test void isSampledEmpiricalTest() { int sampledTransactions = 0; - Id id = Id.new128BitId(); + IdImpl id = IdImpl.new128BitId(); for (int i = 0; i < ITERATIONS; i++) { id.setToRandomValue(); if (sampler.isSampled(id)) { @@ -71,7 +71,7 @@ void isSampledEmpiricalTest() { @Test void testSamplingUpperBoundary() { long upperBound = Long.MAX_VALUE / 2; - final Id transactionId = Id.new128BitId(); + final IdImpl transactionId = IdImpl.new128BitId(); transactionId.fromLongs((long) 0, upperBound - 1); assertThat(ProbabilitySampler.of(0.5).isSampled(transactionId)).isTrue(); @@ -86,7 +86,7 @@ void testSamplingUpperBoundary() { @Test void testSamplingLowerBoundary() { long lowerBound = -Long.MAX_VALUE / 2; - final Id transactionId = Id.new128BitId(); + final IdImpl transactionId = IdImpl.new128BitId(); transactionId.fromLongs((long) 0, lowerBound + 1); assertThat(ProbabilitySampler.of(0.5).isSampled(transactionId)).isTrue(); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfigurationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfigurationTest.java index fb285b04c8..9ab5b69994 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfigurationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/stacktrace/StacktraceConfigurationTest.java @@ -31,7 +31,7 @@ class StacktraceConfigurationTest { void testGetSpanStackTraceMinDurationMs_whenSpanStackTraceMinDurationNonDefault_thenGetValueFromSpanStackTraceMinDuration() { ConfigurationRegistry configRegistry = SpyConfiguration.createSpyConfig(SimpleSource.forTest("span_frames_min_duration", "10ms").add("span_stack_trace_min_duration", "15ms")); - long actual = configRegistry.getConfig(StacktraceConfiguration.class).getSpanStackTraceMinDurationMs(); + long actual = configRegistry.getConfig(StacktraceConfigurationImpl.class).getSpanStackTraceMinDurationMs(); assertThat(actual).isEqualTo(15); } @@ -39,7 +39,7 @@ void testGetSpanStackTraceMinDurationMs_whenSpanStackTraceMinDurationNonDefault_ void testGetSpanStackTraceMinDurationMs_whenSpanStackTraceDefault_whenSpanFramesNonDefault_thenGetValueFromSpanFramesMinDuration() { ConfigurationRegistry configRegistry = SpyConfiguration.createSpyConfig(SimpleSource.forTest("span_frames_min_duration", "15ms")); - long actual = configRegistry.getConfig(StacktraceConfiguration.class).getSpanStackTraceMinDurationMs(); + long actual = configRegistry.getConfig(StacktraceConfigurationImpl.class).getSpanStackTraceMinDurationMs(); assertThat(actual).isEqualTo(15); } @@ -47,7 +47,7 @@ void testGetSpanStackTraceMinDurationMs_whenSpanStackTraceDefault_whenSpanFrames void testGetSpanStackTraceMinDurationMs_whenSpanStackTraceDefault_whenSpanFramesMinDurationIsZero_thenGetSwappedValueOfSpanFramesMinDuration() { ConfigurationRegistry configRegistry = SpyConfiguration.createSpyConfig(SimpleSource.forTest("span_frames_min_duration", "0ms")); - long actual = configRegistry.getConfig(StacktraceConfiguration.class).getSpanStackTraceMinDurationMs(); + long actual = configRegistry.getConfig(StacktraceConfigurationImpl.class).getSpanStackTraceMinDurationMs(); assertThat(actual).isEqualTo(-1); } @@ -55,7 +55,7 @@ void testGetSpanStackTraceMinDurationMs_whenSpanStackTraceDefault_whenSpanFrames void testGetSpanStackTraceMinDurationMs_whenSpanStackTraceDefault_whenSpanFramesMinDurationIsNegative_thenGetSwappedValueOfSpanFramesMinDuration() { ConfigurationRegistry configRegistry = SpyConfiguration.createSpyConfig(SimpleSource.forTest("span_frames_min_duration", "-1ms")); - long actual = configRegistry.getConfig(StacktraceConfiguration.class).getSpanStackTraceMinDurationMs(); + long actual = configRegistry.getConfig(StacktraceConfigurationImpl.class).getSpanStackTraceMinDurationMs(); assertThat(actual).isEqualTo(0); } @@ -63,7 +63,7 @@ void testGetSpanStackTraceMinDurationMs_whenSpanStackTraceDefault_whenSpanFrames void testGetSpanStackTraceMinDurationMs_defaultValue() { ConfigurationRegistry configRegistry = SpyConfiguration.createSpyConfig(); - long actual = configRegistry.getConfig(StacktraceConfiguration.class).getSpanStackTraceMinDurationMs(); + long actual = configRegistry.getConfig(StacktraceConfigurationImpl.class).getSpanStackTraceMinDurationMs(); assertThat(actual).isEqualTo(5); } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/AbstractCompressionStrategyTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/AbstractCompressionStrategyTest.java index 99c576f68b..b5aa5fe896 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/AbstractCompressionStrategyTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/AbstractCompressionStrategyTest.java @@ -22,7 +22,7 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.configuration.SpanConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.context.ServiceTarget; +import co.elastic.apm.agent.impl.context.ServiceTargetImpl; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.configuration.TimeDuration; import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; @@ -81,9 +81,9 @@ void testCompositeSpanIsNotCreatedWhenCompressionIsNotEnabled() { startExitSpan(t).end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(3); - assertThat(reportedSpans).filteredOn(Span::isComposite).isEmpty(); + assertThat(reportedSpans).filteredOn(SpanImpl::isComposite).isEmpty(); } finally { doReturn(true).when(tracer.getConfig(SpanConfiguration.class)).isSpanCompressionEnabled(); } @@ -92,16 +92,16 @@ void testCompositeSpanIsNotCreatedWhenCompressionIsNotEnabled() { @Test void testCompositeSpanIsCreated() { runInTransactionScope(t -> { - Span span1 = startExitSpan(t); + SpanImpl span1 = startExitSpan(t); span1.setStartTimestamp(0); span1.end(1234); - Span span2 = startExitSpan(t); + SpanImpl span2 = startExitSpan(t); span2.setStartTimestamp(2345); span2.end(3456); - Span span3 = startExitSpan(t); + SpanImpl span3 = startExitSpan(t); span3.setStartTimestamp(3456); span3.end(4567); - Span span4 = startExitSpan(t); + SpanImpl span4 = startExitSpan(t); span4.setStartTimestamp(3467); span4.end(4556); }); @@ -110,7 +110,7 @@ void testCompositeSpanIsCreated() { startExitSpan(t).end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertCompositeSpan(reportedSpans.get(0), 4); assertThat(reportedSpans.get(0).getComposite().getSum()).isEqualTo(1234 + (3456 - 2345) + (4567 - 3456) + (4556 - 3467)); @@ -129,7 +129,7 @@ void testUnknownOutcomeStopsRegularCompression() { startExitSpan(t).withOutcome(Outcome.UNKNOWN).end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertThat(reportedSpans.get(0).isComposite()).isFalse(); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -147,7 +147,7 @@ void testUnknownOutcomeStopsCompositeCompression() { startExitSpan(t).withOutcome(Outcome.UNKNOWN).end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertCompositeSpan(reportedSpans.get(0), 2); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -164,7 +164,7 @@ void testFailedOutcomeStopsRegularCompression() { startExitSpan(t).withOutcome(Outcome.FAILURE).end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertThat(reportedSpans.get(0).isComposite()).isFalse(); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -182,7 +182,7 @@ void testFailedOutcomeStopsCompositeCompression() { startExitSpan(t).withOutcome(Outcome.FAILURE).end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertCompositeSpan(reportedSpans.get(0), 2); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -196,14 +196,14 @@ void testFailedOutcomeStopsCompositeCompression() { void testContextPropagationStopsRegularCompression() { runInTransactionScope(t -> { startExitSpan(t).end(); - Span span = startExitSpan(t); + SpanImpl span = startExitSpan(t); span.propagateContext(new HashMap(), (TextHeaderSetter>) (h, v, c) -> { c.put(h, v); }, null); span.end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertThat(reportedSpans.get(0).isComposite()).isFalse(); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -218,14 +218,14 @@ void testContextPropagationStopsCompositeCompression() { runInTransactionScope(t -> { startExitSpan(t).end(); startExitSpan(t).end(); - Span span = startExitSpan(t); + SpanImpl span = startExitSpan(t); span.propagateContext(new HashMap(), (TextHeaderSetter>) (h, v, c) -> { c.put(h, v); }, null); span.end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertCompositeSpan(reportedSpans.get(0), 2); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -242,7 +242,7 @@ void testNonExitSpanStopsRegularCompression() { startSpan(t).end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertThat(reportedSpans.get(0).isComposite()).isFalse(); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -260,7 +260,7 @@ void testNonExitSpanStopsCompositeCompression() { startSpan(t).end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertCompositeSpan(reportedSpans.get(0), 2); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -277,7 +277,7 @@ void testDifferentTypeStopsRegularCompression() { startExitSpan(t).withType("another_type").end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertThat(reportedSpans.get(0).isComposite()).isFalse(); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -295,7 +295,7 @@ void testDifferentTypeStopsCompositeCompression() { startExitSpan(t).withType("another_type").end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertCompositeSpan(reportedSpans.get(0), 2); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -312,7 +312,7 @@ void testDifferentSubtypeStopsRegularCompression() { startExitSpan(t).withSubtype("another_subtype").end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertThat(reportedSpans.get(0).isComposite()).isFalse(); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -330,7 +330,7 @@ void testDifferentSubtypeStopsCompositeCompression() { startExitSpan(t).withSubtype("another_subtype").end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertCompositeSpan(reportedSpans.get(0), 2); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -344,7 +344,7 @@ void testDifferentSubtypeStopsCompositeCompression() { void testSpanExceedingMaxDurationStopsRegularCompression() { runInTransactionScope(t -> { startExitSpan(t).end(); - Span span = startExitSpan(t); + SpanImpl span = startExitSpan(t); try { Thread.sleep(100); } catch (InterruptedException e) { @@ -353,7 +353,7 @@ void testSpanExceedingMaxDurationStopsRegularCompression() { span.end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertThat(reportedSpans.get(0).isComposite()).isFalse(); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -368,7 +368,7 @@ void testSpanExceedingMaxDurationStopsCompositeCompression() { runInTransactionScope(t -> { startExitSpan(t).end(); startExitSpan(t).end(); - Span span = startExitSpan(t); + SpanImpl span = startExitSpan(t); try { Thread.sleep(100); } catch (InterruptedException e) { @@ -377,7 +377,7 @@ void testSpanExceedingMaxDurationStopsCompositeCompression() { span.end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertCompositeSpan(reportedSpans.get(0), 2); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -391,7 +391,7 @@ void testSpanExceedingMaxDurationStopsCompositeCompression() { void testDifferentDestinationServiceResourceStopsRegularCompression() { runInTransactionScope(t -> { startExitSpan(t).end(); - Span span = startExitSpan(t); + SpanImpl span = startExitSpan(t); // set alternative resource from user API assertThat(span.getContext().getServiceTarget().withUserType(null).withUserName("another_resource").withNameOnlyDestinationResource()) @@ -401,7 +401,7 @@ void testDifferentDestinationServiceResourceStopsRegularCompression() { span.end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertThat(reportedSpans.get(0).isComposite()).isFalse(); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -416,10 +416,10 @@ void testDifferentDestinationServiceResourceStopsCompositeCompression() { runInTransactionScope(t -> { startExitSpan(t).end(); startExitSpan(t).end(); - Span span = startExitSpan(t); + SpanImpl span = startExitSpan(t); // set alternative resource from type - ServiceTarget serviceTarget = span.getContext().getServiceTarget(); + ServiceTargetImpl serviceTarget = span.getContext().getServiceTarget(); serviceTarget.resetState(); assertThat(serviceTarget.withType("another")) .hasType("another") @@ -428,7 +428,7 @@ void testDifferentDestinationServiceResourceStopsCompositeCompression() { span.end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertCompositeSpan(reportedSpans.get(0), 2); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -438,8 +438,8 @@ void testDifferentDestinationServiceResourceStopsCompositeCompression() { assertThat(spanCount.getDropped().get()).isEqualTo(1); } - protected static void runInTransactionScope(Consumer> r) { - Transaction transaction = tracer.startRootTransaction(null).withName("Some Transaction"); + protected static void runInTransactionScope(Consumer> r) { + TransactionImpl transaction = tracer.startRootTransaction(null).withName("Some Transaction"); try { r.accept(transaction); } finally { @@ -447,24 +447,24 @@ protected static void runInTransactionScope(Consumer> r) { } } - protected Span startExitSpan(AbstractSpan parent) { - Span span = startSpan(parent).asExit(); + protected SpanImpl startExitSpan(AbstractSpanImpl parent) { + SpanImpl span = startSpan(parent).asExit(); span.getContext().getServiceTarget().withType("service-type").withName("service-name"); return span; } - protected Span startSpan(AbstractSpan parent) { + protected SpanImpl startSpan(AbstractSpanImpl parent) { return parent.createSpan().withName(getSpanName()).withType("some_type").withSubtype("some_subtype"); } protected abstract String getSpanName(); - protected void assertCompositeSpan(Span span, int count) { + protected void assertCompositeSpan(SpanImpl span, int count) { assertThat(span.isComposite()).isTrue(); assertThat(span.getComposite().getCount()).isEqualTo(count); assertThat(span.getComposite().getCompressionStrategy()).isEqualTo(compressionStrategy); assertThat(span.getNameAsString()).isEqualTo(getCompositeSpanName(span)); } - protected abstract String getCompositeSpanName(Span span); + protected abstract String getCompositeSpanName(SpanImpl span); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/BaggageTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/BaggageTest.java index 1dbfe383eb..86e55f56b0 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/BaggageTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/BaggageTest.java @@ -20,16 +20,16 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; import co.elastic.apm.agent.impl.TextHeaderMapAccessor; import co.elastic.apm.agent.impl.baggage.BaggageContext; -import co.elastic.apm.agent.impl.context.TransactionContext; -import co.elastic.apm.agent.impl.error.ErrorCapture; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Scope; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -67,7 +67,7 @@ public void checkChildTransactionBaggageParsingWithTracestate() { headers.put("traceparent", "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); headers.put("baggage", "key1=val1,key2=val2"); - Transaction transaction = tracer.startChildTransaction(headers, TextHeaderMapAccessor.INSTANCE, null); + TransactionImpl transaction = tracer.startChildTransaction(headers, TextHeaderMapAccessor.INSTANCE, null); assertThat(transaction.getTraceContext()) .satisfies(tc -> assertThat(tc.getTraceId().toString()).isEqualTo("0af7651916cd43dd8448eb211c80319c")) .satisfies(tc -> Assertions.assertThat(tc.getParentId().toString()).isEqualTo("b9c7c989f97918e1")); @@ -82,7 +82,7 @@ public void checkChildTransactionBaggageParsingWithoutTracestate() { Map headers = new HashMap<>(); headers.put("baggage", "key1=val1,key2=val2"); - Transaction transaction = tracer.startChildTransaction(headers, TextHeaderMapAccessor.INSTANCE, null); + TransactionImpl transaction = tracer.startChildTransaction(headers, TextHeaderMapAccessor.INSTANCE, null); assertThat(transaction) .hasBaggageCount(2) .hasBaggage("key1", "val1") @@ -95,12 +95,12 @@ public void checkChildTransactionOverridesCurrentBaggage() { Map headers = new HashMap<>(); headers.put("baggage", "key1=val1"); - ElasticContext baggageContext = tracer.currentContext().withUpdatedBaggage() + TraceState baggageContext = tracer.currentContext().withUpdatedBaggage() .put("key1", "rootval1") .put("key2", "rootval2") .buildContext() .activate(); - Transaction transaction = tracer.startChildTransaction(headers, TextHeaderMapAccessor.INSTANCE, null); + TransactionImpl transaction = tracer.startChildTransaction(headers, TextHeaderMapAccessor.INSTANCE, null); baggageContext.deactivate(); @@ -112,12 +112,12 @@ public void checkChildTransactionOverridesCurrentBaggage() { @Test public void checkRootTransactionInheritsCurrentBaggage() { - ElasticContext baggageContext = tracer.currentContext().withUpdatedBaggage() + TraceState baggageContext = tracer.currentContext().withUpdatedBaggage() .put("key1", "rootval1") .put("key2", "rootval2") .buildContext() .activate(); - Transaction transaction = tracer.startRootTransaction(null); + TransactionImpl transaction = tracer.startRootTransaction(null); baggageContext.deactivate(); assertThat(transaction) @@ -129,10 +129,10 @@ public void checkRootTransactionInheritsCurrentBaggage() { @Test public void checkSpanInheritsParentBaggage() { - Transaction transaction; - Span span1, span2, span3, span4; + TransactionImpl transaction; + SpanImpl span1, span2, span3, span4; - ElasticContext baggage1 = tracer.currentContext().withUpdatedBaggage() + TraceState baggage1 = tracer.currentContext().withUpdatedBaggage() .put("key1", "rootval1") .put("key2", "rootval2") .buildContext(); @@ -142,7 +142,7 @@ public void checkSpanInheritsParentBaggage() { span1 = tracer.currentContext().createSpan(); - ElasticContext baggage2 = tracer.currentContext().withUpdatedBaggage() + TraceState baggage2 = tracer.currentContext().withUpdatedBaggage() .put("key1", "baggage2_override") .buildContext(); try (Scope sc2 = baggage2.activateInScope()) { @@ -153,7 +153,7 @@ public void checkSpanInheritsParentBaggage() { span3 = tracer.currentContext().createSpan(); - ElasticContext baggage3 = tracer.currentContext().withUpdatedBaggage() + TraceState baggage3 = tracer.currentContext().withUpdatedBaggage() .put("key3", "baggage3_override") .remove("key2") .buildContext(); @@ -194,7 +194,7 @@ public void checkSpanInheritsParentBaggage() { @Test public void checkBaggagePropagationWithoutTrace() { - ElasticContext baggage = tracer.currentContext().withUpdatedBaggage() + TraceState baggage = tracer.currentContext().withUpdatedBaggage() .put("key", "val") .buildContext(); @@ -217,12 +217,12 @@ public void checkBaggagePropagationWithoutTrace() { @Test public void checkBaggagePropagationFromTransaction() { - ElasticContext baggage = tracer.currentContext().withUpdatedBaggage() + TraceState baggage = tracer.currentContext().withUpdatedBaggage() .put("key", "val") .buildContext() .activate(); - Transaction transaction = tracer.startRootTransaction(null); + TransactionImpl transaction = tracer.startRootTransaction(null); baggage.deactivate(); @@ -239,13 +239,13 @@ public void checkBaggagePropagationFromTransaction() { @Test public void checkBaggagePropagationFromSpan() { - ElasticContext baggage = tracer.currentContext().withUpdatedBaggage() + TraceState baggage = tracer.currentContext().withUpdatedBaggage() .put("key", "val") .buildContext() .activate(); - Transaction transaction = tracer.startRootTransaction(null); - Span span = transaction.createSpan(); + TransactionImpl transaction = tracer.startRootTransaction(null); + SpanImpl span = transaction.createSpan(); baggage.deactivate(); @@ -265,17 +265,17 @@ public void checkBaggagePropagationFromSpan() { public void checkBaggageLiftingToAttributes() { doReturn(List.of(WildcardMatcher.valueOf("foo*"), WildcardMatcher.valueOf("bar*"))) - .when(config.getConfig(CoreConfiguration.class)).getBaggageToAttach(); + .when(config.getConfig(CoreConfigurationImpl.class)).getBaggageToAttach(); - ElasticContext baggage = tracer.currentContext().withUpdatedBaggage() + TraceState baggage = tracer.currentContext().withUpdatedBaggage() .put("foo.key", "foo_val") .put("ignore", "ignore") .buildContext() .activate(); - Transaction transaction = tracer.startRootTransaction(null); + TransactionImpl transaction = tracer.startRootTransaction(null); - Span span = transaction + SpanImpl span = transaction .withUpdatedBaggage() .put("foo.key", "foo_updated_val") .put("bar.key", "bar_val") @@ -298,16 +298,16 @@ public void checkBaggageLiftingToAttributes() { @Test void testStandaloneExceptionCapturesBaggage() { doReturn(List.of(WildcardMatcher.valueOf("foo*"), WildcardMatcher.valueOf("bar*"))) - .when(config.getConfig(CoreConfiguration.class)).getBaggageToAttach(); + .when(config.getConfig(CoreConfigurationImpl.class)).getBaggageToAttach(); BaggageContext parentCtx = tracer.currentContext().withUpdatedBaggage() .put("foo.bar", "foo_val") .put("ignoreme", "ignore") .buildContext(); - ErrorCapture errorCapture = tracer.captureException(new RuntimeException(), parentCtx, null); + ErrorCaptureImpl errorCapture = tracer.captureException(new RuntimeException(), parentCtx, null); - TransactionContext ctx = errorCapture.getContext(); + TransactionContextImpl ctx = errorCapture.getContext(); assertThat(ctx.getLabel("baggage.foo.bar")).isEqualTo("foo_val"); assertThat(ctx.getLabel("baggage.ignoreme")).isNull(); } @@ -316,9 +316,9 @@ void testStandaloneExceptionCapturesBaggage() { @Test void testExceptionInheritsBaggageFromParentSpan() { doReturn(List.of(WildcardMatcher.valueOf("foo*"), WildcardMatcher.valueOf("bar*"))) - .when(config.getConfig(CoreConfiguration.class)).getBaggageToAttach(); + .when(config.getConfig(CoreConfigurationImpl.class)).getBaggageToAttach(); - Span parentSpan = tracer.startRootTransaction(null) + SpanImpl parentSpan = tracer.startRootTransaction(null) .withUpdatedBaggage() .put("foo.bar", "foo_val") .put("ignoreme", "ignore") @@ -328,9 +328,9 @@ void testExceptionInheritsBaggageFromParentSpan() { parentSpan.captureException(new RuntimeException()); assertThat(mockReporter.getErrors()).hasSize(1); - ErrorCapture errorCapture = mockReporter.getErrors().get(0); + ErrorCaptureImpl errorCapture = mockReporter.getErrors().get(0); - TransactionContext ctx = errorCapture.getContext(); + TransactionContextImpl ctx = errorCapture.getContext(); assertThat(ctx.getLabel("baggage.foo.bar")).isEqualTo("foo_val"); assertThat(ctx.getLabel("baggage.ignoreme")).isNull(); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/ExactMatchCompressionStrategyTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/ExactMatchCompressionStrategyTest.java index 64ad5d4c42..f750f0a985 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/ExactMatchCompressionStrategyTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/ExactMatchCompressionStrategyTest.java @@ -46,7 +46,7 @@ void testDifferentNameStopsRegularCompression() { startExitSpan(t).withName("Another Name").end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertThat(reportedSpans.get(0).isComposite()).isFalse(); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -60,7 +60,7 @@ void testDifferentNameStopsCompositeCompression() { startExitSpan(t).withName("Another Name").end(); }); - List reportedSpans = reporter.getSpans(); + List reportedSpans = reporter.getSpans(); assertThat(reportedSpans).hasSize(2); assertCompositeSpan(reportedSpans.get(0), 2); assertThat(reportedSpans.get(1).isComposite()).isFalse(); @@ -72,7 +72,7 @@ protected String getSpanName() { } @Override - protected String getCompositeSpanName(Span span) { + protected String getCompositeSpanName(SpanImpl span) { return getSpanName(); } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/FastExitSpanTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/FastExitSpanTest.java index 47d3d45baf..44ae314789 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/FastExitSpanTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/FastExitSpanTest.java @@ -59,7 +59,7 @@ void resetReporter() { @Test void testExitSpanBelowDuration() { - Transaction transaction = startTransaction(); + TransactionImpl transaction = startTransaction(); try { // each combination of (outcome,service target type, service target name) should have its own bucket for (Outcome outcome : Outcome.values()) { @@ -67,7 +67,7 @@ void testExitSpanBelowDuration() { startExitSpan(transaction, 0L).withOutcome(outcome).end(49_999L); // with service target name - Span spanWithServiceTargetName = startExitSpan(transaction, 0L).withOutcome(outcome); + SpanImpl spanWithServiceTargetName = startExitSpan(transaction, 0L).withOutcome(outcome); spanWithServiceTargetName.getContext().getDb().withInstance("db-name"); spanWithServiceTargetName.end(49_999L); } @@ -99,15 +99,15 @@ void testExitSpanBelowDuration() { @Test void testCompositeExitSpanBelowDurationAndMoreThanOneDroppedSpanStatsEntry() { - Transaction transaction = startTransaction(); + TransactionImpl transaction = startTransaction(); try { - Span span = startExitSpan(transaction, 0L); + SpanImpl span = startExitSpan(transaction, 0L); span.end(10_000L); startExitSpan(transaction, 10_000L).end(20_000L); startExitSpan(transaction, 20_000L).end(30_000L); assertThat(span.isComposite()).isTrue(); //second span destination to ensure more than one dropped span stats entry - Span span2 = startExitSpan(transaction, 30_000L, "mysql"); + SpanImpl span2 = startExitSpan(transaction, 30_000L, "mysql"); span2.end(40_000L); startExitSpan(transaction, 40_000L, "mysql").end(50_000L); assertThat(span2.isComposite()).isTrue(); @@ -129,7 +129,7 @@ void testCompositeExitSpanBelowDurationAndMoreThanOneDroppedSpanStatsEntry() { @Test void testExitSpanAboveDuration() { - Transaction transaction = startTransaction(); + TransactionImpl transaction = startTransaction(); try { startExitSpan(transaction, 0L).end(50_001L); } finally { @@ -148,9 +148,9 @@ void testExitSpanAboveDuration() { @Test void testCompositeExitSpanAboveDuration() { - Transaction transaction = startTransaction(); + TransactionImpl transaction = startTransaction(); try { - Span span = startExitSpan(transaction, 0L); + SpanImpl span = startExitSpan(transaction, 0L); span.end(20_000L); startExitSpan(transaction, 20_000L).end(40_000L); startExitSpan(transaction, 40_000L).end(60_000L); @@ -170,16 +170,16 @@ void testCompositeExitSpanAboveDuration() { assertThat(droppedSpanStats.getStats("postgresql", null, Outcome.SUCCESS)).isNull(); } - private Transaction startTransaction() { + private TransactionImpl startTransaction() { return tracer.startRootTransaction(null).withName("Some Transaction"); } - protected Span startExitSpan(AbstractSpan parent, long startTimestamp) { + protected SpanImpl startExitSpan(AbstractSpanImpl parent, long startTimestamp) { return startExitSpan(parent, startTimestamp, "postgresql"); } - protected Span startExitSpan(AbstractSpan parent, long startTimestamp, String subtype) { - Span span = parent.createExitSpan().withName("Some Name").withType("db").withSubtype(subtype); + protected SpanImpl startExitSpan(AbstractSpanImpl parent, long startTimestamp, String subtype) { + SpanImpl span = parent.createExitSpan().withName("Some Name").withType("db").withSubtype(subtype); span.getContext().getDestination().withAddress("127.0.0.1").withPort(5432); span.setStartTimestamp(startTimestamp); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/IdTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/IdTest.java index dddc596a3f..734240c5ac 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/IdTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/IdTest.java @@ -26,7 +26,7 @@ class IdTest { @Test void testReInit() { - final Id id = Id.new64BitId(); + final IdImpl id = IdImpl.new64BitId(); id.fromHexString("0000000000000001", 0); assertThat(id.toString()).isEqualTo("0000000000000001"); @@ -39,7 +39,7 @@ void testReInit() { @Test void testReset() { - final Id id = Id.new64BitId(); + final IdImpl id = IdImpl.new64BitId(); id.fromHexString("0000000000000001", 0); assertThat(id.toString()).isEqualTo("0000000000000001"); @@ -52,7 +52,7 @@ void testReset() { @Test void testInitEmpty() { - final Id id = Id.new64BitId(); + final IdImpl id = IdImpl.new64BitId(); assertThat(id.toString()).isEqualTo("0000000000000000"); assertThat(id.isEmpty()).isTrue(); @@ -67,7 +67,7 @@ void testInitEmpty() { @Test void testFromAndToLong() { - final Id id = Id.new128BitId(); + final IdImpl id = IdImpl.new128BitId(); id.fromLongs(21, 42); assertThat(id.isEmpty()).isFalse(); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SameKindCompressionStrategyTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SameKindCompressionStrategyTest.java index bd8b2b1692..2f1e776cae 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SameKindCompressionStrategyTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SameKindCompressionStrategyTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.impl.transaction; -import co.elastic.apm.agent.impl.context.ServiceTarget; +import co.elastic.apm.agent.impl.context.ServiceTargetImpl; class SameKindCompressionStrategyTest extends AbstractCompressionStrategyTest { @@ -34,9 +34,9 @@ protected String getSpanName() { } @Override - protected String getCompositeSpanName(Span span) { + protected String getCompositeSpanName(SpanImpl span) { StringBuilder name = new StringBuilder().append("Calls to "); - ServiceTarget serviceTarget = span.getContext().getServiceTarget(); + ServiceTargetImpl serviceTarget = span.getContext().getServiceTarget(); name.append(serviceTarget.getType()); name.append("/"); name.append(serviceTarget.getName()); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SpanCompressionIT.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SpanCompressionIT.java index d83082b0b5..a4b2d43a59 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SpanCompressionIT.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SpanCompressionIT.java @@ -111,8 +111,8 @@ void testParallelNonCompressibleExitSpanCreationWithRecycling() { } - private static void runInTransactionScope(BiFunction, Integer, Runnable> r) { - Transaction transaction = tracer.startRootTransaction(null).withName("Some Transaction"); + private static void runInTransactionScope(BiFunction, Integer, Runnable> r) { + TransactionImpl transaction = tracer.startRootTransaction(null).withName("Some Transaction"); try { CompletableFuture[] tasks = new CompletableFuture[numberOfSpans]; for (int i = 0; i < numberOfSpans; ++i) { @@ -125,25 +125,25 @@ private static void runInTransactionScope(BiFunction, Integer, R } } - private static void createSpan(AbstractSpan parent, long startTimestamp, long endTimestamp) { - Span span = parent.createSpan().withName("Some Name").withType("app"); + private static void createSpan(AbstractSpanImpl parent, long startTimestamp, long endTimestamp) { + SpanImpl span = parent.createSpan().withName("Some Name").withType("app"); span.setStartTimestamp(startTimestamp); span.end(endTimestamp); } - private static void createExitSpan(AbstractSpan parent, long startTimestamp, long endTimestamp, String subtype) { - Span span = parent.createSpan().asExit().withName("Some Other Name").withType("db").withSubtype(subtype); + private static void createExitSpan(AbstractSpanImpl parent, long startTimestamp, long endTimestamp, String subtype) { + SpanImpl span = parent.createSpan().asExit().withName("Some Other Name").withType("db").withSubtype(subtype); span.getContext().getDestination().withAddress("127.0.0.1").withPort(5432); span.setStartTimestamp(startTimestamp); span.end(endTimestamp); } - private static void assertReportedSpans(List reportedSpans) { + private static void assertReportedSpans(List reportedSpans) { int numberOfReportedSpans = reportedSpans.stream() .mapToInt(s -> s.isComposite() ? s.getComposite().getCount() : 1) .sum(); assertThat(numberOfReportedSpans).isEqualTo(numberOfReportedSpans); - assertThat(reportedSpans).filteredOn(Span::isComposite) + assertThat(reportedSpans).filteredOn(SpanImpl::isComposite) .allSatisfy(span -> { int numberOfCompositeSpans = span.getComposite().getCount(); assertThat(span.getDuration()).isGreaterThanOrEqualTo(1000L + numberOfCompositeSpans - 1L); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SpanTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SpanTest.java index 7b7bbae19b..6e571b0570 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SpanTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/SpanTest.java @@ -22,7 +22,7 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.TextHeaderMapAccessor; import co.elastic.apm.agent.impl.Utf8HeaderMapAccessor; -import co.elastic.apm.agent.impl.baggage.Baggage; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; import co.elastic.apm.agent.impl.sampling.ConstantSampler; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import co.elastic.apm.agent.tracer.Outcome; @@ -51,7 +51,7 @@ void setUp() { @Test void resetState() { - Span span = new Span(tracer) + SpanImpl span = new SpanImpl(tracer) .withName("SELECT FROM product_types") .withType("db") .withSubtype("postgresql") @@ -72,9 +72,9 @@ void resetState() { @Test void testOutcomeExplicitlyToUnknown() { - Transaction transaction = tracer.startRootTransaction(null); + TransactionImpl transaction = tracer.startRootTransaction(null); assertThat(transaction).isNotNull(); - Span span = transaction.createSpan() + SpanImpl span = transaction.createSpan() .withName("SELECT FROM product_types") .withType("db") .withSubtype("postgresql") @@ -89,7 +89,7 @@ void testOutcomeExplicitlyToUnknown() { @Test void normalizeEmptyFields() { - Span span = new Span(tracer) + SpanImpl span = new SpanImpl(tracer) .withName("span"); assertThat(span.withType("").getType()).isNull(); @@ -101,11 +101,11 @@ void normalizeEmptyFields() { @MethodSource("typeTestArguments") void normalizeType(String type, String expectedType) { - Transaction transaction = new Transaction(tracer); - transaction.startRoot(0, ConstantSampler.of(true), Baggage.EMPTY); + TransactionImpl transaction = new TransactionImpl(tracer); + transaction.startRoot(0, ConstantSampler.of(true), BaggageImpl.EMPTY); try { - Span span = new Span(tracer); - span.start(TraceContext.fromParent(), transaction, Baggage.EMPTY, -1L); + SpanImpl span = new SpanImpl(tracer); + span.start(TraceContextImpl.fromParent(), transaction, BaggageImpl.EMPTY, -1L); assertThat(span.getType()) .describedAs("span type should not be set by default") .isNull(); @@ -129,12 +129,12 @@ static Stream typeTestArguments() { @Test void testSpanLinks() { TestObjectPoolFactory objectPoolFactory = (TestObjectPoolFactory) tracer.getObjectPoolFactory(); - Transaction transaction = tracer.startRootTransaction(null); - Span testSpan = Objects.requireNonNull(transaction).createSpan(); + TransactionImpl transaction = tracer.startRootTransaction(null); + SpanImpl testSpan = Objects.requireNonNull(transaction).createSpan(); assertThat(objectPoolFactory.getSpanLinksPool().getObjectsInPool()).isEqualTo(0); assertThat(objectPoolFactory.getSpanLinksPool().getRequestedObjectCount()).isEqualTo(0); assertThat(testSpan.getSpanLinks()).isEmpty(); - Span parent1 = transaction.createSpan(); + SpanImpl parent1 = transaction.createSpan(); Map textTraceContextCarrier = new HashMap<>(); parent1.propagateContext(textTraceContextCarrier, TextHeaderMapAccessor.INSTANCE, null); assertThat(testSpan.addSpanLink( @@ -144,7 +144,7 @@ void testSpanLinks() { assertThat(objectPoolFactory.getSpanLinksPool().getObjectsInPool()).isEqualTo(0); assertThat(objectPoolFactory.getSpanLinksPool().getRequestedObjectCount()).isEqualTo(1); assertThat(testSpan.getSpanLinks()).hasSize(1); - Span parent2 = transaction.createSpan(); + SpanImpl parent2 = transaction.createSpan(); Map utfTraceContextCarrier = new HashMap<>(); parent2.propagateContext(utfTraceContextCarrier, Utf8HeaderMapAccessor.INSTANCE, null); assertThat(testSpan.addSpanLink( @@ -153,7 +153,7 @@ void testSpanLinks() { ).isTrue(); assertThat(objectPoolFactory.getSpanLinksPool().getObjectsInPool()).isEqualTo(0); assertThat(objectPoolFactory.getSpanLinksPool().getRequestedObjectCount()).isEqualTo(2); - List spanLinks = testSpan.getSpanLinks(); + List spanLinks = testSpan.getSpanLinks(); assertThat(spanLinks).hasSize(2); assertThat(spanLinks.get(0).getTraceId()).isEqualTo(parent1.getTraceContext().getTraceId()); assertThat(spanLinks.get(0).getParentId()).isEqualTo(parent1.getTraceContext().getId()); @@ -166,10 +166,10 @@ void testSpanLinks() { @Test void testSpanLinksUniqueness() { - Transaction transaction = tracer.startRootTransaction(null); - Span testSpan = Objects.requireNonNull(transaction).createSpan(); + TransactionImpl transaction = tracer.startRootTransaction(null); + SpanImpl testSpan = Objects.requireNonNull(transaction).createSpan(); assertThat(testSpan.getSpanLinks()).isEmpty(); - Span parent1 = transaction.createSpan(); + SpanImpl parent1 = transaction.createSpan(); Map textTraceContextCarrier = new HashMap<>(); parent1.propagateContext(textTraceContextCarrier, TextHeaderMapAccessor.INSTANCE, null); assertThat(testSpan.addSpanLink( @@ -195,11 +195,11 @@ void testSpanLinksUniqueness() { } /** - * A utility to enable arbitrary tests to set an existing {@link Span} state without making this functionality globally accessible + * A utility to enable arbitrary tests to set an existing {@link SpanImpl} state without making this functionality globally accessible * @param recorded should the provided trace context be recorded * @param span a span of which state is to be set */ - public static void setRecorded(boolean recorded, Span span) { + public static void setRecorded(boolean recorded, SpanImpl span) { span.getTraceContext().setRecorded(recorded); } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextTest.java index e1f5c0a1d1..0425a58567 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextTest.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; @@ -66,18 +66,18 @@ public void setup() { /** * Test flow: * 1. create a parent context from a fixed string - * 2. create a child based on the string header - test {@link TraceContext#asChildOf(String)} - * 3. create a grandchild based on byte[] utf8 header - test {@link TraceContext#propagateTraceContext(Object, HeaderSetter)} - * and {@link TraceContext#asChildOf(Object, HeaderGetter, boolean)} with utf8 encoded byte[]s - * 4. create a second grandchild based on text header - test both {@link TraceContext#getOutgoingTraceParentTextHeader()} - * and {@link TraceContext#asChildOf(String)} + * 2. create a child based on the string header - test {@link TraceContextImpl#asChildOf(String)} + * 3. create a grandchild based on byte[] utf8 header - test {@link TraceContextImpl#propagateTraceContext(Object, HeaderSetter)} + * and {@link TraceContextImpl#asChildOf(Object, HeaderGetter, boolean)} with utf8 encoded byte[]s + * 4. create a second grandchild based on text header - test both {@link TraceContextImpl#getOutgoingTraceParentTextHeader()} + * and {@link TraceContextImpl#asChildOf(String)} * * @param flagsValue tested flags * @param isSampled whether to test context propagation of sampled trace or not */ private void mixTextAndBinaryParsingAndContextPropagation(String flagsValue, boolean isSampled) { - Map textHeaderMap = Map.of(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-" + flagsValue); - final TraceContext child = TraceContext.with64BitId(tracer); + Map textHeaderMap = Map.of(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-" + flagsValue); + final TraceContextImpl child = TraceContextImpl.with64BitId(tracer); assertThat(child.asChildOf(textHeaderMap, TextHeaderMapAccessor.INSTANCE)).isTrue(); assertThat(child.getTraceId().toString()).isEqualTo("0af7651916cd43dd8448eb211c80319c"); assertThat(child.getParentId().toString()).isEqualTo("b9c7c989f97918e1"); @@ -85,7 +85,7 @@ private void mixTextAndBinaryParsingAndContextPropagation(String flagsValue, boo assertThat(child.isSampled()).isEqualTo(isSampled); // create a grandchild to ensure proper regenerated trace context - final TraceContext grandchild1 = TraceContext.with64BitId(tracer); + final TraceContextImpl grandchild1 = TraceContextImpl.with64BitId(tracer); final Map binaryHeaderMap = new HashMap<>(); child.propagateTraceContext(binaryHeaderMap, Utf8HeaderMapAccessor.INSTANCE); assertThat(grandchild1.asChildOf(binaryHeaderMap, Utf8HeaderMapAccessor.INSTANCE)).isTrue(); @@ -96,7 +96,7 @@ private void mixTextAndBinaryParsingAndContextPropagation(String flagsValue, boo String childHeader = child.getOutgoingTraceParentTextHeader().toString(); assertThat(childHeader).endsWith("-" + flagsValue); - final TraceContext grandchild2 = TraceContext.with64BitId(tracer); + final TraceContextImpl grandchild2 = TraceContextImpl.with64BitId(tracer); assertThat(grandchild2.asChildOf(childHeader)).isTrue(); assertThat(grandchild2.getTraceId().toString()).isEqualTo("0af7651916cd43dd8448eb211c80319c"); assertThat(grandchild2.getParentId().toString()).isEqualTo(child.getId().toString()); @@ -121,8 +121,8 @@ void parseFromTraceParentHeaderUnsupportedFlag() { @Test void testChildOfElasticTraceparentHeader() { - Map textHeaderMap = Map.of(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); - final TraceContext child = TraceContext.with64BitId(tracer); + Map textHeaderMap = Map.of(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); + final TraceContextImpl child = TraceContextImpl.with64BitId(tracer); assertThat(child.asChildOf(textHeaderMap, TextHeaderMapAccessor.INSTANCE)).isTrue(); assertThat(child.getTraceId().toString()).isEqualTo("0af7651916cd43dd8448eb211c80319c"); assertThat(child.getParentId().toString()).isEqualTo("b9c7c989f97918e1"); @@ -133,10 +133,10 @@ void testChildOfElasticTraceparentHeader() { @Test void testW3CTraceparentHeaderPrecedence() { Map textHeaderMap = Map.of( - TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-00", - TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-dd8448eb211c80319c0af7651916cd43-f97918e1b9c7c989-01" + TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-00", + TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-dd8448eb211c80319c0af7651916cd43-f97918e1b9c7c989-01" ); - final TraceContext child = TraceContext.with64BitId(tracer); + final TraceContextImpl child = TraceContextImpl.with64BitId(tracer); assertThat(child.asChildOf(textHeaderMap, TextHeaderMapAccessor.INSTANCE)).isTrue(); assertThat(child.getTraceId().toString()).isEqualTo("0af7651916cd43dd8448eb211c80319c"); assertThat(child.getParentId().toString()).isEqualTo("b9c7c989f97918e1"); @@ -147,11 +147,11 @@ void testW3CTraceparentHeaderPrecedence() { @Test void testInvalidElasticTraceparentHeader() { Map textHeaderMap = Map.of( - TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01", + TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01", // one char too short trace ID - TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-d8448eb211c80319c0af7651916cd43-f97918e1b9c7c989-00" + TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-d8448eb211c80319c0af7651916cd43-f97918e1b9c7c989-00" ); - final TraceContext child = TraceContext.with64BitId(tracer); + final TraceContextImpl child = TraceContextImpl.with64BitId(tracer); assertThat(child.asChildOf(textHeaderMap, TextHeaderMapAccessor.INSTANCE)).isTrue(); // we should fallback to try the W3C header assertThat(child.getTraceId().toString()).isEqualTo("0af7651916cd43dd8448eb211c80319c"); @@ -162,39 +162,39 @@ void testInvalidElasticTraceparentHeader() { @Test void testElasticTraceparentHeaderDisabled() { - Map textHeaderMap = Map.of(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); - final TraceContext child = TraceContext.with64BitId(tracer); + Map textHeaderMap = Map.of(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); + final TraceContextImpl child = TraceContextImpl.with64BitId(tracer); assertThat(child.asChildOf(textHeaderMap, TextHeaderMapAccessor.INSTANCE)).isTrue(); Map outgoingHeaders = new HashMap<>(); - doReturn(false).when(config.getConfig(CoreConfiguration.class)).isElasticTraceparentHeaderEnabled(); + doReturn(false).when(config.getConfig(CoreConfigurationImpl.class)).isElasticTraceparentHeaderEnabled(); child.propagateTraceContext(outgoingHeaders, TextHeaderMapAccessor.INSTANCE); - assertThat(outgoingHeaders.get(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotNull(); - assertThat(outgoingHeaders.get(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNull(); + assertThat(outgoingHeaders.get(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotNull(); + assertThat(outgoingHeaders.get(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNull(); } @Test void testTraceContextTextHeadersRemoval() { Map headerMap = new HashMap<>(); - headerMap.put(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); - headerMap.put(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); - headerMap.put(TraceContext.TRACESTATE_HEADER_NAME, "foo=bar,baz=qux"); - TraceContext.removeTraceContextHeaders(headerMap, TextHeaderMapAccessor.INSTANCE); - assertThat(headerMap.get(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNull(); - assertThat(headerMap.get(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNull(); - assertThat(headerMap.get(TraceContext.TRACESTATE_HEADER_NAME)).isNull(); + headerMap.put(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); + headerMap.put(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); + headerMap.put(TraceContextImpl.TRACESTATE_HEADER_NAME, "foo=bar,baz=qux"); + TraceContextImpl.removeTraceContextHeaders(headerMap, TextHeaderMapAccessor.INSTANCE); + assertThat(headerMap.get(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNull(); + assertThat(headerMap.get(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNull(); + assertThat(headerMap.get(TraceContextImpl.TRACESTATE_HEADER_NAME)).isNull(); } @Test void testTraceContextHeadersCopy() { Map original = new HashMap<>(); - original.put(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); - original.put(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); - original.put(TraceContext.TRACESTATE_HEADER_NAME, "foo=bar,baz=qux"); + original.put(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); + original.put(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); + original.put(TraceContextImpl.TRACESTATE_HEADER_NAME, "foo=bar,baz=qux"); Map copy = new HashMap<>(); - TraceContext.copyTraceContextTextHeaders(original, TextHeaderMapAccessor.INSTANCE, copy, TextHeaderMapAccessor.INSTANCE); - assertThat(copy.get(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotNull(); - assertThat(copy.get(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotNull(); - assertThat(copy.get(TraceContext.TRACESTATE_HEADER_NAME)).isNotNull(); + TraceContextImpl.copyTraceContextTextHeaders(original, TextHeaderMapAccessor.INSTANCE, copy, TextHeaderMapAccessor.INSTANCE); + assertThat(copy.get(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotNull(); + assertThat(copy.get(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotNull(); + assertThat(copy.get(TraceContextImpl.TRACESTATE_HEADER_NAME)).isNotNull(); } @Test @@ -203,7 +203,7 @@ void testTracestateHeader() { incomingHeaders.add("traceparent", "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); incomingHeaders.add("tracestate", "foo=bar"); incomingHeaders.add("tracestate", "baz=qux,quux=quuz"); - final TraceContext child = TraceContext.with64BitId(tracer); + final TraceContextImpl child = TraceContextImpl.with64BitId(tracer); assertThat(child.asChildOf(incomingHeaders, MultiValueMapAccessor.INSTANCE)).isTrue(); assertThat(child.getTraceId().toString()).isEqualTo("0af7651916cd43dd8448eb211c80319c"); assertThat(child.getParentId().toString()).isEqualTo("b9c7c989f97918e1"); @@ -212,43 +212,43 @@ void testTracestateHeader() { PotentiallyMultiValuedMap outgoingHeaders = new PotentiallyMultiValuedMap(); child.propagateTraceContext(outgoingHeaders, MultiValueMapAccessor.INSTANCE); assertThat(outgoingHeaders.size()).isEqualTo(3); - assertThat(outgoingHeaders.getFirst(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotNull(); - assertThat(outgoingHeaders.getAll(TraceContext.TRACESTATE_HEADER_NAME)).hasSize(1); - assertThat(outgoingHeaders.getFirst(TraceContext.TRACESTATE_HEADER_NAME)).isEqualTo("foo=bar,baz=qux,quux=quuz"); + assertThat(outgoingHeaders.getFirst(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotNull(); + assertThat(outgoingHeaders.getAll(TraceContextImpl.TRACESTATE_HEADER_NAME)).hasSize(1); + assertThat(outgoingHeaders.getFirst(TraceContextImpl.TRACESTATE_HEADER_NAME)).isEqualTo("foo=bar,baz=qux,quux=quuz"); } @Test void testTracestateHeaderSizeLimit() { - doReturn(20).when(config.getConfig(CoreConfiguration.class)).getTracestateSizeLimit(); + doReturn(20).when(config.getConfig(CoreConfigurationImpl.class)).getTracestateSizeLimit(); PotentiallyMultiValuedMap incomingHeaders = new PotentiallyMultiValuedMap(); incomingHeaders.add("traceparent", "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); incomingHeaders.add("tracestate", "foo=bar"); incomingHeaders.add("tracestate", "baz=qux,quux=quuz"); - final TraceContext child = TraceContext.with64BitId(tracer); + final TraceContextImpl child = TraceContextImpl.with64BitId(tracer); assertThat(child.asChildOf(incomingHeaders, MultiValueMapAccessor.INSTANCE)).isTrue(); PotentiallyMultiValuedMap outgoingHeaders = new PotentiallyMultiValuedMap(); child.propagateTraceContext(outgoingHeaders, MultiValueMapAccessor.INSTANCE); assertThat(outgoingHeaders.size()).isEqualTo(3); - assertThat(outgoingHeaders.getFirst(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotNull(); - assertThat(outgoingHeaders.getAll(TraceContext.TRACESTATE_HEADER_NAME)).hasSize(1); - assertThat(outgoingHeaders.getFirst(TraceContext.TRACESTATE_HEADER_NAME)).isEqualTo("foo=bar,baz=qux"); + assertThat(outgoingHeaders.getFirst(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotNull(); + assertThat(outgoingHeaders.getAll(TraceContextImpl.TRACESTATE_HEADER_NAME)).hasSize(1); + assertThat(outgoingHeaders.getFirst(TraceContextImpl.TRACESTATE_HEADER_NAME)).isEqualTo("foo=bar,baz=qux"); } @Test void testNoTracestateWhenInvalidTraceparentHeader() { Map textHeaderMap = Map.of( // one char too short trace ID - TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-d8448eb211c80319c0af7651916cd43-f97918e1b9c7c989-00", - TraceContext.TRACESTATE_HEADER_NAME, "foo=bar,baz=qux" + TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-d8448eb211c80319c0af7651916cd43-f97918e1b9c7c989-00", + TraceContextImpl.TRACESTATE_HEADER_NAME, "foo=bar,baz=qux" ); - final TraceContext child = TraceContext.with64BitId(tracer); + final TraceContextImpl child = TraceContextImpl.with64BitId(tracer); assertThat(child.asChildOf(textHeaderMap, TextHeaderMapAccessor.INSTANCE)).isFalse(); assertThat(child.isRecorded()).isFalse(); Map outgoingHeaders = new HashMap<>(); child.propagateTraceContext(outgoingHeaders, TextHeaderMapAccessor.INSTANCE); - assertThat(outgoingHeaders.get(TraceContext.TRACESTATE_HEADER_NAME)).isNull(); + assertThat(outgoingHeaders.get(TraceContextImpl.TRACESTATE_HEADER_NAME)).isNull(); } private void verifyTraceContextContents(String traceContext, String expectedTraceId, String expectedParentId, @@ -262,7 +262,7 @@ private void verifyTraceContextContents(String traceContext, String expectedTrac @Test void outgoingHeader() { - final TraceContext traceContext = TraceContext.with64BitId(tracer); + final TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); final String header = "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-03"; assertThat(traceContext.asChildOf(header)).isTrue(); String parentId = traceContext.getId().toString(); @@ -270,13 +270,13 @@ void outgoingHeader() { "0af7651916cd43dd8448eb211c80319c", parentId, "00", "03"); Map headerMap = new HashMap<>(); traceContext.propagateTraceContext(headerMap, Utf8HeaderMapAccessor.INSTANCE); - verifyTraceContextContents(headerMap.get(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME), + verifyTraceContextContents(headerMap.get(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME), "0af7651916cd43dd8448eb211c80319c", parentId, "00", "03"); } @Test void outgoingHeaderRootSpan() { - final TraceContext traceContext = TraceContext.with64BitId(tracer); + final TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); traceContext.asRootSpan(ConstantSampler.of(true)); assertThat(traceContext.isSampled()).isTrue(); String outgoingStringHeader = traceContext.getOutgoingTraceParentTextHeader().toString(); @@ -285,13 +285,13 @@ void outgoingHeaderRootSpan() { traceContext.getId().toString(), "00", "01"); Map headerMap = new HashMap<>(); traceContext.propagateTraceContext(headerMap, Utf8HeaderMapAccessor.INSTANCE); - verifyTraceContextContents(headerMap.get(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME), traceContext.getTraceId().toString(), + verifyTraceContextContents(headerMap.get(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME), traceContext.getTraceId().toString(), traceContext.getId().toString(), "00", "01"); } @Test void parseFromTraceParentHeader_notSampled() { - final TraceContext traceContext = TraceContext.with64BitId(tracer); + final TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); final String header = "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-00"; assertThat(traceContext.asChildOf(header)).isTrue(); assertThat(traceContext.isSampled()).isFalse(); @@ -300,7 +300,7 @@ void parseFromTraceParentHeader_notSampled() { @Test void testResetState() { - final TraceContext traceContext = TraceContext.with64BitId(tracer); + final TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); traceContext.asChildOf("00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-00"); traceContext.resetState(); assertThat(traceContext.getIncomingTraceParentHeader()).isEqualTo("00-00000000000000000000000000000000-0000000000000000-00"); @@ -308,7 +308,7 @@ void testResetState() { @Test void testResetOutgoingTextHeader() { - final TraceContext traceContext = TraceContext.with64BitId(tracer); + final TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); String traceParentHeader = traceContext.getOutgoingTraceParentTextHeader().toString(); traceContext.asChildOf("00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-00"); assertThat(traceContext.getOutgoingTraceParentTextHeader().toString()).isNotEqualTo(traceParentHeader); @@ -317,14 +317,14 @@ void testResetOutgoingTextHeader() { @Test void testCopyFrom() { Map textHeaderMap = Map.of( - TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01", - TraceContext.TRACESTATE_HEADER_NAME, "foo=bar,baz=qux" + TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01", + TraceContextImpl.TRACESTATE_HEADER_NAME, "foo=bar,baz=qux" ); - final TraceContext first = TraceContext.with64BitId(tracer); + final TraceContextImpl first = TraceContextImpl.with64BitId(tracer); assertThat(first.asChildOf(textHeaderMap, TextHeaderMapAccessor.INSTANCE)).isTrue(); - textHeaderMap = Map.of(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-8448ebb9c7c989f97918e11916cd43dd-211c80319c0af765-00"); - final TraceContext second = TraceContext.with64BitId(tracer); + textHeaderMap = Map.of(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-8448ebb9c7c989f97918e11916cd43dd-211c80319c0af765-00"); + final TraceContextImpl second = TraceContextImpl.with64BitId(tracer); assertThat(second.asChildOf(textHeaderMap, TextHeaderMapAccessor.INSTANCE)).isTrue(); assertThat(first.getTraceId()).isNotEqualTo(second.getTraceId()); @@ -333,9 +333,9 @@ void testCopyFrom() { assertThat(first.getOutgoingTraceParentTextHeader()).isNotEqualTo(second.getOutgoingTraceParentTextHeader()); Map binaryHeaderMap = new HashMap<>(); first.propagateTraceContext(binaryHeaderMap, Utf8HeaderMapAccessor.INSTANCE); - String firstOutgoingHeader = binaryHeaderMap.get(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME); + String firstOutgoingHeader = binaryHeaderMap.get(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME); second.propagateTraceContext(binaryHeaderMap, Utf8HeaderMapAccessor.INSTANCE); - assertThat(binaryHeaderMap.get(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotEqualTo(firstOutgoingHeader); + assertThat(binaryHeaderMap.get(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isNotEqualTo(firstOutgoingHeader); second.copyFrom(first); assertThat(first.getTraceId()).isEqualTo(second.getTraceId()); @@ -343,39 +343,39 @@ void testCopyFrom() { assertThat(first.isSampled()).isEqualTo(second.isSampled()); assertThat(first.getOutgoingTraceParentTextHeader().toString()).isEqualTo(second.getOutgoingTraceParentTextHeader().toString()); second.propagateTraceContext(binaryHeaderMap, Utf8HeaderMapAccessor.INSTANCE); - assertThat(binaryHeaderMap.get(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isEqualTo(firstOutgoingHeader); + assertThat(binaryHeaderMap.get(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME)).isEqualTo(firstOutgoingHeader); } @Test void testAsChildOfHeaders() { Map textHeaderMap = Map.of( - TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01", - TraceContext.TRACESTATE_HEADER_NAME, "foo=bar,baz=qux" + TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01", + TraceContextImpl.TRACESTATE_HEADER_NAME, "foo=bar,baz=qux" ); - final TraceContext first = TraceContext.with64BitId(tracer); + final TraceContextImpl first = TraceContextImpl.with64BitId(tracer); assertThat(first.asChildOf(textHeaderMap, TextHeaderMapAccessor.INSTANCE)).isTrue(); - final TraceContext second = TraceContext.with64BitId(tracer); + final TraceContextImpl second = TraceContextImpl.with64BitId(tracer); second.asChildOf(first); HashMap textHeaders = new HashMap<>(); second.propagateTraceContext(textHeaders, TextHeaderMapAccessor.INSTANCE); - assertThat(textHeaders.get(TraceContext.TRACESTATE_HEADER_NAME)).isEqualTo("foo=bar,baz=qux"); - assertThat(textHeaders.get(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).startsWith("00-0af7651916cd43dd8448eb211c80319c-"); + assertThat(textHeaders.get(TraceContextImpl.TRACESTATE_HEADER_NAME)).isEqualTo("foo=bar,baz=qux"); + assertThat(textHeaders.get(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).startsWith("00-0af7651916cd43dd8448eb211c80319c-"); - final TraceContext firstUtf8 = TraceContext.with64BitId(tracer); + final TraceContextImpl firstUtf8 = TraceContextImpl.with64BitId(tracer); assertThat(firstUtf8.asChildOf(textHeaderMap, Utf8HeaderMapAccessor.INSTANCE)).isTrue(); HashMap utf8Headers = new HashMap<>(); firstUtf8.propagateTraceContext(utf8Headers, Utf8HeaderMapAccessor.INSTANCE); - assertThat(utf8Headers.get(TraceContext.TRACESTATE_HEADER_NAME)).isEqualTo("foo=bar,baz=qux"); - assertThat(utf8Headers.get(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).startsWith("00-0af7651916cd43dd8448eb211c80319c-"); + assertThat(utf8Headers.get(TraceContextImpl.TRACESTATE_HEADER_NAME)).isEqualTo("foo=bar,baz=qux"); + assertThat(utf8Headers.get(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME)).startsWith("00-0af7651916cd43dd8448eb211c80319c-"); } @Test void testRandomValue() { - final TraceContext traceContext = TraceContext.with64BitId(tracer); + final TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); traceContext.asRootSpan(ConstantSampler.of(true)); assertThat(traceContext.getTraceId().isEmpty()).isFalse(); assertThat(traceContext.getParentId().isEmpty()).isTrue(); @@ -384,7 +384,7 @@ void testRandomValue() { @Test void testSetSampled() { - final TraceContext traceContext = TraceContext.with64BitId(tracer); + final TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); traceContext.asRootSpan(ConstantSampler.of(false)); // not sampled means zero sample rate @@ -411,16 +411,16 @@ void testSetSampled() { @Test void testRootSpanShouldAddsSampleRateToTraceState() { - final TraceContext traceContext = createRootSpan(0.42d); + final TraceContextImpl traceContext = createRootSpan(0.42d); String traceState = traceContext.getTraceState().toTextHeader(); assertThat(traceState).isEqualTo("es=s:0.42"); } - private TraceContext createRootSpan(double sampleRate) { - final TraceContext traceContext = TraceContext.with64BitId(tracer); + private TraceContextImpl createRootSpan(double sampleRate) { + final TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); Sampler sampler = mock(Sampler.class); - doReturn(true).when(sampler).isSampled(any(Id.class)); + doReturn(true).when(sampler).isSampled(any(IdImpl.class)); doReturn(sampleRate).when(sampler).getSampleRate(); doReturn(TraceState.getHeaderValue(sampleRate)).when(sampler).getTraceStateHeader(); @@ -431,9 +431,9 @@ private TraceContext createRootSpan(double sampleRate) { @Test void testTracedChildSpanWithoutTraceState() { Map headers = Map.of( - TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01" + TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01" ); - TraceContext child = createChildSpanFromHeaders(headers); + TraceContextImpl child = createChildSpanFromHeaders(headers); assertThat(child.isSampled()).isTrue(); assertThat(child.getSampleRate()).isNaN(); @@ -442,9 +442,9 @@ void testTracedChildSpanWithoutTraceState() { @Test void testNonTracedChildSpanWithoutTraceState() { Map headers = Map.of( - TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-00" + TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-00" ); - TraceContext child = createChildSpanFromHeaders(headers); + TraceContextImpl child = createChildSpanFromHeaders(headers); assertThat(child.isSampled()).isFalse(); assertThat(child.getSampleRate()).isEqualTo(0.0d); @@ -466,12 +466,12 @@ void testNonTracedChildSpanWithoutTraceState() { }) void checkExpectedSampleRate(@Nullable String traceState, double expectedRate, @Nullable String expectedHeader) { Map headers = new HashMap<>(); - headers.put(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); + headers.put(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01"); if (null != traceState) { - headers.put(TraceContext.TRACESTATE_HEADER_NAME, traceState); + headers.put(TraceContextImpl.TRACESTATE_HEADER_NAME, traceState); } - TraceContext child = createChildSpanFromHeaders(headers); + TraceContextImpl child = createChildSpanFromHeaders(headers); assertThat(child.isSampled()).isTrue(); @@ -485,51 +485,51 @@ void checkExpectedSampleRate(@Nullable String traceState, double expectedRate, @ } - private TraceContext createChildSpanFromHeaders(Map inHeaders) { - TraceContext child = TraceContext.with64BitId(tracer); + private TraceContextImpl createChildSpanFromHeaders(Map inHeaders) { + TraceContextImpl child = TraceContextImpl.with64BitId(tracer); assertThat(child.asChildOf(inHeaders, TextHeaderMapAccessor.INSTANCE)).isTrue(); return child; } @Test void testPropagateTransactionIdForUnsampledSpan() { - final TraceContext rootContext = TraceContext.with64BitId(tracer); + final TraceContextImpl rootContext = TraceContextImpl.with64BitId(tracer); rootContext.asRootSpan(ConstantSampler.of(false)); - final TraceContext childContext = TraceContext.with64BitId(tracer); + final TraceContextImpl childContext = TraceContextImpl.with64BitId(tracer); childContext.asChildOf(rootContext); verifyTraceContextContents(childContext.getOutgoingTraceParentTextHeader().toString(), childContext.getTraceId().toString(), rootContext.getId().toString(), "00", "00"); Map binaryHeaderMap = new HashMap<>(); childContext.propagateTraceContext(binaryHeaderMap, Utf8HeaderMapAccessor.INSTANCE); - verifyTraceContextContents(binaryHeaderMap.get(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME), + verifyTraceContextContents(binaryHeaderMap.get(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME), childContext.getTraceId().toString(), rootContext.getId().toString(), "00", "00"); } @Test void testPropagateSpanIdForSampledSpan() { - final TraceContext rootContext = TraceContext.with64BitId(tracer); + final TraceContextImpl rootContext = TraceContextImpl.with64BitId(tracer); rootContext.asRootSpan(ConstantSampler.of(true)); - final TraceContext childContext = TraceContext.with64BitId(tracer); + final TraceContextImpl childContext = TraceContextImpl.with64BitId(tracer); childContext.asChildOf(rootContext); verifyTraceContextContents(childContext.getOutgoingTraceParentTextHeader().toString(), childContext.getTraceId().toString(), childContext.getId().toString(), "00", "01"); Map binaryHeaderMap = new HashMap<>(); childContext.propagateTraceContext(binaryHeaderMap, Utf8HeaderMapAccessor.INSTANCE); - verifyTraceContextContents(binaryHeaderMap.get(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME), + verifyTraceContextContents(binaryHeaderMap.get(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME), childContext.getTraceId().toString(), childContext.getId().toString(), "00", "01"); } @Test void testRootContextSampleRateFromSampler() { Sampler sampler = mock(Sampler.class); - doReturn(true).when(sampler).isSampled(any(Id.class)); + doReturn(true).when(sampler).isSampled(any(IdImpl.class)); doReturn(0.42d).when(sampler).getSampleRate(); - final TraceContext rootContext = TraceContext.with64BitId(tracer); + final TraceContextImpl rootContext = TraceContextImpl.with64BitId(tracer); rootContext.asRootSpan(sampler); assertThat(rootContext.isRecorded()).isTrue(); @@ -583,18 +583,18 @@ void testInvalidHeader_invalidTotalLength() { } private void assertInvalid(String s) { - final TraceContext traceContext = TraceContext.with64BitId(tracer); + final TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); assertThat(traceContext.asChildOf(s)).isFalse(); assertThat(traceContext.asChildOf(s.getBytes(StandardCharsets.UTF_8), CharAccessor.forAsciiBytes())).isFalse(); } private void assertValid(String s) { - TraceContext textTraceContext = TraceContext.with64BitId(tracer); + TraceContextImpl textTraceContext = TraceContextImpl.with64BitId(tracer); assertThat(textTraceContext.asChildOf(s)).isTrue(); verifyTraceContextContents(textTraceContext.getOutgoingTraceParentTextHeader().toString(), textTraceContext.getTraceId().toString(), textTraceContext.getId().toString(), "00", s.substring(53, 55)); - TraceContext utf8TraceContext = TraceContext.with64BitId(tracer); + TraceContextImpl utf8TraceContext = TraceContextImpl.with64BitId(tracer); assertThat(utf8TraceContext.asChildOf(s.getBytes(StandardCharsets.UTF_8), CharAccessor.forAsciiBytes())).isTrue(); verifyTraceContextContents(utf8TraceContext.getOutgoingTraceParentTextHeader().toString(), utf8TraceContext.getTraceId().toString(), utf8TraceContext.getId().toString(), "00", s.substring(53, 55)); @@ -603,16 +603,16 @@ private void assertValid(String s) { @Test void testDeserialization() { ElasticApmTracer tracer = MockTracer.create(); - CoreConfiguration configuration = tracer.getConfig(CoreConfiguration.class); + CoreConfigurationImpl configuration = tracer.getConfig(CoreConfigurationImpl.class); doReturn(Integer.MAX_VALUE).when(configuration).getTracestateSizeLimit(); - final TraceContext traceContext = TraceContext.with64BitId(tracer); + final TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); traceContext.asRootSpan(ConstantSampler.of(true)); - byte[] serializedContext = new byte[TraceContext.SERIALIZED_LENGTH]; + byte[] serializedContext = new byte[TraceContextImpl.SERIALIZED_LENGTH]; traceContext.serialize(serializedContext); - TraceContext deserialized = TraceContext.with64BitId(tracer); + TraceContextImpl deserialized = TraceContextImpl.with64BitId(tracer); deserialized.deserialize(serializedContext, null, null); assertThat(deserialized.traceIdAndIdEquals(serializedContext)).isTrue(); @@ -626,7 +626,7 @@ void testDeserialization() { @Test void testSetServiceInfoWithEmptyServiceName() { - TraceContext traceContext = TraceContext.with64BitId(tracer); + TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); traceContext.setServiceInfo(null, "My Version"); assertThat(traceContext.getServiceName()).isNull(); @@ -638,7 +638,7 @@ void testSetServiceInfoWithEmptyServiceName() { @Test void testSetServiceInfoWithNonEmptyServiceName() { - TraceContext traceContext = TraceContext.with64BitId(tracer); + TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); traceContext.setServiceInfo("My Service", null); assertThat(traceContext.getServiceName()).isEqualTo("My Service"); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextW3CTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextW3CTest.java index 914ff65aae..435ed04e2d 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextW3CTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContextW3CTest.java @@ -49,7 +49,7 @@ void testW3CData() { final boolean traceparentValid = testCase.get("is_traceparent_valid").booleanValue(); ElasticApmTracer tracer = MockTracer.create(); - final TraceContext traceContext = TraceContext.with64BitId(tracer); + final TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); softly.assertThat(traceContext.asChildOf(traceParentHeader)) .withFailMessage("Expected '%s' to be %s", traceParentHeader, traceparentValid ? "valid" : "invalid") .isEqualTo(traceparentValid); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContinuationStrategyTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContinuationStrategyTest.java index 5b42855a11..5da2ed629e 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContinuationStrategyTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TraceContinuationStrategyTest.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; @@ -66,37 +66,37 @@ static void setUp() { @Test void continueTraceFromNonElasticSystem() { - traceFromSystem(false, CoreConfiguration.TraceContinuationStrategy.CONTINUE, false); + traceFromSystem(false, CoreConfigurationImpl.TraceContinuationStrategy.CONTINUE, false); } @Test void continueTraceFromElasticSystem() { - traceFromSystem(true, CoreConfiguration.TraceContinuationStrategy.CONTINUE, false); + traceFromSystem(true, CoreConfigurationImpl.TraceContinuationStrategy.CONTINUE, false); } @Test void restartTraceFromNonElasticSystem() { - traceFromSystem(false, CoreConfiguration.TraceContinuationStrategy.RESTART, true); + traceFromSystem(false, CoreConfigurationImpl.TraceContinuationStrategy.RESTART, true); } @Test void restartTraceFromElasticSystem() { - traceFromSystem(true, CoreConfiguration.TraceContinuationStrategy.RESTART, true); + traceFromSystem(true, CoreConfigurationImpl.TraceContinuationStrategy.RESTART, true); } @Test void restartExternalTraceFromNonElasticSystem() { - traceFromSystem(false, CoreConfiguration.TraceContinuationStrategy.RESTART_EXTERNAL, true); + traceFromSystem(false, CoreConfigurationImpl.TraceContinuationStrategy.RESTART_EXTERNAL, true); } @Test void restartExternalTraceFromElasticSystem() { - traceFromSystem(true, CoreConfiguration.TraceContinuationStrategy.RESTART_EXTERNAL, false); + traceFromSystem(true, CoreConfigurationImpl.TraceContinuationStrategy.RESTART_EXTERNAL, false); } @Test void testAssumptions() { - Transaction transaction = new Transaction(tracerImpl); + TransactionImpl transaction = new TransactionImpl(tracerImpl); assertThat(transaction.getTraceContext().getParentId().toString()).isEqualTo("0000000000000000"); assertThat(transaction.getTraceContext().getId().toString()).isEqualTo("0000000000000000"); assertThat(transaction.getTraceContext().getTraceId().toString()).isEqualTo("00000000000000000000000000000000"); @@ -106,17 +106,17 @@ void testAssumptions() { assertThat(transaction.getTraceContext().getTraceId().toString()).isNotEqualTo("00000000000000000000000000000000"); } - void traceFromSystem(boolean fromElastic, CoreConfiguration.TraceContinuationStrategy strategy, boolean restartExpected) { - doReturn(strategy).when(tracerImpl.getConfig(CoreConfiguration.class)).getTraceContinuationStrategy(); + void traceFromSystem(boolean fromElastic, CoreConfigurationImpl.TraceContinuationStrategy strategy, boolean restartExpected) { + doReturn(strategy).when(tracerImpl.getConfig(CoreConfigurationImpl.class)).getTraceContinuationStrategy(); String traceID = "ca6150c33a473fda1f3a7a0b9eb4d143"; String parentSpanID = "abc345d9029d61ff"; final Map headerMap = new HashMap<>(); - headerMap.put(TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-"+traceID+"-"+parentSpanID+"-01"); + headerMap.put(TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-"+traceID+"-"+parentSpanID+"-01"); if (fromElastic) { - headerMap.put(TraceContext.TRACESTATE_HEADER_NAME, "es=s:1"); + headerMap.put(TraceContextImpl.TRACESTATE_HEADER_NAME, "es=s:1"); } - final Transaction transaction = tracerImpl.startChildTransaction(headerMap, TextHeaderMapAccessor.INSTANCE, ConstantSampler.of(false), 0, null); + final TransactionImpl transaction = tracerImpl.startChildTransaction(headerMap, TextHeaderMapAccessor.INSTANCE, ConstantSampler.of(false), 0, null); if (restartExpected) { assertThat(transaction.getTraceContext().getTraceId().toString()).isNotEqualTo(traceID); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TransactionTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TransactionTest.java index 8035ef3a0d..3f69986556 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TransactionTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/impl/transaction/TransactionTest.java @@ -20,12 +20,12 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.TransactionUtils; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.baggage.Baggage; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; import co.elastic.apm.agent.impl.metadata.MetaDataMock; import co.elastic.apm.agent.impl.sampling.ConstantSampler; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import co.elastic.apm.agent.report.serialize.SerializationConstants; @@ -49,11 +49,11 @@ public class TransactionTest { @BeforeEach void setUp() { - CoreConfiguration coreConfig = MockTracer.createRealTracer().getConfig(CoreConfiguration.class); + CoreConfigurationImpl coreConfig = MockTracer.createRealTracer().getConfig(CoreConfigurationImpl.class); SerializationConstants.init(coreConfig); jsonSerializer = new DslJsonSerializer( - mock(StacktraceConfiguration.class), + mock(StacktraceConfigurationImpl.class), mock(ApmServerClient.class), MetaDataMock.create() ).newWriter(); @@ -61,15 +61,15 @@ void setUp() { @Test void resetState() { - final Transaction transaction = new Transaction(MockTracer.create()); + final TransactionImpl transaction = new TransactionImpl(MockTracer.create()); TransactionUtils.fillTransaction(transaction); transaction.resetState(); - assertThat(jsonSerializer.toJsonString(transaction)).isEqualTo(jsonSerializer.toJsonString(new Transaction(MockTracer.create()))); + assertThat(jsonSerializer.toJsonString(transaction)).isEqualTo(jsonSerializer.toJsonString(new TransactionImpl(MockTracer.create()))); } @Test void getSetOutcome() { - Transaction transaction = new Transaction(MockTracer.create()); + TransactionImpl transaction = new TransactionImpl(MockTracer.create()); assertThat(transaction.getOutcome()) .describedAs("default outcome should be unknown") @@ -105,9 +105,9 @@ void getSetOutcome() { @ParameterizedTest @MethodSource("typeTestArguments") void normalizeType(String type, String expectedType) { - Transaction transaction = new Transaction(MockTracer.createRealTracer()); + TransactionImpl transaction = new TransactionImpl(MockTracer.createRealTracer()); - transaction.startRoot(0, ConstantSampler.of(true), Baggage.EMPTY); + transaction.startRoot(0, ConstantSampler.of(true), BaggageImpl.EMPTY); assertThat(transaction.getType()) .describedAs("transaction type should not be set by default") .isNull(); @@ -132,9 +132,9 @@ void skipChildSpanCreationWhenLimitReached() { int limit = 3; ElasticApmTracer tracer = MockTracer.createRealTracer(); - doReturn(limit).when(tracer.getConfig(CoreConfiguration.class)).getTransactionMaxSpans(); + doReturn(limit).when(tracer.getConfig(CoreConfigurationImpl.class)).getTransactionMaxSpans(); - Transaction transaction = tracer.startRootTransaction(TransactionTest.class.getClassLoader()); + TransactionImpl transaction = tracer.startRootTransaction(TransactionTest.class.getClassLoader()); assertThat(transaction).isNotNull(); transaction.activate(); @@ -172,11 +172,11 @@ void skipChildSpanCreationWhenLimitReached() { } /** - * A utility to enable arbitrary tests to set an existing {@link Transaction} state without making this functionality globally accessible + * A utility to enable arbitrary tests to set an existing {@link TransactionImpl} state without making this functionality globally accessible * @param recorded should the provided trace context be recorded * @param transaction a span of which state is to be set */ - public static void setRecorded(boolean recorded, Transaction transaction) { + public static void setRecorded(boolean recorded, TransactionImpl transaction) { transaction.getTraceContext().setRecorded(recorded); } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/logging/ApmServerLogAppenderTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/logging/ApmServerLogAppenderTest.java index 072885b5ed..0a6e35f78b 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/logging/ApmServerLogAppenderTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/logging/ApmServerLogAppenderTest.java @@ -84,7 +84,7 @@ void createAndInit() throws Exception { ApmServerReporter reporter = mock(ApmServerReporter.class); doReturn(reporter).when(tracer).getReporter(); - LoggingConfiguration config = tracer.getConfig(LoggingConfiguration.class); + LoggingConfigurationImpl config = tracer.getConfig(LoggingConfigurationImpl.class); doReturn(true).when(config).getSendLogs(); appender.getInitListener().init(tracer); @@ -117,7 +117,7 @@ void bufferingAndInit(boolean enabled) throws Exception { verifyNoInteractions(reporter); ElasticApmTracer tracer = MockTracer.create(); - LoggingConfiguration config = tracer.getConfig(LoggingConfiguration.class); + LoggingConfigurationImpl config = tracer.getConfig(LoggingConfigurationImpl.class); doReturn(enabled).when(config).getSendLogs(); doReturn(reporter).when(tracer).getReporter(); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/logging/LoggingConfigurationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/logging/LoggingConfigurationTest.java index 42fb36b746..0c691ffde7 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/logging/LoggingConfigurationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/logging/LoggingConfigurationTest.java @@ -53,7 +53,7 @@ import java.util.Map; import java.util.Objects; -import static co.elastic.apm.agent.logging.LoggingConfiguration.LOG_LEVEL_KEY; +import static co.elastic.apm.agent.logging.LoggingConfigurationImpl.LOG_LEVEL_KEY; import static org.assertj.core.api.Assertions.assertThat; @SuppressWarnings("NotNullFieldNotInitialized") diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/MetricRegistryTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/MetricRegistryTest.java index 5590fea3cc..b069f1e6f1 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/MetricRegistryTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/MetricRegistryTest.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.metrics; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.tracer.metrics.DoubleSupplier; import co.elastic.apm.agent.tracer.metrics.Labels; import org.junit.jupiter.api.BeforeEach; @@ -40,13 +40,13 @@ class MetricRegistryTest { private MetricRegistry metricRegistry; - private ReporterConfiguration reporterConfiguration; - private MetricsConfiguration metricsConfiguration; + private ReporterConfigurationImpl reporterConfiguration; + private MetricsConfigurationImpl metricsConfiguration; @BeforeEach void setUp() { - reporterConfiguration = mock(ReporterConfiguration.class); - metricsConfiguration = spy(MetricsConfiguration.class); + reporterConfiguration = mock(ReporterConfigurationImpl.class); + metricsConfiguration = spy(MetricsConfigurationImpl.class); metricRegistry = new MetricRegistry(reporterConfiguration, metricsConfiguration); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetricsTest.java index 093782f979..22f3f79746 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentOverheadMetricsTest.java @@ -18,12 +18,12 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.MetricSet; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.util.ExecutorUtils; import com.sun.management.ThreadMXBean; import org.junit.jupiter.api.BeforeEach; @@ -55,15 +55,15 @@ public class AgentOverheadMetricsTest { private MetricRegistry metricRegistry; - private ReporterConfiguration spyReporterConfig; - private MetricsConfiguration spyMetricsConfig; + private ReporterConfigurationImpl spyReporterConfig; + private MetricsConfigurationImpl spyMetricsConfig; private AgentOverheadMetrics overheadMetrics; @BeforeEach public void setUp() { - spyReporterConfig = spy(ReporterConfiguration.class); - spyMetricsConfig = spy(MetricsConfiguration.class); + spyReporterConfig = spy(ReporterConfigurationImpl.class); + spyMetricsConfig = spy(MetricsConfigurationImpl.class); overheadMetrics = new AgentOverheadMetrics(); metricRegistry = new MetricRegistry(spyReporterConfig, spyMetricsConfig); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetricsTest.java index 83527ffe6b..96be6d0918 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/AgentReporterMetricsTest.java @@ -18,12 +18,12 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.MetricSet; -import co.elastic.apm.agent.report.ReporterConfiguration; import co.elastic.apm.agent.report.ReportingEvent; import co.elastic.apm.agent.report.ReportingEventCounter; import org.junit.jupiter.api.BeforeEach; @@ -46,16 +46,16 @@ public class AgentReporterMetricsTest { private MetricRegistry metricRegistry; - private ReporterConfiguration mockReporterConfig; + private ReporterConfigurationImpl mockReporterConfig; - private MetricsConfiguration mockMetricsConfig; + private MetricsConfigurationImpl mockMetricsConfig; private AgentReporterMetrics reporterMetrics; @BeforeEach public void setUp() { - mockReporterConfig = mock(ReporterConfiguration.class); - mockMetricsConfig = spy(MetricsConfiguration.class); + mockReporterConfig = mock(ReporterConfigurationImpl.class); + mockMetricsConfig = spy(MetricsConfigurationImpl.class); metricRegistry = new MetricRegistry(mockReporterConfig, mockMetricsConfig); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/CGroupMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/CGroupMetricsTest.java index 5dd24ae174..8f50668d59 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/CGroupMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/CGroupMetricsTest.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; -import co.elastic.apm.agent.report.ReporterConfiguration; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -38,7 +38,7 @@ class CGroupMetricsTest { - private final MetricRegistry metricRegistry = new MetricRegistry(mock(ReporterConfiguration.class), spy(MetricsConfiguration.class)); + private final MetricRegistry metricRegistry = new MetricRegistry(mock(ReporterConfigurationImpl.class), spy(MetricsConfigurationImpl.class)); private CGroupMetrics createUnlimitedSystemMetrics() throws URISyntaxException, IOException { File mountInfo = new File(getClass().getResource("/proc/unlimited/memory").toURI()); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetricsTest.java index 3f87b5c70c..4d5de2bfaf 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmFdMetricsTest.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; -import co.elastic.apm.agent.report.ReporterConfiguration; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.condition.OS; @@ -44,7 +44,7 @@ class JvmFdMetricsTest { }) @DisabledOnOs(OS.WINDOWS) void testMetrics(String metric) { - MetricRegistry registry = new MetricRegistry(mock(ReporterConfiguration.class), spy(MetricsConfiguration.class)); + MetricRegistry registry = new MetricRegistry(mock(ReporterConfigurationImpl.class), spy(MetricsConfigurationImpl.class)); jvmFdMetrics.bindTo(registry); assertThat(registry.getGaugeValue(metric, Labels.EMPTY)) @@ -61,7 +61,7 @@ void testMetrics(String metric) { }) @EnabledOnOs(OS.WINDOWS) void testMetricsDisabledOnWindows(String metric) { - MetricRegistry registry = new MetricRegistry(mock(ReporterConfiguration.class), spy(MetricsConfiguration.class)); + MetricRegistry registry = new MetricRegistry(mock(ReporterConfigurationImpl.class), spy(MetricsConfigurationImpl.class)); jvmFdMetrics.bindTo(registry); assertThat(registry.getGauge(metric, Labels.EMPTY)).isNull(); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetricsTest.java index 413b148d5c..b36a6e3e2a 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/JvmMemoryMetricsTest.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; -import co.elastic.apm.agent.report.ReporterConfiguration; import org.assertj.core.api.AbstractDoubleAssert; import org.junit.jupiter.api.Test; @@ -42,7 +42,7 @@ class JvmMemoryMetricsTest { @Test void testMetrics() { - final MetricRegistry registry = new MetricRegistry(mock(ReporterConfiguration.class), spy(MetricsConfiguration.class)); + final MetricRegistry registry = new MetricRegistry(mock(ReporterConfigurationImpl.class), spy(MetricsConfigurationImpl.class)); jvmMemoryMetrics.bindTo(registry); Stream.of( diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/SystemMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/SystemMetricsTest.java index 3226241264..692b7affb8 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/SystemMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/SystemMetricsTest.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.OS; @@ -36,7 +36,7 @@ class SystemMetricsTest { - private MetricRegistry metricRegistry = new MetricRegistry(mock(ReporterConfiguration.class), spy(MetricsConfiguration.class)); + private MetricRegistry metricRegistry = new MetricRegistry(mock(ReporterConfigurationImpl.class), spy(MetricsConfigurationImpl.class)); private SystemMetrics systemMetrics = new SystemMetrics(); @Test diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/ThreadMetricsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/ThreadMetricsTest.java index 4fec12cf1a..c8afa7c992 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/ThreadMetricsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/metrics/builtin/ThreadMetricsTest.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.metrics.builtin; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricRegistry; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +32,7 @@ class ThreadMetricsTest { private static final double NUM_ADDED_THREADS = 12.0; private final ThreadMetrics threadMetrics = new ThreadMetrics(); - private MetricRegistry registry = new MetricRegistry(mock(ReporterConfiguration.class), spy(MetricsConfiguration.class)); + private MetricRegistry registry = new MetricRegistry(mock(ReporterConfigurationImpl.class), spy(MetricsConfigurationImpl.class)); @Test void testThreadCount() { diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/ObjectPoolTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/ObjectPoolTest.java index ee96d7841b..23ad800ef9 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/ObjectPoolTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/ObjectPoolTest.java @@ -27,7 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.SoftAssertions.assertSoftly; -public abstract class ObjectPoolTest> { +public abstract class ObjectPoolTest> { private static final int MAX_SIZE = 16; private T objectPool; diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestObjectPoolFactory.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestObjectPoolFactory.java index 72a2bfc5b3..ff85357cb1 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestObjectPoolFactory.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/TestObjectPoolFactory.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.objectpool; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.objectpool.impl.BookkeeperObjectPool; import co.elastic.apm.agent.tracer.pooling.Allocator; import co.elastic.apm.agent.tracer.pooling.Recyclable; @@ -36,17 +36,17 @@ /** * Extension of default pool factory that keeps track of all pools and thus allows to query their state while testing */ -public class TestObjectPoolFactory extends ObjectPoolFactory { +public class TestObjectPoolFactory extends ObjectPoolFactoryImpl { private final List> createdPools = new ArrayList>(); - private BookkeeperObjectPool transactionPool; - private BookkeeperObjectPool spanPool; - private BookkeeperObjectPool errorPool; - private BookkeeperObjectPool spanLinksPool; + private BookkeeperObjectPool transactionPool; + private BookkeeperObjectPool spanPool; + private BookkeeperObjectPool errorPool; + private BookkeeperObjectPool spanLinksPool; @Override - public ObjectPool createRecyclableObjectPool(int maxCapacity, Allocator allocator) { - ObjectPool pool = super.createRecyclableObjectPool(maxCapacity, allocator); + public ObservableObjectPool createRecyclableObjectPool(int maxCapacity, Allocator allocator) { + ObservableObjectPool pool = super.createRecyclableObjectPool(maxCapacity, allocator); BookkeeperObjectPool wrappedPool = new BookkeeperObjectPool<>(pool); createdPools.add(wrappedPool); return wrappedPool; @@ -95,42 +95,42 @@ public void reset() { } @Override - public ObjectPool createTransactionPool(int maxCapacity, ElasticApmTracer tracer) { - transactionPool = (BookkeeperObjectPool) super.createTransactionPool(maxCapacity, tracer); + public ObservableObjectPool createTransactionPool(int maxCapacity, ElasticApmTracer tracer) { + transactionPool = (BookkeeperObjectPool) super.createTransactionPool(maxCapacity, tracer); return transactionPool; } @Override - public ObjectPool createSpanPool(int maxCapacity, ElasticApmTracer tracer) { - spanPool = (BookkeeperObjectPool) super.createSpanPool(maxCapacity, tracer); + public ObservableObjectPool createSpanPool(int maxCapacity, ElasticApmTracer tracer) { + spanPool = (BookkeeperObjectPool) super.createSpanPool(maxCapacity, tracer); return spanPool; } @Override - public ObjectPool createErrorPool(int maxCapacity, ElasticApmTracer tracer) { - errorPool = (BookkeeperObjectPool) super.createErrorPool(maxCapacity, tracer); + public ObservableObjectPool createErrorPool(int maxCapacity, ElasticApmTracer tracer) { + errorPool = (BookkeeperObjectPool) super.createErrorPool(maxCapacity, tracer); return errorPool; } @Override - public ObjectPool createSpanLinkPool(int maxCapacity, ElasticApmTracer tracer) { - spanLinksPool = (BookkeeperObjectPool) super.createSpanLinkPool(maxCapacity, tracer); + public ObservableObjectPool createSpanLinkPool(int maxCapacity, ElasticApmTracer tracer) { + spanLinksPool = (BookkeeperObjectPool) super.createSpanLinkPool(maxCapacity, tracer); return spanLinksPool; } - public BookkeeperObjectPool getTransactionPool() { + public BookkeeperObjectPool getTransactionPool() { return transactionPool; } - public BookkeeperObjectPool getSpanPool() { + public BookkeeperObjectPool getSpanPool() { return spanPool; } - public BookkeeperObjectPool getErrorPool() { + public BookkeeperObjectPool getErrorPool() { return errorPool; } - public BookkeeperObjectPool getSpanLinksPool() { + public BookkeeperObjectPool getSpanLinksPool() { return spanLinksPool; } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/BookkeeperObjectPool.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/BookkeeperObjectPool.java index ac4ce8292f..853eb138a1 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/BookkeeperObjectPool.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/BookkeeperObjectPool.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.objectpool.impl; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -29,16 +29,16 @@ import java.util.concurrent.atomic.AtomicInteger; /** - * {@link ObjectPool} wrapper implementation that keeps track of all created object instances, and thus allows to check + * {@link ObservableObjectPool} wrapper implementation that keeps track of all created object instances, and thus allows to check * for any pooled object leak. Should only be used for testing as it keeps a reference to all in-flight pooled objects. * * @param pooled object type */ -public class BookkeeperObjectPool implements ObjectPool { +public class BookkeeperObjectPool implements ObservableObjectPool { private static final Logger logger = LoggerFactory.getLogger(BookkeeperObjectPool.class); - private final ObjectPool pool; + private final ObservableObjectPool pool; private final Set toReturn = Collections.synchronizedSet(Collections.newSetFromMap(new IdentityHashMap())); // An ever-increasing counter for how many objects where requested from the pool private AtomicInteger objectCounter = new AtomicInteger(); @@ -46,7 +46,7 @@ public class BookkeeperObjectPool implements ObjectPool { /** * @param pool pool to wrap */ - public BookkeeperObjectPool(ObjectPool pool) { + public BookkeeperObjectPool(ObservableObjectPool pool) { this.pool = pool; } @@ -96,7 +96,7 @@ public Collection getRecyclablesToReturn() { * Returns the number of times an object has been requested from the pool since its creation. * The returned value cannot be used as any indication as to the number of objects actually allocated by the pool. * - * @return number of times {@link ObjectPool#createInstance()} was called on this pool since its creation + * @return number of times {@link ObservableObjectPool#createInstance()} was called on this pool since its creation */ public int getRequestedObjectCount() { return objectCounter.get(); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/BookkeeperObjectPoolTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/BookkeeperObjectPoolTest.java index 8dbec5ed48..037fa0285e 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/BookkeeperObjectPoolTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/BookkeeperObjectPoolTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.objectpool.impl; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; import co.elastic.apm.agent.objectpool.ObjectPoolTest; import co.elastic.apm.agent.objectpool.TestRecyclable; import org.jctools.queues.atomic.MpmcAtomicArrayQueue; @@ -31,7 +31,7 @@ class BookkeeperObjectPoolTest extends ObjectPoolTest createObjectPool(int maxSize) { - ObjectPool queuePool = QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue<>(maxSize), false, TestRecyclable::new); + ObservableObjectPool queuePool = QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue<>(maxSize), false, TestRecyclable::new); return new BookkeeperObjectPool<>(queuePool); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/QueueBasedObjectPoolTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/QueueBasedObjectPoolTest.java index 4edae48c03..1e24ad2bc3 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/QueueBasedObjectPoolTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/objectpool/impl/QueueBasedObjectPoolTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.objectpool.impl; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; import co.elastic.apm.agent.objectpool.ObjectPoolTest; import co.elastic.apm.agent.objectpool.TestRecyclable; import co.elastic.apm.agent.sdk.internal.util.IOUtils; @@ -47,7 +47,7 @@ void preAllocationShouldCreateObjectsInPool() { // we have to use a power of two as capacity, otherwise actual capacity will differ int capacity = 8; - ObjectPool pool = QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue<>(capacity), true, TestRecyclable::new); + ObservableObjectPool pool = QueueBasedObjectPool.ofRecyclable(new MpmcAtomicArrayQueue<>(capacity), true, TestRecyclable::new); assertThat(pool.getGarbageCreated()).isEqualTo(0); assertThat(pool.getObjectsInPool()).isEqualTo(capacity); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerClientProxySupportIT.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerClientProxySupportIT.java index 645c0020f8..6807952ed2 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerClientProxySupportIT.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerClientProxySupportIT.java @@ -226,7 +226,7 @@ private void setSystemProxyCredentialProperties() { private static ApmServerClient createAndStartClient(boolean useProxy) { ConfigurationRegistry spyConfig = SpyConfiguration.createSpyConfig(); - ReporterConfiguration config = spyConfig.getConfig(ReporterConfiguration.class); + ReporterConfigurationImpl config = spyConfig.getConfig(ReporterConfigurationImpl.class); doReturn(Collections.singletonList(useProxy ? proxyUrl : directUrl)).when(config).getServerUrls(); ApmServerClient client = new ApmServerClient(spyConfig); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerClientTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerClientTest.java index e469235bcc..bb488f4934 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerClientTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerClientTest.java @@ -20,18 +20,18 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.common.util.Version; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.configuration.ServerlessConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.configuration.source.ConfigSources; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; -import co.elastic.apm.agent.impl.error.ErrorCapture; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.impl.metadata.MetaData; import co.elastic.apm.agent.impl.metadata.MetaDataMock; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import co.elastic.apm.agent.objectpool.impl.BookkeeperObjectPool; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; @@ -87,8 +87,8 @@ public class ApmServerClientTest { private ConfigurationRegistry config; private ElasticApmTracer tracer; private TestObjectPoolFactory objectPoolFactory; - private ReporterConfiguration reporterConfiguration; - private CoreConfiguration coreConfiguration; + private ReporterConfigurationImpl reporterConfiguration; + private CoreConfigurationImpl coreConfiguration; private List urlList; @Before @@ -106,8 +106,8 @@ public void setUp() throws IOException, ExecutionException, InterruptedException apmServer2.stubFor(get(urlEqualTo("/proxy/not-found")).willReturn(notFound())); config = SpyConfiguration.createSpyConfig(); - reporterConfiguration = config.getConfig(ReporterConfiguration.class); - coreConfiguration = config.getConfig(CoreConfiguration.class); + reporterConfiguration = config.getConfig(ReporterConfigurationImpl.class); + coreConfiguration = config.getConfig(CoreConfigurationImpl.class); objectPoolFactory = new TestObjectPoolFactory(); config.save("server_urls", url1 + "," + url2, SpyConfiguration.CONFIG_SOURCE_NAME); urlList = List.of(UrlValueConverter.INSTANCE.convert(url1.toString()), UrlValueConverter.INSTANCE.convert(url2.toString())); @@ -131,7 +131,7 @@ public void setUp() throws IOException, ExecutionException, InterruptedException @Test @SuppressWarnings("unchecked") public void ensureSerializerDoesNotBlockOnAwsLambda() throws Exception { - doReturn(true).when(config.getConfig(ServerlessConfiguration.class)).runsOnAwsLambda(); + doReturn(true).when(config.getConfig(ServerlessConfigurationImpl.class)).runsOnAwsLambda(); ApmServerClient client = new ApmServerClient(config); Future serverVersionFuture = Mockito.mock(Future.class); doReturn(false).when(serverVersionFuture).isDone(); @@ -139,7 +139,7 @@ public void ensureSerializerDoesNotBlockOnAwsLambda() throws Exception { client.start(serverVersionFuture); Future metadata = MetaDataMock.create(); - DslJsonSerializer dslJsonSerializer = new DslJsonSerializer(config.getConfig(StacktraceConfiguration.class), client, metadata); + DslJsonSerializer dslJsonSerializer = new DslJsonSerializer(config.getConfig(StacktraceConfigurationImpl.class), client, metadata); dslJsonSerializer.newWriter().blockUntilReady(); verify(serverVersionFuture, never()).get(); @@ -165,19 +165,19 @@ public void testDroppingAndRecyclingEventsWithEmptyUrls() { // tests setting server_url to an empty string in configuration apmServerClient.start(Lists.emptyList()); - BookkeeperObjectPool transactionPool = objectPoolFactory.getTransactionPool(); + BookkeeperObjectPool transactionPool = objectPoolFactory.getTransactionPool(); int transactionsRequestedBefore = transactionPool.getRequestedObjectCount(); - final Transaction transaction = tracer.startRootTransaction(getClass().getClassLoader()); + final TransactionImpl transaction = tracer.startRootTransaction(getClass().getClassLoader()); assertThat(transactionPool.getRequestedObjectCount()).isEqualTo(transactionsRequestedBefore + 1); int transactionsInPoolAfterCreation = transactionPool.getObjectsInPool(); - BookkeeperObjectPool spanPool = objectPoolFactory.getSpanPool(); + BookkeeperObjectPool spanPool = objectPoolFactory.getSpanPool(); int spansRequestedBefore = spanPool.getRequestedObjectCount(); - final Span span = Objects.requireNonNull(transaction).createSpan(); + final SpanImpl span = Objects.requireNonNull(transaction).createSpan(); assertThat(transactionPool.getRequestedObjectCount()).isEqualTo(spansRequestedBefore + 1); int spansInPoolAfterCreation = spanPool.getObjectsInPool(); - BookkeeperObjectPool errorPool = objectPoolFactory.getErrorPool(); + BookkeeperObjectPool errorPool = objectPoolFactory.getErrorPool(); int errorsRequestedBefore = errorPool.getRequestedObjectCount(); span.captureException(new Throwable()); assertThat(errorPool.getRequestedObjectCount()).isEqualTo(errorsRequestedBefore + 1); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerReporterIntegrationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerReporterIntegrationTest.java index e7c234fc2a..ff8412dcce 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerReporterIntegrationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ApmServerReporterIntegrationTest.java @@ -19,17 +19,17 @@ package co.elastic.apm.agent.report; import co.elastic.apm.agent.MockTracer; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.error.ErrorCapture; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.impl.metadata.MetaDataMock; import co.elastic.apm.agent.impl.metadata.ProcessInfo; -import co.elastic.apm.agent.impl.metadata.Service; +import co.elastic.apm.agent.impl.metadata.ServiceImpl; import co.elastic.apm.agent.impl.metadata.SystemInfo; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.objectpool.ObjectPoolFactory; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; +import co.elastic.apm.agent.objectpool.ObjectPoolFactoryImpl; import co.elastic.apm.agent.report.processor.ProcessorEventHandler; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import co.elastic.apm.agent.report.serialize.SerializationConstants; @@ -83,9 +83,9 @@ class ApmServerReporterIntegrationTest { private final ElasticApmTracer tracer = MockTracer.create(); private volatile int statusCode = HttpStatus.OK_200; private volatile int acceptedEventCount = 0; - private ReporterConfiguration reporterConfiguration; + private ReporterConfigurationImpl reporterConfiguration; - private CoreConfiguration coreConfiguration; + private CoreConfigurationImpl coreConfiguration; private ApmServerReporter reporter; private ReporterMonitor mockMonitor; @@ -141,8 +141,8 @@ void setUp() throws Exception { }); ConfigurationRegistry config = tracer.getConfigurationRegistry(); - reporterConfiguration = config.getConfig(ReporterConfiguration.class); - coreConfiguration = config.getConfig(CoreConfiguration.class); + reporterConfiguration = config.getConfig(ReporterConfigurationImpl.class); + coreConfiguration = config.getConfig(CoreConfigurationImpl.class); SerializationConstants.init(coreConfiguration); // mockito mocking does not seem to reliably work here @@ -154,13 +154,13 @@ void setUp() throws Exception { doReturn(Collections.singletonList(new URL("http://localhost:" + port))).when(reporterConfiguration).getServerUrls(); SystemInfo system = new SystemInfo("x64", "localhost", null, "platform"); - final Service service = new Service(); + final ServiceImpl service = new ServiceImpl(); final ProcessInfo title = new ProcessInfo("title"); final ProcessorEventHandler processorEventHandler = ProcessorEventHandler.loadProcessors(config); ApmServerClient apmServerClient = new ApmServerClient(config); apmServerClient.start(); DslJsonSerializer payloadSerializer = new DslJsonSerializer( - mock(StacktraceConfiguration.class), + mock(StacktraceConfigurationImpl.class), apmServerClient, MetaDataMock.create(title, service, system, null, Collections.emptyMap(), null) ); @@ -170,7 +170,7 @@ void setUp() throws Exception { payloadSerializer, apmServerClient); mockMonitor = Mockito.mock(ReporterMonitor.class); - reporter = new ApmServerReporter(false, reporterConfiguration, coreConfiguration, v2handler, mockMonitor, apmServerClient, payloadSerializer, new ObjectPoolFactory()); + reporter = new ApmServerReporter(false, reporterConfiguration, coreConfiguration, v2handler, mockMonitor, apmServerClient, payloadSerializer, new ObjectPoolFactoryImpl()); reporter.start(); } @@ -187,7 +187,7 @@ void tearDown() { @Test void testReportTransaction() { - reporter.report(new Transaction(tracer)); + reporter.report(new TransactionImpl(tracer)); assertThat(reporter.flush(5, TimeUnit.SECONDS, false)).isTrue(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedIntakeApiCalls.get()).isEqualTo(1); @@ -206,8 +206,8 @@ void testReportTransaction() { void testContextPropagationOnlyRespected() { doReturn(true).when(coreConfiguration).isContextPropagationOnly(); - reporter.reportPartialTransaction(new Transaction(tracer)); - reporter.report(new Transaction(tracer)); + reporter.reportPartialTransaction(new TransactionImpl(tracer)); + reporter.report(new TransactionImpl(tracer)); assertThat(reporter.flush(5, TimeUnit.SECONDS, false)).isTrue(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedIntakeApiCalls.get()).isEqualTo(0); @@ -219,7 +219,7 @@ void testContextPropagationOnlyRespected() { @Test void testReportTransaction_withFlushRequest() { - reporter.report(new Transaction(tracer)); + reporter.report(new TransactionImpl(tracer)); assertThat(receivedEvents.get()).isEqualTo(0); assertThat(reporter.flush(5, TimeUnit.SECONDS, true)).isTrue(); assertThat(reporter.getDropped()).isEqualTo(0); @@ -237,7 +237,7 @@ void testReportTransaction_withFlushRequest() { @Test void testReportSpan() { - reporter.report(new Span(tracer)); + reporter.report(new SpanImpl(tracer)); reporter.flush(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedIntakeApiCalls.get()).isEqualTo(1); @@ -252,7 +252,7 @@ void testReportSpan() { @Test void testReportSpan_withFlushRequest() { - reporter.report(new Span(tracer)); + reporter.report(new SpanImpl(tracer)); reporter.flush(5, TimeUnit.SECONDS, true); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedIntakeApiCalls.get()).isEqualTo(2); @@ -277,7 +277,7 @@ void testSecretToken() { } exchange.setStatusCode(200).endExchange(); }; - reporter.report(new Transaction(tracer)); + reporter.report(new TransactionImpl(tracer)); reporter.flush(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedIntakeApiCalls.get()).isEqualTo(1); @@ -285,7 +285,7 @@ void testSecretToken() { @Test void testReportErrorCapture() { - reporter.report(new ErrorCapture(tracer)); + reporter.report(new ErrorCaptureImpl(tracer)); reporter.flush(); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedIntakeApiCalls.get()).isEqualTo(1); @@ -300,7 +300,7 @@ void testReportErrorCapture() { @Test void testTimeout() { timeout.set(TimeDuration.of("1ms")); - reporter.report(new Transaction(tracer)); + reporter.report(new TransactionImpl(tracer)); await().untilAsserted(() -> assertThat(reporter.getReported()).isEqualTo(1)); assertThat(reporter.getDropped()).isEqualTo(0); assertThat(receivedIntakeApiCalls.get()).isEqualTo(1); @@ -317,13 +317,13 @@ void testTimeout() { void testFailingApmServer() { statusCode = HttpStatus.SERVICE_UNAVAILABLE_503; // try to report a few events to trigger backoff - reporter.report(new Transaction(tracer)); + reporter.report(new TransactionImpl(tracer)); reporter.flush(1, TimeUnit.SECONDS, false); - reporter.report(new Transaction(tracer)); + reporter.report(new TransactionImpl(tracer)); reporter.flush(1, TimeUnit.SECONDS, false); - reporter.report(new Transaction(tracer)); + reporter.report(new TransactionImpl(tracer)); reporter.flush(1, TimeUnit.SECONDS, false); - reporter.report(new Transaction(tracer)); + reporter.report(new TransactionImpl(tracer)); assertThat(v2handler.isHealthy()).isFalse(); assertThat(reporter.flush(1, TimeUnit.SECONDS, false)).isFalse(); @@ -339,7 +339,7 @@ void testErrorResponseParsing() { acceptedEventCount = 2; // try to report a few events to trigger backoff for (int i = 0; i < 5; i++) { - reporter.report(new Transaction(tracer)); + reporter.report(new TransactionImpl(tracer)); } reporter.flush(1, TimeUnit.SECONDS, false); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/IntakeV2ReportingEventHandlerTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/IntakeV2ReportingEventHandlerTest.java index ba31a13dac..cea5759cb7 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/IntakeV2ReportingEventHandlerTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/IntakeV2ReportingEventHandlerTest.java @@ -20,16 +20,16 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.common.util.Version; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; -import co.elastic.apm.agent.impl.error.ErrorCapture; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.impl.metadata.MetaDataMock; import co.elastic.apm.agent.impl.metadata.ProcessInfo; -import co.elastic.apm.agent.impl.metadata.Service; +import co.elastic.apm.agent.impl.metadata.ServiceImpl; import co.elastic.apm.agent.impl.metadata.SystemInfo; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.report.processor.ProcessorEventHandler; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import com.dslplatform.json.DslJson; @@ -103,11 +103,11 @@ void setUp() throws Exception { mockApmServer2.start(); final ConfigurationRegistry configurationRegistry = SpyConfiguration.createSpyConfig(); - final ReporterConfiguration reporterConfiguration = configurationRegistry.getConfig(ReporterConfiguration.class); - final CoreConfiguration coreConfiguration = configurationRegistry.getConfig(CoreConfiguration.class); + final ReporterConfigurationImpl reporterConfiguration = configurationRegistry.getConfig(ReporterConfigurationImpl.class); + final CoreConfigurationImpl coreConfiguration = configurationRegistry.getConfig(CoreConfigurationImpl.class); SystemInfo system = new SystemInfo("x64", "localhost", null, "platform"); final ProcessInfo title = new ProcessInfo("title"); - final Service service = new Service(); + final ServiceImpl service = new ServiceImpl(); apmServerClient = new ApmServerClient(configurationRegistry); apmServerClient.start(List.of( new URL(HTTP_LOCALHOST + mockApmServer1.port()), @@ -118,21 +118,21 @@ void setUp() throws Exception { reporterConfiguration, mock(ProcessorEventHandler.class), new DslJsonSerializer( - mock(StacktraceConfiguration.class), + mock(StacktraceConfigurationImpl.class), apmServerClient, MetaDataMock.create(title, service, system, null, Collections.emptyMap(), null) ), apmServerClient); final ProcessInfo title1 = new ProcessInfo("title"); - final Service service1 = new Service(); + final ServiceImpl service1 = new ServiceImpl(); ApmServerClient nonConnectedApmServerClient = new ApmServerClient(configurationRegistry); nonConnectedApmServerClient.start(List.of(new URL("http://non.existing:8080"))); nonConnectedReportingEventHandler = new IntakeV2ReportingEventHandler( reporterConfiguration, mock(ProcessorEventHandler.class), new DslJsonSerializer( - mock(StacktraceConfiguration.class), + mock(StacktraceConfigurationImpl.class), nonConnectedApmServerClient, MetaDataMock.create(title1, service1, system, null, Collections.emptyMap(), null) ), @@ -244,21 +244,21 @@ void testRandomJitter() { private void reportTransaction(IntakeV2ReportingEventHandler reportingEventHandler) throws Exception { final ReportingEvent reportingEvent = new ReportingEvent(); - reportingEvent.setTransaction(new Transaction(MockTracer.create())); + reportingEvent.setTransaction(new TransactionImpl(MockTracer.create())); reportingEventHandler.onEvent(reportingEvent, -1, true); } private void reportSpan() throws Exception { final ReportingEvent reportingEvent = new ReportingEvent(); - reportingEvent.setSpan(new Span(MockTracer.create())); + reportingEvent.setSpan(new SpanImpl(MockTracer.create())); reportingEventHandler.onEvent(reportingEvent, -1, true); } private void reportError() throws Exception { final ReportingEvent reportingEvent = new ReportingEvent(); - reportingEvent.setError(new ErrorCapture(MockTracer.create())); + reportingEvent.setError(new ErrorCaptureImpl(MockTracer.create())); reportingEventHandler.onEvent(reportingEvent, -1, true); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/PartialTransactionTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/PartialTransactionTest.java index 1b8a6ec486..1176b4b6c8 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/PartialTransactionTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/PartialTransactionTest.java @@ -20,11 +20,11 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; -import co.elastic.apm.agent.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.configuration.ServerlessConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.metadata.MetaDataMock; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import com.github.tomakehurst.wiremock.junit5.WireMockExtension; @@ -79,7 +79,7 @@ public void setup() throws MalformedURLException { ApmServerClient client = new ApmServerClient(spyConfig); client.start(List.of(new URL(apmServer.getRuntimeInfo().getHttpBaseUrl()))); - StacktraceConfiguration stackTraceConfig = spyConfig.getConfig(StacktraceConfiguration.class); + StacktraceConfigurationImpl stackTraceConfig = spyConfig.getConfig(StacktraceConfigurationImpl.class); DslJsonSerializer serializer = new DslJsonSerializer(stackTraceConfig, client, MetaDataMock.create()); PartialTransactionReporter partialTransactionReporter = new PartialTransactionReporter(client, serializer, objectPoolFactory); @@ -96,10 +96,10 @@ public void cleanup() { @Test public void testReportAwsLambdaTransaction() { apmServer.stubFor(post(urlEqualTo("/register/transaction")).willReturn(aResponse().withStatus(200))); - ServerlessConfiguration serverlessConfig = spyConfig.getConfig(ServerlessConfiguration.class); + ServerlessConfigurationImpl serverlessConfig = spyConfig.getConfig(ServerlessConfigurationImpl.class); doReturn(true).when(serverlessConfig).runsOnAwsLambda(); - Transaction tx1 = tracer + TransactionImpl tx1 = tracer .startRootTransaction(null) .withName("faas-transaction"); tx1.getFaas().withExecution("foo-bar-id"); @@ -135,7 +135,7 @@ public void testReportAwsLambdaTransaction() { tx1.deactivate().end(); apmServer.verify(1, postRequestedFor(urlEqualTo("/register/transaction"))); - Transaction tx2 = tracer + TransactionImpl tx2 = tracer .startRootTransaction(null) .withName("second-faas-transaction"); tx2.getFaas().withExecution("baz-id"); @@ -170,10 +170,10 @@ public void testReportAwsLambdaTransaction() { @Test public void testNoMoreReportingAfter4xx() { apmServer.stubFor(post(urlEqualTo("/register/transaction")).willReturn(aResponse().withStatus(404))); - ServerlessConfiguration serverlessConfig = spyConfig.getConfig(ServerlessConfiguration.class); + ServerlessConfigurationImpl serverlessConfig = spyConfig.getConfig(ServerlessConfigurationImpl.class); doReturn(true).when(serverlessConfig).runsOnAwsLambda(); - Transaction tx1 = tracer + TransactionImpl tx1 = tracer .startRootTransaction(null) .withName("faas-transaction"); tx1.getFaas().withExecution("foo-bar-id"); @@ -182,7 +182,7 @@ public void testNoMoreReportingAfter4xx() { tx1.deactivate().end(); - Transaction tx2 = tracer + TransactionImpl tx2 = tracer .startRootTransaction(null) .withName("faas-transaction"); tx2.getFaas().withExecution("foo-bar-id"); @@ -196,10 +196,10 @@ public void testNoMoreReportingAfter4xx() { @Test public void testNonLambdaTransactionNotReported() { apmServer.stubFor(post(urlEqualTo("/register/transaction")).willReturn(aResponse().withStatus(200))); - ServerlessConfiguration serverlessConfig = spyConfig.getConfig(ServerlessConfiguration.class); + ServerlessConfigurationImpl serverlessConfig = spyConfig.getConfig(ServerlessConfigurationImpl.class); doReturn(true).when(serverlessConfig).runsOnAwsLambda(); - Transaction transaction = tracer.startRootTransaction(null).withName("nonfaas-transaction"); + TransactionImpl transaction = tracer.startRootTransaction(null).withName("nonfaas-transaction"); transaction.activate(); apmServer.verify(0, postRequestedFor(urlEqualTo("/register/transaction"))); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ReporterFactoryTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ReporterFactoryTest.java index ed2748dd09..c463f8cb2d 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ReporterFactoryTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/ReporterFactoryTest.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.metadata.MetaDataMock; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.objectpool.ObjectPoolFactory; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; +import co.elastic.apm.agent.objectpool.ObjectPoolFactoryImpl; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.server.HttpConfiguration; @@ -58,7 +58,7 @@ class ReporterFactoryTest { private ReporterFactory reporterFactory = new ReporterFactory(); private ConfigurationRegistry configuration; private AtomicBoolean requestHandled = new AtomicBoolean(false); - private ReporterConfiguration reporterConfiguration; + private ReporterConfigurationImpl reporterConfiguration; @BeforeEach void setUp() throws Exception { @@ -89,7 +89,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques }); server.start(); configuration = SpyConfiguration.createSpyConfig(); - reporterConfiguration = configuration.getConfig(ReporterConfiguration.class); + reporterConfiguration = configuration.getConfig(ReporterConfigurationImpl.class); doReturn(Collections.singletonList(new URL("https://localhost:" + getPort()))).when(reporterConfiguration).getServerUrls(); } @@ -107,12 +107,12 @@ void testNotValidatingSslCertificate() throws Exception { doReturn(false).when(reporterConfiguration).isVerifyServerCert(); ApmServerClient apmServerClient = new ApmServerClient(configuration); apmServerClient.start(); - DslJsonSerializer serializer = new DslJsonSerializer(configuration.getConfig(StacktraceConfiguration.class), apmServerClient, MetaDataMock.create()); - ObjectPoolFactory poolFactory = new ObjectPoolFactory(); + DslJsonSerializer serializer = new DslJsonSerializer(configuration.getConfig(StacktraceConfigurationImpl.class), apmServerClient, MetaDataMock.create()); + ObjectPoolFactoryImpl poolFactory = new ObjectPoolFactoryImpl(); final Reporter reporter = reporterFactory.createReporter(configuration, apmServerClient, serializer, ReporterMonitor.NOOP, poolFactory); reporter.start(); - reporter.report(new Transaction(MockTracer.create())); + reporter.report(new TransactionImpl(MockTracer.create())); reporter.flush(); assertThat(requestHandled) @@ -126,12 +126,12 @@ void testValidatingSslCertificate() throws Exception { doReturn(true).when(reporterConfiguration).isVerifyServerCert(); ApmServerClient apmServerClient = new ApmServerClient(configuration); apmServerClient.start(); - DslJsonSerializer serializer = new DslJsonSerializer(configuration.getConfig(StacktraceConfiguration.class), apmServerClient, MetaDataMock.create()); - ObjectPoolFactory poolFactory = new ObjectPoolFactory(); + DslJsonSerializer serializer = new DslJsonSerializer(configuration.getConfig(StacktraceConfigurationImpl.class), apmServerClient, MetaDataMock.create()); + ObjectPoolFactoryImpl poolFactory = new ObjectPoolFactoryImpl(); final Reporter reporter = reporterFactory.createReporter(configuration, apmServerClient, serializer, ReporterMonitor.NOOP, poolFactory); reporter.start(); - reporter.report(new Transaction(MockTracer.create())); + reporter.report(new TransactionImpl(MockTracer.create())); reporter.flush(); assertThat(requestHandled) diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/TestProcessor.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/TestProcessor.java index 53937e8cbb..9b3ef496e2 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/TestProcessor.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/TestProcessor.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.report; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.report.processor.Processor; import java.util.concurrent.atomic.AtomicInteger; @@ -30,12 +30,12 @@ public class TestProcessor implements Processor { private static AtomicInteger errorCounter = new AtomicInteger(); @Override - public void processBeforeReport(Transaction transaction) { + public void processBeforeReport(TransactionImpl transaction) { transactionCounter.incrementAndGet(); } @Override - public void processBeforeReport(ErrorCapture error) { + public void processBeforeReport(ErrorCaptureImpl error) { errorCounter.incrementAndGet(); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/DslJsonSerializerTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/DslJsonSerializerTest.java index 8f341fd835..7006fd0fa8 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/DslJsonSerializerTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/DslJsonSerializerTest.java @@ -20,19 +20,19 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.configuration.ServerlessConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.TextHeaderMapAccessor; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.baggage.Baggage; -import co.elastic.apm.agent.impl.context.AbstractContext; -import co.elastic.apm.agent.impl.context.Destination; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; +import co.elastic.apm.agent.impl.context.AbstractContextImpl; +import co.elastic.apm.agent.impl.context.BodyCaptureImpl; +import co.elastic.apm.agent.impl.context.DestinationImpl; import co.elastic.apm.agent.impl.context.Headers; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Url; -import co.elastic.apm.agent.impl.error.ErrorCapture; +import co.elastic.apm.agent.impl.context.RequestImpl; +import co.elastic.apm.agent.impl.context.UrlImpl; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.impl.metadata.Agent; import co.elastic.apm.agent.impl.metadata.CloudProviderInfo; import co.elastic.apm.agent.impl.metadata.FaaSMetaDataExtension; @@ -42,18 +42,18 @@ import co.elastic.apm.agent.impl.metadata.MetaDataMock; import co.elastic.apm.agent.impl.metadata.NameAndIdField; import co.elastic.apm.agent.impl.metadata.ProcessInfo; -import co.elastic.apm.agent.impl.metadata.Service; +import co.elastic.apm.agent.impl.metadata.ServiceImpl; import co.elastic.apm.agent.impl.metadata.SystemInfo; import co.elastic.apm.agent.impl.sampling.ConstantSampler; import co.elastic.apm.agent.impl.sampling.Sampler; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Id; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.IdImpl; import co.elastic.apm.agent.impl.transaction.OTelSpanKind; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.impl.transaction.StackFrame; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.sdk.internal.collections.LongList; import co.elastic.apm.agent.sdk.internal.util.IOUtils; @@ -102,13 +102,13 @@ class DslJsonSerializerTest { @BeforeEach void setUp() throws Exception { - StacktraceConfiguration stacktraceConfiguration = mock(StacktraceConfiguration.class); + StacktraceConfigurationImpl stacktraceConfiguration = mock(StacktraceConfigurationImpl.class); doReturn(15).when(stacktraceConfiguration).getStackTraceLimit(); apmServerClient = mock(ApmServerClient.class); metaData = MetaDataMock.create(); objectMapper = new ObjectMapper(); tracer = MockTracer.createRealTracer(); - SerializationConstants.init(tracer.getConfig(CoreConfiguration.class)); + SerializationConstants.init(tracer.getConfig(CoreConfigurationImpl.class)); DslJsonSerializer serializer = new DslJsonSerializer(stacktraceConfiguration, apmServerClient, metaData); writer = serializer.newWriter(); @@ -149,7 +149,7 @@ void testSerializeUrlPort(boolean useNumericPort) { doReturn(useNumericPort).when(apmServerClient).supportsNumericUrlPort(); - Url url = new Url() + UrlImpl url = new UrlImpl() .withPort(42) .withHostname("hostname") .withProtocol("http") @@ -168,9 +168,9 @@ void testSerializeUrlPort(boolean useNumericPort) { @Test void testErrorSerialization() { - Transaction transaction = new Transaction(tracer); - transaction.startRoot(-1, ConstantSampler.of(true), Baggage.EMPTY); - ErrorCapture error = new ErrorCapture(tracer).asChildOf(transaction).withTimestamp(5000); + TransactionImpl transaction = new TransactionImpl(tracer); + transaction.startRoot(-1, ConstantSampler.of(true), BaggageImpl.EMPTY); + ErrorCaptureImpl error = new ErrorCaptureImpl(tracer).asChildOf(transaction).withTimestamp(5000); error.setTransactionSampled(true); error.setTransactionType("test-type"); error.setTransactionName(new StringBuilder("Test Transaction")); @@ -201,11 +201,11 @@ void testErrorSerialization() { @Test void testErrorSerializationAllFrames() { - StacktraceConfiguration stacktraceConfiguration = mock(StacktraceConfiguration.class); + StacktraceConfigurationImpl stacktraceConfiguration = mock(StacktraceConfigurationImpl.class); doReturn(-1).when(stacktraceConfiguration).getStackTraceLimit(); writer = new DslJsonSerializer(stacktraceConfiguration, apmServerClient, metaData).newWriter(); - ErrorCapture error = new ErrorCapture(tracer).withTimestamp(5000); + ErrorCaptureImpl error = new ErrorCaptureImpl(tracer).withTimestamp(5000); Exception exception = new Exception("test"); error.setException(exception); @@ -216,10 +216,10 @@ void testErrorSerializationAllFrames() { @Test void testErrorSerializationWithEmptyTraceId() { - Transaction transaction = new Transaction(tracer); - transaction.startRoot(-1, ConstantSampler.of(true), Baggage.EMPTY); + TransactionImpl transaction = new TransactionImpl(tracer); + transaction.startRoot(-1, ConstantSampler.of(true), BaggageImpl.EMPTY); transaction.getTraceContext().getTraceId().resetState(); - ErrorCapture error = new ErrorCapture(tracer).asChildOf(transaction).withTimestamp(5000); + ErrorCaptureImpl error = new ErrorCaptureImpl(tracer).asChildOf(transaction).withTimestamp(5000); JsonNode errorTree = readJsonString(writer.toJsonString(error)); @@ -240,7 +240,7 @@ void testErrorSerializationWithEmptyTraceId() { @Test void testErrorSerializationOutsideTrace() { MockReporter reporter = new MockReporter(); - Tracer tracer = MockTracer.createRealTracer(reporter); + ElasticApmTracer tracer = MockTracer.createRealTracer(reporter); tracer.captureAndReportException(new Exception("test"), getClass().getClassLoader()); String errorJson = writer.toJsonString(reporter.getFirstError()); @@ -261,7 +261,7 @@ void testErrorSerializationOutsideTrace() { void testErrorSerializationWithExceptionCause() { // testing outside trace is enough to test exception serialization logic MockReporter reporter = new MockReporter(); - Tracer tracer = MockTracer.createRealTracer(reporter); + ElasticApmTracer tracer = MockTracer.createRealTracer(reporter); Exception cause2 = new IllegalStateException("second cause"); Exception cause1 = new RuntimeException("first cause", cause2); @@ -336,7 +336,7 @@ void testLimitStringValueLength() throws IOException { @Test void testNullTransactionHeaders() { - Transaction transaction = new Transaction(tracer); + TransactionImpl transaction = new TransactionImpl(tracer); transaction.getContext().getRequest().addHeader("foo", (String) null); transaction.getContext().getRequest().addHeader("baz", (Enumeration) null); transaction.getContext().getRequest().getHeaders().add("bar", null); @@ -350,7 +350,7 @@ void testNullTransactionHeaders() { @Test void testMessageHeaders() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getTraceContext().asRootSpan(ConstantSampler.of(true)); span.withType("messaging").withSubtype("kafka"); @@ -380,7 +380,7 @@ void testMessageHeaders() { @Test void testSpanTypeSerialization() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getTraceContext().asRootSpan(ConstantSampler.of(true)); span.withType("template.jsf.render.view"); JsonNode spanJson = readJsonString(writer.toJsonString(span)); @@ -395,19 +395,19 @@ void testSpanTypeSerialization() { spanJson = readJsonString(writer.toJsonString(span)); assertThat(spanJson.get("type").textValue()).isEqualTo("template.jsf_lifecycle.render_view"); - span = new Span(tracer); + span = new SpanImpl(tracer); span.getTraceContext().asRootSpan(ConstantSampler.of(true)); span.withType("template").withAction("jsf.render"); spanJson = readJsonString(writer.toJsonString(span)); assertThat(spanJson.get("type").textValue()).isEqualTo("template..jsf_render"); - span = new Span(tracer); + span = new SpanImpl(tracer); span.getTraceContext().asRootSpan(ConstantSampler.of(true)); span.withType("template").withSubtype("jsf.render"); spanJson = readJsonString(writer.toJsonString(span)); assertThat(spanJson.get("type").textValue()).isEqualTo("template.jsf_render"); - span = new Span(tracer); + span = new SpanImpl(tracer); span.getTraceContext().asRootSpan(ConstantSampler.of(true)); span.withSubtype("jsf").withAction("render"); spanJson = readJsonString(writer.toJsonString(span)); @@ -416,7 +416,7 @@ void testSpanTypeSerialization() { @Test void testSpanHttpContextSerialization() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getContext().getHttp() .withMethod("GET") .withStatusCode(523) @@ -431,6 +431,21 @@ void testSpanHttpContextSerialization() { assertThat(http.get("status_code").intValue()).isEqualTo(523); } + @Test + void testSpanHttpRequestBodySerialization() { + SpanImpl span = new SpanImpl(tracer); + + BodyCaptureImpl bodyCapture = span.getContext().getHttp().getRequestBody(); + bodyCapture.markEligibleForCapturing(); + bodyCapture.startCapture("utf-8", 50); + bodyCapture.append("foobar".getBytes(StandardCharsets.UTF_8), 0, 6); + + JsonNode spanJson = readJsonString(writer.toJsonString(span)); + JsonNode otel = spanJson.get("otel"); + JsonNode attribs = otel.get("attributes"); + assertThat(attribs.get("http.request.body.content").textValue()).isEqualTo("foobar"); + } + public static boolean[][] getContentCombinations() { return new boolean[][]{ {true, true, true, true}, @@ -451,8 +466,8 @@ void testSpanDestinationContextSerializationWithCombinations(boolean[] contentCo boolean hasPort = contentCombination[1]; boolean hasServiceTargetContent = contentCombination[2]; boolean hasCloudContent = contentCombination[3]; - Span span = new Span(MockTracer.create()); - Destination dest = span.getContext().getDestination(); + SpanImpl span = new SpanImpl(MockTracer.create()); + DestinationImpl dest = span.getContext().getDestination(); if (hasAddress) { dest.withAddress("whatever.com"); } @@ -509,7 +524,7 @@ void testSpanDestinationContextSerializationWithCombinations(boolean[] contentCo @Test void testTransactionNullFrameworkNameSerialization() { - Transaction transaction = new Transaction(tracer); + TransactionImpl transaction = new TransactionImpl(tracer); transaction.getTraceContext().setServiceInfo("service-name", null); transaction.setUserFrameworkName(null); JsonNode transactionJson = readJsonString(writer.toJsonString(transaction)); @@ -518,7 +533,7 @@ void testTransactionNullFrameworkNameSerialization() { @Test void testTransactionEmptyFrameworkNameSerialization() { - Transaction transaction = new Transaction(tracer); + TransactionImpl transaction = new TransactionImpl(tracer); transaction.getTraceContext().setServiceInfo("service-name", null); transaction.setUserFrameworkName(""); JsonNode transactionJson = readJsonString(writer.toJsonString(transaction)); @@ -527,7 +542,7 @@ void testTransactionEmptyFrameworkNameSerialization() { @Test void testSpanInvalidDestinationSerialization() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getContext().getDestination().withAddress(null).withPort(-1); span.getContext().getServiceTarget().withUserName("").withNameOnlyDestinationResource(); @@ -540,7 +555,7 @@ void testSpanInvalidDestinationSerialization() { @Test void testSpanValidPortSerialization() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getContext().getDestination().withAddress(null).withPort(8090); JsonNode spanJson = readJsonString(writer.toJsonString(span)); @@ -553,7 +568,7 @@ void testSpanValidPortSerialization() { @Test void testSpanValidAddressAndPortSerialization() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getContext().getDestination().withAddress("test").withPort(8090); JsonNode spanJson = readJsonString(writer.toJsonString(span)); @@ -566,7 +581,7 @@ void testSpanValidAddressAndPortSerialization() { @Test void testSpanValidAddressSerialization() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getContext().getDestination().withAddress("test").withPort(0); JsonNode spanJson = readJsonString(writer.toJsonString(span)); @@ -579,7 +594,7 @@ void testSpanValidAddressSerialization() { @Test void testSpanValidServiceResourceSerialization() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getContext().getDestination().withAddress("").withPort(0); span.getContext().getServiceTarget().withType("test").withName("resource"); @@ -598,7 +613,7 @@ void testSpanValidServiceResourceSerialization() { @Test void testSpanValidServiceAndAddressResourceSerialization() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getContext().getDestination().withAddress("test-address").withPort(0); span.getContext().getServiceTarget().withType("test").withName("test-resource").withNameOnlyDestinationResource(); @@ -618,7 +633,7 @@ void testSpanValidServiceAndAddressResourceSerialization() { @Test void testSpanMessageContextSerialization() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getContext().getMessage() .withRoutingKey("routing-key") .withQueue("test-queue") @@ -651,7 +666,7 @@ void testSpanMessageContextSerialization() { @Test void testSpanMessageContextSerializationWithoutRoutingKey() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getContext().getMessage() .withQueue("test-queue") .withBody("test-body") @@ -666,7 +681,7 @@ void testSpanMessageContextSerializationWithoutRoutingKey() { @Test void testSpanMessageContextInvalidTimestamp() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getContext().getMessage() .withQueue("test-queue"); @@ -683,7 +698,7 @@ void testSpanMessageContextInvalidTimestamp() { @Test void testSpanDbContextSerialization() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getContext().getDb() .withAffectedRowsCount(5) .withInstance("test-instance") @@ -700,11 +715,11 @@ void testSpanDbContextSerialization() { @Test void testSpanChildIdSerialization() { - Id id1 = Id.new64BitId(); + IdImpl id1 = IdImpl.new64BitId(); id1.setToRandomValue(); - Id id2 = Id.new64BitId(); + IdImpl id2 = IdImpl.new64BitId(); id2.setToRandomValue(); - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.withChildIds(LongList.of(id1.getLeastSignificantBits(), id2.getLeastSignificantBits())); JsonNode spanJson = readJsonString(writer.toJsonString(span)); @@ -730,7 +745,7 @@ void testSerializeMetadata() throws Exception { doReturn(kubernetes).when(systemInfo).getKubernetesInfo(); doReturn("9 3/4").when(systemInfo).getPlatform(); // this terrible pun is intentional - Service service = new Service() + ServiceImpl service = new ServiceImpl() .withAgent(new Agent("MyAgent", "1.11.1")) .withFramework(new Framework("Lambda_Java", "1.2.3")) .withName("MyService") @@ -743,7 +758,7 @@ void testSerializeMetadata() throws Exception { CloudProviderInfo cloudProviderInfo = createCloudProviderInfo(); writer = new DslJsonSerializer( - mock(StacktraceConfiguration.class), + mock(StacktraceConfigurationImpl.class), apmServerClient, MetaDataMock.create( processInfo, service, systemInfo, cloudProviderInfo, @@ -824,8 +839,8 @@ void testSerializeMetadata() throws Exception { @Test void testConfiguredServiceNodeName() throws Exception { ConfigurationRegistry configRegistry = SpyConfiguration.createSpyConfig(); - doReturn("Custom-Node-Name").when(configRegistry.getConfig(CoreConfiguration.class)).getServiceNodeName(); - writer = new DslJsonSerializer(mock(StacktraceConfiguration.class), apmServerClient, MetaData.create(configRegistry, null)).newWriter(); + doReturn("Custom-Node-Name").when(configRegistry.getConfig(CoreConfigurationImpl.class)).getServiceNodeName(); + writer = new DslJsonSerializer(mock(StacktraceConfigurationImpl.class), apmServerClient, MetaData.create(configRegistry, null)).newWriter(); writer.blockUntilReady(); writer.appendMetaDataNdJsonToStream(); JsonNode metaDataJson = readJsonString(writer.toString()).get("metadata"); @@ -840,7 +855,7 @@ void testConfiguredServiceNodeName() throws Exception { @Test void testTransactionContextSerialization() { - Transaction transaction = new Transaction(tracer); + TransactionImpl transaction = new TransactionImpl(tracer); // test only the most recent server here doReturn(true).when(apmServerClient).supportsMultipleHeaderValues(); @@ -851,7 +866,7 @@ void testTransactionContextSerialization() { .withEmail("user@email.com") .withUsername("bob"); - Request request = transaction.getContext().getRequest(); + RequestImpl request = transaction.getContext().getRequest(); request.withMethod("PUT") .withHttpVersion("5.0") @@ -889,7 +904,7 @@ void testTransactionContextSerialization() { transaction.getContext().getServiceOrigin().withName("origin_service_name").withId("origin_service_id").withVersion("origin_service_version"); transaction.getContext().getCloudOrigin().withRegion("origin_cloud_region").withAccountId("origin_cloud_account_id").withProvider("origin_cloud_provider").withServiceName("origin_cloud_service_name"); - TraceContext ctx = transaction.getTraceContext(); + TraceContextImpl ctx = transaction.getTraceContext(); String serviceName = RandomStringUtils.randomAlphabetic(5); String serviceVersion = RandomStringUtils.randomAlphabetic(5); @@ -985,8 +1000,8 @@ void testTransactionContextSerialization() { @Test void testBodyBuffer() throws IOException { - final Transaction transaction = createRootTransaction(); - Request request = transaction.getContext().getRequest(); + final TransactionImpl transaction = createRootTransaction(); + RequestImpl request = transaction.getContext().getRequest(); final CharBuffer bodyBuffer = request.withBodyBuffer(); IOUtils.decodeUtf8Bytes("{f".getBytes(StandardCharsets.UTF_8), bodyBuffer); IOUtils.decodeUtf8Bytes(new byte[]{0, 0, 'o', 'o', 0}, 2, 2, bodyBuffer); @@ -1008,8 +1023,8 @@ void testBodyBuffer() throws IOException { */ @Test void testNonFlippedTransactionBodyBuffer() throws IOException { - final Transaction transaction = createRootTransaction(); - Request request = transaction.getContext().getRequest(); + final TransactionImpl transaction = createRootTransaction(); + RequestImpl request = transaction.getContext().getRequest(); request.withBodyBuffer().append("TEST"); final String content = writer.toJsonString(transaction); System.out.println(content); @@ -1019,13 +1034,13 @@ void testNonFlippedTransactionBodyBuffer() throws IOException { @Test void testBodyBufferCopy() throws IOException { - final Transaction transaction = createRootTransaction(); - Request request = transaction.getContext().getRequest(); + final TransactionImpl transaction = createRootTransaction(); + RequestImpl request = transaction.getContext().getRequest(); final CharBuffer bodyBuffer = request.withBodyBuffer(); IOUtils.decodeUtf8Bytes("{foo}".getBytes(StandardCharsets.UTF_8), bodyBuffer); request.endOfBufferInput(); - Transaction copy = createRootTransaction(); + TransactionImpl copy = createRootTransaction(); copy.getContext().copyFrom(transaction.getContext()); assertThat(objectMapper.readTree(writer.toJsonString(copy)).get("context")) @@ -1034,7 +1049,7 @@ void testBodyBufferCopy() throws IOException { @Test void testCustomContext() throws Exception { - final Transaction transaction = createRootTransaction(); + final TransactionImpl transaction = createRootTransaction(); transaction.addCustomContext("string", "foo"); final String longString = RandomStringUtils.randomAlphanumeric(10001); transaction.addCustomContext("long_string", longString); @@ -1050,7 +1065,7 @@ void testCustomContext() throws Exception { @Test void testJsonSchemaDslJsonEmptyValues() throws IOException { - Transaction transaction = new Transaction(tracer); + TransactionImpl transaction = new TransactionImpl(tracer); final String content = writer.toJsonString(transaction); System.out.println(content); JsonNode transactionNode = objectMapper.readTree(content); @@ -1271,11 +1286,11 @@ void testActivationMethodMetadataUpdate(boolean value1, boolean value2 ) throws // because metadata is serialized only once, we need to ensure it's properly updated whenever needed // in particular when going from 'apm server version unknown' to 'apm server version known' - StacktraceConfiguration stacktraceConfiguration = mock(StacktraceConfiguration.class); + StacktraceConfigurationImpl stacktraceConfiguration = mock(StacktraceConfigurationImpl.class); apmServerClient = mock(ApmServerClient.class); doReturn(value1).when(apmServerClient).supportsActivationMethod(); - Service service = mock(Service.class); + ServiceImpl service = mock(ServiceImpl.class); Agent agent = new Agent("java-test", "1.0.0"); doReturn(agent).when(service).getAgent(); MetaData mockMetada = MetaDataMock.createDefaultMock(); @@ -1316,11 +1331,11 @@ private void checkMetadataActivationMethod(String json, @Nullable String expecte } private MetaData createMetaData() throws Exception { - return createMetaData(SystemInfo.create("hostname", 0, mock(ServerlessConfiguration.class))); + return createMetaData(SystemInfo.create("hostname", 0, mock(ServerlessConfigurationImpl.class))); } private MetaData createMetaData(SystemInfo system) throws Exception { - Service service = new Service().withAgent(new Agent("name", "version")).withName("name"); + ServiceImpl service = new ServiceImpl().withAgent(new Agent("name", "version")).withName("name"); final ProcessInfo processInfo = new ProcessInfo("title"); processInfo.getArgv().add("test"); return MetaDataMock.create(processInfo, service, system, createCloudProviderInfo(), new HashMap<>(0), createFaaSMetaDataExtension()).get(); @@ -1346,22 +1361,22 @@ private FaaSMetaDataExtension createFaaSMetaDataExtension() { ); } - private Transaction createRootTransaction(Sampler sampler) { - Transaction t = new Transaction(tracer); - t.startRoot(0, sampler, Baggage.EMPTY); + private TransactionImpl createRootTransaction(Sampler sampler) { + TransactionImpl t = new TransactionImpl(tracer); + t.startRoot(0, sampler, BaggageImpl.EMPTY); t.withType("type"); t.getContext().getRequest().withMethod("GET"); t.getContext().getRequest().getUrl().withFull("http://localhost:8080/foo/bar"); return t; } - private Transaction createRootTransaction() { + private TransactionImpl createRootTransaction() { return createRootTransaction(ConstantSampler.of(true)); } @Test void testSpanStackFrameSerialization() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.setStackTrace(Arrays.asList(StackFrame.of("foo.Bar", "baz"), StackFrame.of("foo.Bar$Baz", "qux"))); JsonNode spanJson = readJsonString(writer.toJsonString(span)); @@ -1394,10 +1409,10 @@ void testSampledRootTransaction() { private void testRootTransactionSampleRate(boolean sampled, double samplerRate, @Nullable Double expectedRate) { Sampler sampler = mock(Sampler.class); - doReturn(sampled).when(sampler).isSampled(any(Id.class)); + doReturn(sampled).when(sampler).isSampled(any(IdImpl.class)); doReturn(samplerRate).when(sampler).getSampleRate(); - Transaction transaction = createRootTransaction(sampler); + TransactionImpl transaction = createRootTransaction(sampler); JsonNode jsonTransaction = readJsonString(writer.toJsonString(transaction)); @@ -1415,15 +1430,15 @@ private void testRootTransactionSampleRate(boolean sampled, double samplerRate, void testSampledSpan_rateFromParent() { Sampler sampler = mock(Sampler.class); - doReturn(true).when(sampler).isSampled(any(Id.class)); + doReturn(true).when(sampler).isSampled(any(IdImpl.class)); doReturn(0.42d).when(sampler).getSampleRate(); - Transaction transaction = createRootTransaction(sampler); - TraceContext transactionContext = transaction.getTraceContext(); + TransactionImpl transaction = createRootTransaction(sampler); + TraceContextImpl transactionContext = transaction.getTraceContext(); assertThat(transactionContext.isSampled()).isTrue(); assertThat(transactionContext.getSampleRate()).isEqualTo(0.42d); - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getTraceContext().asChildOf(transactionContext); JsonNode jsonSpan = readJsonString(writer.toJsonString(span)); @@ -1434,10 +1449,10 @@ void testSampledSpan_rateFromParent() { @Test void testNonSampledTransaction() { Sampler sampler = mock(Sampler.class); - doReturn(false).when(sampler).isSampled(any(Id.class)); + doReturn(false).when(sampler).isSampled(any(IdImpl.class)); doReturn(0.42d).when(sampler).getSampleRate(); - Transaction transaction = createRootTransaction(sampler); - TraceContext transactionContext = transaction.getTraceContext(); + TransactionImpl transaction = createRootTransaction(sampler); + TraceContextImpl transactionContext = transaction.getTraceContext(); assertThat(transactionContext.isSampled()).isFalse(); assertThat(transactionContext.getSampleRate()).isEqualTo(0.0d); JsonNode transactionSpan = readJsonString(writer.toJsonString(transaction)); @@ -1450,7 +1465,7 @@ void multiValueHeaders(boolean supportsMulti) { // older versions of APM server do not support multi-value headers // thus we should make sure to not break those - Transaction transaction = createRootTransaction(); + TransactionImpl transaction = createRootTransaction(); transaction.getContext().getRequest() .addHeader("user-agent", "user-agent1") @@ -1491,14 +1506,14 @@ void multiValueHeaders(boolean supportsMulti) { @Test void testOTelSpanSerialization() { - Span span = new Span(tracer).withName("otel span"); + SpanImpl span = new SpanImpl(tracer).withName("otel span"); testOTelSpanSerialization(span, s -> readJsonString(writer.toJsonString(s))); - Transaction transaction = new Transaction(MockTracer.create()).withName("otel span"); + TransactionImpl transaction = new TransactionImpl(MockTracer.create()).withName("otel span"); testOTelSpanSerialization(transaction, t -> readJsonString(writer.toJsonString(t))); } - private > void testOTelSpanSerialization(T context, Function toJson) { + private > void testOTelSpanSerialization(T context, Function toJson) { assertThat(context.getOtelKind()) .describedAs("otel span kind should not be set by default") @@ -1537,7 +1552,7 @@ private > void testOTelSpanSerialization(T context, Fu @Test void testNonCompositeSpan() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); JsonNode jsonSpan = readJsonString(writer.toJsonString(span)); assertThat(jsonSpan.get("composite")).isNull(); @@ -1545,7 +1560,7 @@ void testNonCompositeSpan() { @Test void testCompositeSpan() { - Span span = new Span(tracer); + SpanImpl span = new SpanImpl(tracer); span.getComposite().init(1234, "exact_match"); JsonNode jsonSpan = readJsonString(writer.toJsonString(span)); @@ -1560,12 +1575,12 @@ void testCompositeSpan() { @Test void testSpanLinksSerialization() { - Transaction transaction = tracer.startRootTransaction(null); - Span parent1 = Objects.requireNonNull(transaction).createSpan(); + TransactionImpl transaction = tracer.startRootTransaction(null); + SpanImpl parent1 = Objects.requireNonNull(transaction).createSpan(); Map textTraceContextCarrier = new HashMap<>(); parent1.propagateContext(textTraceContextCarrier, TextHeaderMapAccessor.INSTANCE, null); transaction.addSpanLink(TextHeaderMapAccessor.INSTANCE, textTraceContextCarrier); - Span parent2 = transaction.createSpan(); + SpanImpl parent2 = transaction.createSpan(); Map binaryTraceContextCarrier = new HashMap<>(); parent2.propagateContext(binaryTraceContextCarrier, TextHeaderMapAccessor.INSTANCE, null); transaction.addSpanLink(TextHeaderMapAccessor.INSTANCE, binaryTraceContextCarrier); @@ -1584,15 +1599,15 @@ void testSpanLinksSerialization() { assertThat(parent2link.get("span_id").textValue()).isEqualTo(parent2.getTraceContext().getId().toString()); } - private static Id create128BitId(String id) { - Id idObj = Id.new128BitId(); + private static IdImpl create128BitId(String id) { + IdImpl idObj = IdImpl.new128BitId(); idObj.fromHexString(id, 0); return idObj; } @Test void testProfilingStackTraceIdSerialization() { - Transaction transaction = tracer.startRootTransaction(null); + TransactionImpl transaction = tracer.startRootTransaction(null); transaction.addProfilerCorrelationStackTrace(create128BitId("a1a2a3a4a5a6a7a8b1b2b3b4b5b6b7b8")); transaction.addProfilerCorrelationStackTrace(create128BitId("c1c2c3c4c5c6c7c8d1d2d3d4d5d6d7d8")); @@ -1696,7 +1711,7 @@ private String toJson(Map map) { } private String serializeTags(Map tags) { - final AbstractContext context = new AbstractContext() { + final AbstractContextImpl context = new AbstractContextImpl() { }; for (Map.Entry entry : tags.entrySet()) { if (entry.getValue() instanceof String) { diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/MetricSetSerializationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/MetricSetSerializationTest.java index 1abc82a114..964ac02e6f 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/MetricSetSerializationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/MetricSetSerializationTest.java @@ -18,13 +18,13 @@ */ package co.elastic.apm.agent.report.serialize; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.tracer.service.ServiceInfo; import co.elastic.apm.agent.tracer.metrics.Labels; import co.elastic.apm.agent.metrics.MetricCollector; import co.elastic.apm.agent.metrics.MetricRegistry; import co.elastic.apm.agent.metrics.MetricsProvider; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import com.dslplatform.json.JsonWriter; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -44,7 +44,7 @@ class MetricSetSerializationTest { private ObjectMapper objectMapper = new ObjectMapper(); - private MetricRegistry registry = new MetricRegistry(mock(ReporterConfiguration.class), spy(MetricsConfiguration.class)); + private MetricRegistry registry = new MetricRegistry(mock(ReporterConfigurationImpl.class), spy(MetricsConfigurationImpl.class)); private MetricRegistrySerializer metricRegistrySerializer = new MetricRegistrySerializer(); @Test diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/SerializationConstantsTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/SerializationConstantsTest.java index e6dbdd16db..7b3e743325 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/SerializationConstantsTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/report/serialize/SerializationConstantsTest.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import net.bytebuddy.agent.ByteBuddyAgent; @@ -49,7 +49,7 @@ void getDefaults() { void overrideDefaults() { ConfigurationRegistry config = SpyConfiguration.createSpyConfig(); - CoreConfiguration configuration = config.getConfig(CoreConfiguration.class); + CoreConfigurationImpl configuration = config.getConfig(CoreConfigurationImpl.class); doReturn(42).when(configuration).getLongFieldMaxLength(); MockTracer.MockInstrumentationSetup mockInstrumentationSetup = MockTracer.createMockInstrumentationSetup(config); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/AbstractSpanAssert.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/AbstractSpanAssert.java index fd21a92d17..50398baf1b 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/AbstractSpanAssert.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/AbstractSpanAssert.java @@ -18,14 +18,14 @@ */ package co.elastic.apm.agent.testutils.assertions; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import co.elastic.apm.agent.tracer.Outcome; import java.util.Objects; import java.util.stream.Collectors; -public class AbstractSpanAssert, ACTUAL extends AbstractSpan> extends ElasticContextAssert { +public class AbstractSpanAssert, ACTUAL extends AbstractSpanImpl> extends ElasticContextAssert { protected AbstractSpanAssert(ACTUAL actual, Class selfType) { super(actual, selfType); @@ -64,9 +64,9 @@ public SELF isNotExit() { return thiz(); } - public SELF hasParent(AbstractSpan expectedParent) { - TraceContext parentCtx = expectedParent.getTraceContext(); - TraceContext actualCtx = actual.getTraceContext(); + public SELF hasParent(AbstractSpanImpl expectedParent) { + TraceContextImpl parentCtx = expectedParent.getTraceContext(); + TraceContextImpl actualCtx = actual.getTraceContext(); checkObject("Expected span to have traceId '%s' but was '%s'", parentCtx.getTraceId(), actualCtx.getTraceId()); checkObject("Expected span to have parent-Id '%s' but was '%s'", parentCtx.getId(), actualCtx.getParentId()); @@ -80,7 +80,7 @@ public SELF hasSpanLinkCount(int expected) { return thiz(); } - public SELF hasSpanLink(AbstractSpan expectedLink) { + public SELF hasSpanLink(AbstractSpanImpl expectedLink) { if (!checkSpanLinksContain(expectedLink.getTraceContext())) { String links = actual.getSpanLinks().stream() .map(ctx -> String.format("%s-%s", ctx.getTraceId(), ctx.getParentId())) @@ -101,7 +101,7 @@ public SELF hasOtelAttribute(String key, Object expectedValue) { return thiz(); } - private boolean checkSpanLinksContain(TraceContext expectedLink) { + private boolean checkSpanLinksContain(TraceContextImpl expectedLink) { return actual.getSpanLinks().stream() .anyMatch(ctx -> Objects.equals(ctx.getParentId(), expectedLink.getId()) && Objects.equals(ctx.getTraceId(), expectedLink.getTraceId()) diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/Assertions.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/Assertions.java index 8a680803cf..c640665c9d 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/Assertions.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/Assertions.java @@ -18,13 +18,13 @@ */ package co.elastic.apm.agent.testutils.assertions; -import co.elastic.apm.agent.impl.baggage.Baggage; -import co.elastic.apm.agent.impl.context.Db; -import co.elastic.apm.agent.impl.context.Destination; -import co.elastic.apm.agent.impl.context.ServiceTarget; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; +import co.elastic.apm.agent.impl.context.DbImpl; +import co.elastic.apm.agent.impl.context.DestinationImpl; +import co.elastic.apm.agent.impl.context.ServiceTargetImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.testutils.assertions.metrics.MetricSetsAssert; import java.util.Collection; @@ -34,27 +34,27 @@ public class Assertions extends org.assertj.core.api.Assertions { private Assertions() { } - public static ServiceTargetAssert assertThat(ServiceTarget serviceTarget) { + public static ServiceTargetAssert assertThat(ServiceTargetImpl serviceTarget) { return new ServiceTargetAssert(serviceTarget); } - public static DestinationAssert assertThat(Destination destination) { + public static DestinationAssert assertThat(DestinationImpl destination) { return new DestinationAssert(destination); } - public static SpanAssert assertThat(Span span) { + public static SpanAssert assertThat(SpanImpl span) { return new SpanAssert(span); } - public static DbAssert assertThat(Db db) { + public static DbAssert assertThat(DbImpl db) { return new DbAssert(db); } - public static AbstractSpanAssert assertThat(AbstractSpan span) { + public static AbstractSpanAssert assertThat(AbstractSpanImpl span) { return new AbstractSpanAssert<>(span, AbstractSpanAssert.class); } - public static ElasticContextAssert assertThat(ElasticContext span) { + public static ElasticContextAssert assertThat(TraceStateImpl span) { return new ElasticContextAssert<>(span, ElasticContextAssert.class); } @@ -62,7 +62,7 @@ public static MetricSetsAssert assertThatMetricSets(Collection metricset return new MetricSetsAssert(metricsetsJson); } - public static BaggageAssert assertThat(Baggage baggage) { + public static BaggageAssert assertThat(BaggageImpl baggage) { return new BaggageAssert(baggage); } } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/BaggageAssert.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/BaggageAssert.java index a31cccabc1..0b6f1a9997 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/BaggageAssert.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/BaggageAssert.java @@ -18,14 +18,14 @@ */ package co.elastic.apm.agent.testutils.assertions; -import co.elastic.apm.agent.impl.baggage.Baggage; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; import javax.annotation.Nullable; import java.util.Objects; -public class BaggageAssert extends BaseAssert { +public class BaggageAssert extends BaseAssert { - protected BaggageAssert(Baggage actual) { + protected BaggageAssert(BaggageImpl actual) { super(actual, BaggageAssert.class); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/DbAssert.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/DbAssert.java index 6a3b5069a3..69825f0018 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/DbAssert.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/DbAssert.java @@ -18,14 +18,14 @@ */ package co.elastic.apm.agent.testutils.assertions; -import co.elastic.apm.agent.impl.context.Db; +import co.elastic.apm.agent.impl.context.DbImpl; import javax.annotation.Nullable; import java.nio.CharBuffer; -public class DbAssert extends BaseAssert { +public class DbAssert extends BaseAssert { - protected DbAssert(Db actual) { + protected DbAssert(DbImpl actual) { super(actual, DbAssert.class); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/DestinationAssert.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/DestinationAssert.java index dde666dcf2..70259210f2 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/DestinationAssert.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/DestinationAssert.java @@ -18,11 +18,11 @@ */ package co.elastic.apm.agent.testutils.assertions; -import co.elastic.apm.agent.impl.context.Destination; +import co.elastic.apm.agent.impl.context.DestinationImpl; -public class DestinationAssert extends BaseAssert { +public class DestinationAssert extends BaseAssert { - DestinationAssert(Destination actual) { + DestinationAssert(DestinationImpl actual) { super(actual, DestinationAssert.class); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/ElasticContextAssert.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/ElasticContextAssert.java index 7e140bea1e..76e7611ca6 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/ElasticContextAssert.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/ElasticContextAssert.java @@ -18,9 +18,9 @@ */ package co.elastic.apm.agent.testutils.assertions; -import co.elastic.apm.agent.impl.transaction.ElasticContext; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; -public class ElasticContextAssert, ACTUAL extends ElasticContext> extends BaseAssert { +public class ElasticContextAssert, ACTUAL extends TraceStateImpl> extends BaseAssert { protected ElasticContextAssert(ACTUAL actual, Class selfType) { super(actual, selfType); diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/ServiceTargetAssert.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/ServiceTargetAssert.java index 58fad0cec1..49aafc6e67 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/ServiceTargetAssert.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/ServiceTargetAssert.java @@ -18,11 +18,11 @@ */ package co.elastic.apm.agent.testutils.assertions; -import co.elastic.apm.agent.impl.context.ServiceTarget; +import co.elastic.apm.agent.impl.context.ServiceTargetImpl; -public class ServiceTargetAssert extends BaseAssert { +public class ServiceTargetAssert extends BaseAssert { - ServiceTargetAssert(ServiceTarget actual) { + ServiceTargetAssert(ServiceTargetImpl actual) { super(actual, ServiceTargetAssert.class); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/SpanAssert.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/SpanAssert.java index dacc4f78cc..2794429dd7 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/SpanAssert.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/testutils/assertions/SpanAssert.java @@ -18,11 +18,11 @@ */ package co.elastic.apm.agent.testutils.assertions; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; -public class SpanAssert extends AbstractSpanAssert { +public class SpanAssert extends AbstractSpanAssert { - protected SpanAssert(Span actual) { + protected SpanAssert(SpanImpl actual) { super(actual, SpanAssert.class); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentationTest.java index 393e2cce56..0be632fabc 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/tracemethods/TraceMethodInstrumentationTest.java @@ -22,11 +22,11 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.TracerInternalApiUtils; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.matcher.MethodMatcher; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import co.elastic.apm.agent.tracer.configuration.TimeDuration; @@ -53,7 +53,7 @@ class TraceMethodInstrumentationTest { private MockReporter reporter; private TestObjectPoolFactory objectPoolFactory; private ElasticApmTracer tracer; - private CoreConfiguration coreConfiguration; + private CoreConfigurationImpl coreConfiguration; @BeforeEach void setUp(TestInfo testInfo) { @@ -61,7 +61,7 @@ void setUp(TestInfo testInfo) { reporter = mockInstrumentationSetup.getReporter(); objectPoolFactory = mockInstrumentationSetup.getObjectPoolFactory(); ConfigurationRegistry config = mockInstrumentationSetup.getConfig(); - coreConfiguration = config.getConfig(CoreConfiguration.class); + coreConfiguration = config.getConfig(CoreConfigurationImpl.class); doReturn(Arrays.asList( MethodMatcher.of("private co.elastic.apm.agent.tracemethods.TraceMethodInstrumentationTest$TestClass#traceMe*()"), MethodMatcher.of("private co.elastic.apm.agent.tracemethods.TraceMethodInstrumentationTest$TestDiscardableMethods#*"), @@ -230,7 +230,7 @@ void testErrorCapture_TraceAll() { void testErrorCapture_TraceErrorBranch() { new TestErrorCapture().root(); assertThat(reporter.getTransactions()).hasSize(1); - assertThat(reporter.getSpans().stream().map(Span::getNameAsString)).containsExactly("TestErrorCapture#throwException", "TestErrorCapture#catchException"); + assertThat(reporter.getSpans().stream().map(SpanImpl::getNameAsString)).containsExactly("TestErrorCapture#throwException", "TestErrorCapture#catchException"); assertThat(reporter.getErrors()).hasSize(1); } @@ -350,9 +350,9 @@ private void mainMethod(boolean invokeManual) { } private void manuallyTraced() { - AbstractSpan active = tracer.getActive(); + AbstractSpanImpl active = tracer.getActive(); if (active != null) { - Span span = active.createSpan(); + SpanImpl span = active.createSpan(); span.propagateContext(new HashMap<>(), (TextHeaderSetter>) (k, v, m) -> m.put(k, v), null); span.end(); } diff --git a/apm-agent-core/src/test/java/co/elastic/apm/agent/universalprofiling/UniversalProfilingIntegrationTest.java b/apm-agent-core/src/test/java/co/elastic/apm/agent/universalprofiling/UniversalProfilingIntegrationTest.java index d9ec6cfb36..255b1b876c 100644 --- a/apm-agent-core/src/test/java/co/elastic/apm/agent/universalprofiling/UniversalProfilingIntegrationTest.java +++ b/apm-agent-core/src/test/java/co/elastic/apm/agent/universalprofiling/UniversalProfilingIntegrationTest.java @@ -20,15 +20,15 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.configuration.UniversalProfilingConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.sampling.ConstantSampler; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Id; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.IdImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import co.elastic.otel.JvmtiAccessImpl; import org.assertj.core.api.Assertions; @@ -139,9 +139,9 @@ class SharedMemory { public void testNestedActivations() { setupTracer(); - Transaction first = tracer.startRootTransaction(null); - Transaction second = tracer.startRootTransaction(null); - Span third = second.createSpan(); + TransactionImpl first = tracer.startRootTransaction(null); + TransactionImpl second = tracer.startRootTransaction(null); + SpanImpl third = second.createSpan(); checkTlsIs(null); @@ -190,7 +190,7 @@ public void testProcessStoragePopulated(String environment) { UniversalProfilingConfiguration profConfig = conf.getConfig(UniversalProfilingConfiguration.class); doReturn(true).when(profConfig).isEnabled(); doReturn(tempDir.toAbsolutePath().toString()).when(profConfig).getSocketDir(); - CoreConfiguration core = conf.getConfig(CoreConfiguration.class); + CoreConfigurationImpl core = conf.getConfig(CoreConfigurationImpl.class); doReturn("service Ä 1").when(core).getServiceName(); doReturn(environment).when(core).getEnvironment(); }); @@ -212,7 +212,7 @@ private String readUtf8Str(ByteBuffer buffer) { } } - static void checkTlsIs(@Nullable AbstractSpan span) { + static void checkTlsIs(@Nullable AbstractSpanImpl span) { ByteBuffer tls = JvmtiAccessImpl.createThreadProfilingCorrelationBufferAlias(TLS_STORAGE_SIZE); if (tls != null) { tls.order(ByteOrder.nativeOrder()); @@ -256,16 +256,16 @@ void checkCorrelationFunctional() { sendProfilerRegistrationMsg(1, "hostid"); - Transaction tx1 = tracer.startRootTransaction(null); - Transaction tx2 = tracer.startRootTransaction(null); + TransactionImpl tx1 = tracer.startRootTransaction(null); + TransactionImpl tx2 = tracer.startRootTransaction(null); - Id st1 = randomStackTraceId(1); + IdImpl st1 = randomStackTraceId(1); sendSampleMsg(tx1, st1, 1); // Send some garbage which should not affect our processing JvmtiAccessImpl.sendToProfilerReturnChannelSocket0(new byte[]{1, 2, 3}); - Id st2 = randomStackTraceId(2); + IdImpl st2 = randomStackTraceId(2); sendSampleMsg(tx2, st2, 2); // ensure that the messages are processed now @@ -277,7 +277,7 @@ void checkCorrelationFunctional() { // ensure that spans are not sent, their delay has not yet elapsed assertThat(reporter.getTransactions()).isEmpty(); - Id st3 = randomStackTraceId(3); + IdImpl st3 = randomStackTraceId(3); sendSampleMsg(tx2, st2, 1); sendSampleMsg(tx1, st3, 2); sendSampleMsg(tx2, st3, 1); @@ -310,7 +310,7 @@ void unsampledTransactionsNotCorrelated() { sendProfilerRegistrationMsg(1, "hostid"); - Transaction tx = tracer.startRootTransaction(ConstantSampler.of(false), 0L, null); + TransactionImpl tx = tracer.startRootTransaction(ConstantSampler.of(false), 0L, null); assertThat(tx.isSampled()).isFalse(); // Still send a stacktrace to make sure it is actually ignored @@ -326,7 +326,7 @@ void unsampledTransactionsNotCorrelated() { @Test void shutdownFlushesBufferedSpans() { - Id st1 = randomStackTraceId(1); + IdImpl st1 = randomStackTraceId(1); setupTracer(); UniversalProfilingIntegration profilingIntegration = tracer.getProfilingIntegration(); @@ -335,7 +335,7 @@ void shutdownFlushesBufferedSpans() { sendProfilerRegistrationMsg(1, "hostid"); profilingIntegration.periodicTimer(); - Transaction tx = tracer.startRootTransaction(null); + TransactionImpl tx = tracer.startRootTransaction(null); tx.end(); profilingIntegration.periodicTimer(); @@ -362,16 +362,16 @@ void bufferCapacityExceeded() { sendProfilerRegistrationMsg(1, "hostid"); profilingIntegration.periodicTimer(); - Transaction tx1 = tracer.startRootTransaction(null); + TransactionImpl tx1 = tracer.startRootTransaction(null); tx1.end(); - Transaction tx2 = tracer.startRootTransaction(null); + TransactionImpl tx2 = tracer.startRootTransaction(null); tx2.end(); //the actual buffer capacity is 2 + 1 because the peeked transaction is stored outside of the buffer profilingIntegration.periodicTimer(); - Transaction tx3 = tracer.startRootTransaction(null); + TransactionImpl tx3 = tracer.startRootTransaction(null); tx3.end(); // now the buffer should be full, transaction 4 should be sent immediately - Transaction tx4 = tracer.startRootTransaction(null); + TransactionImpl tx4 = tracer.startRootTransaction(null); tx4.end(); Assertions.assertThat(reporter.getTransactions()).containsExactly(tx4); @@ -423,15 +423,15 @@ void socketParentDirCreated() throws Exception { } - private Id randomStackTraceId(int seed) { + private IdImpl randomStackTraceId(int seed) { byte[] id = new byte[16]; new Random(seed).nextBytes(id); - Id idObj = Id.new128BitId(); + IdImpl idObj = IdImpl.new128BitId(); idObj.fromBytes(id, 0); return idObj; } - void sendSampleMsg(Transaction transaction, Id stackTraceId, int count) { + void sendSampleMsg(TransactionImpl transaction, IdImpl stackTraceId, int count) { byte[] traceId = idToBytes(transaction.getTraceContext().getTraceId()); byte[] transactionId = idToBytes(transaction.getTraceContext().getId()); @@ -462,7 +462,7 @@ void sendProfilerRegistrationMsg(int sampleDelayMillis, String hostId) { } } - private static byte[] idToBytes(Id id) { + private static byte[] idToBytes(IdImpl id) { byte[] buff = new byte[32]; int len = id.toBytes(buff, 0); byte[] result = new byte[len]; diff --git a/apm-agent-core/src/test/java/org/example/stacktrace/ErrorCaptureTest.java b/apm-agent-core/src/test/java/org/example/stacktrace/ErrorCaptureTest.java index 580a1eac28..29ed723f95 100644 --- a/apm-agent-core/src/test/java/org/example/stacktrace/ErrorCaptureTest.java +++ b/apm-agent-core/src/test/java/org/example/stacktrace/ErrorCaptureTest.java @@ -20,13 +20,13 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.error.ErrorCapture; +import co.elastic.apm.agent.impl.context.RequestImpl; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.impl.error.RedactedException; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,19 +38,19 @@ class ErrorCaptureTest { private ElasticApmTracer tracer; - private StacktraceConfiguration stacktraceConfiguration; - private CoreConfiguration coreConfiguration; + private StacktraceConfigurationImpl stacktraceConfiguration; + private CoreConfigurationImpl coreConfiguration; @BeforeEach void setUp() { tracer = MockTracer.createRealTracer(); - stacktraceConfiguration = tracer.getConfig(StacktraceConfiguration.class); - coreConfiguration = tracer.getConfig(CoreConfiguration.class); + stacktraceConfiguration = tracer.getConfig(StacktraceConfigurationImpl.class); + coreConfiguration = tracer.getConfig(CoreConfigurationImpl.class); } @Test void testCulpritApplicationPackagesNotConfigured() { - final ErrorCapture errorCapture = new ErrorCapture(tracer); + final ErrorCaptureImpl errorCapture = new ErrorCaptureImpl(tracer); errorCapture.setException(new Exception()); assertThat(errorCapture.getCulprit()).isEmpty(); } @@ -58,7 +58,7 @@ void testCulpritApplicationPackagesNotConfigured() { @Test void testCulprit() { doReturn(List.of("org.example.stacktrace")).when(stacktraceConfiguration).getApplicationPackages(); - final ErrorCapture errorCapture = new ErrorCapture(tracer); + final ErrorCaptureImpl errorCapture = new ErrorCaptureImpl(tracer); final Exception nestedException = new Exception(); final Exception topLevelException = new Exception(nestedException); errorCapture.setException(topLevelException); @@ -69,7 +69,7 @@ void testCulprit() { @Test void testUnnestNestedException() { final NestedException nestedException = new NestedException(new CustomException()); - ErrorCapture errorCapture = tracer.captureException(nestedException, tracer.currentContext(), null); + ErrorCaptureImpl errorCapture = tracer.captureException(nestedException, tracer.currentContext(), null); assertThat(errorCapture).isNotNull(); assertThat(errorCapture.getException()).isNotInstanceOf(NestedException.class); assertThat(errorCapture.getException()).isInstanceOf(CustomException.class); @@ -78,7 +78,7 @@ void testUnnestNestedException() { @Test void testUnnestDoublyNestedException() { final NestedException nestedException = new NestedException(new NestedException(new CustomException())); - ErrorCapture errorCapture = tracer.captureException(nestedException, tracer.currentContext(), null); + ErrorCaptureImpl errorCapture = tracer.captureException(nestedException, tracer.currentContext(), null); assertThat(errorCapture).isNotNull(); assertThat(errorCapture.getException()).isNotInstanceOf(NestedException.class); assertThat(errorCapture.getException()).isInstanceOf(CustomException.class); @@ -88,14 +88,14 @@ void testUnnestDoublyNestedException() { void testIgnoredNestedException() { doReturn(List.of(WildcardMatcher.valueOf("*CustomException"))).when(coreConfiguration).getIgnoreExceptions(); final NestedException nestedException = new NestedException(new CustomException()); - ErrorCapture errorCapture = tracer.captureException(nestedException, tracer.currentContext(), null); + ErrorCaptureImpl errorCapture = tracer.captureException(nestedException, tracer.currentContext(), null); assertThat(errorCapture).isNull(); } @Test void testNonConfiguredNestingException() { final WrapperException wrapperException = new WrapperException(new CustomException()); - ErrorCapture errorCapture = tracer.captureException(wrapperException, tracer.currentContext(), null); + ErrorCaptureImpl errorCapture = tracer.captureException(wrapperException, tracer.currentContext(), null); assertThat(errorCapture).isNotNull(); assertThat(errorCapture.getException()).isInstanceOf(WrapperException.class); } @@ -103,7 +103,7 @@ void testNonConfiguredNestingException() { @Test void testNonConfiguredWrappingConfigured() { final NestedException nestedException = new NestedException(new WrapperException(new NestedException(new Exception()))); - ErrorCapture errorCapture = tracer.captureException(nestedException, tracer.currentContext(), null); + ErrorCaptureImpl errorCapture = tracer.captureException(nestedException, tracer.currentContext(), null); assertThat(errorCapture).isNotNull(); assertThat(errorCapture.getException()).isInstanceOf(WrapperException.class); } @@ -120,11 +120,11 @@ void testExceptionRedaction() { // double redaction means no instanceof check assertThat(tracer.redactExceptionIfRequired(redacted)).isNotSameAs(redacted); - ErrorCapture errorCapture = tracer.captureException(exception, tracer.currentContext(), null); + ErrorCaptureImpl errorCapture = tracer.captureException(exception, tracer.currentContext(), null); assertThat(errorCapture).isNotNull(); assertThat(errorCapture.getException()).isInstanceOf(RedactedException.class); - ErrorCapture alreadyRedacted = tracer.captureException(redacted, tracer.currentContext(), null); + ErrorCaptureImpl alreadyRedacted = tracer.captureException(redacted, tracer.currentContext(), null); assertThat(alreadyRedacted).isNotNull(); assertThat(alreadyRedacted.getException()).isNotSameAs(redacted); } @@ -146,14 +146,14 @@ private static class CustomException extends Exception {} @Test void testTransactionContextTransfer() { - final Transaction transaction = new Transaction(tracer); - Request transactionRequest = transaction.getContext().getRequest() + final TransactionImpl transaction = new TransactionImpl(tracer); + RequestImpl transactionRequest = transaction.getContext().getRequest() .withMethod("GET") .addHeader("key", "value"); transactionRequest.withBodyBuffer().append("TEST"); transactionRequest.endOfBufferInput(); - final ErrorCapture errorCapture = new ErrorCapture(tracer).asChildOf(transaction); - Request errorRequest = errorCapture.getContext().getRequest(); + final ErrorCaptureImpl errorCapture = new ErrorCaptureImpl(tracer).asChildOf(transaction); + RequestImpl errorRequest = errorCapture.getContext().getRequest(); assertThat(errorRequest.getMethod()).isEqualTo("GET"); assertThat(errorRequest.getHeaders().get("key")).isEqualTo("value"); assertThat(errorRequest.getBodyBufferForSerialization()).isNotNull(); @@ -162,13 +162,13 @@ void testTransactionContextTransfer() { @Test void testTransactionContextTransferNonFinishedBody() { - final Transaction transaction = new Transaction(tracer); - Request transactionRequest = transaction.getContext().getRequest() + final TransactionImpl transaction = new TransactionImpl(tracer); + RequestImpl transactionRequest = transaction.getContext().getRequest() .withMethod("GET") .addHeader("key", "value"); transactionRequest.withBodyBuffer().append("TEST"); - final ErrorCapture errorCapture = new ErrorCapture(tracer).asChildOf(transaction); - Request errorRequest = errorCapture.getContext().getRequest(); + final ErrorCaptureImpl errorCapture = new ErrorCaptureImpl(tracer).asChildOf(transaction); + RequestImpl errorRequest = errorCapture.getContext().getRequest(); assertThat(errorRequest.getMethod()).isEqualTo("GET"); assertThat(errorRequest.getHeaders().get("key")).isEqualTo("value"); assertThat(errorRequest.getBodyBufferForSerialization()) @@ -178,11 +178,11 @@ void testTransactionContextTransferNonFinishedBody() { @Test void testActiveError() { - assertThat(ErrorCapture.getActive()).isNull(); - ErrorCapture errorCapture = new ErrorCapture(tracer).activate(); - assertThat(ErrorCapture.getActive()).isNotNull(); + assertThat(ErrorCaptureImpl.getActive()).isNull(); + ErrorCaptureImpl errorCapture = new ErrorCaptureImpl(tracer).activate(); + assertThat(ErrorCaptureImpl.getActive()).isNotNull(); errorCapture.deactivate().end(); - assertThat(ErrorCapture.getActive()).isNull(); + assertThat(ErrorCaptureImpl.getActive()).isNull(); } diff --git a/apm-agent-core/src/test/java/org/example/stacktrace/StacktraceSerializationTest.java b/apm-agent-core/src/test/java/org/example/stacktrace/StacktraceSerializationTest.java index 4b4981d6ba..38be48f6c3 100644 --- a/apm-agent-core/src/test/java/org/example/stacktrace/StacktraceSerializationTest.java +++ b/apm-agent-core/src/test/java/org/example/stacktrace/StacktraceSerializationTest.java @@ -20,9 +20,9 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import com.fasterxml.jackson.databind.JsonNode; @@ -48,7 +48,7 @@ class StacktraceSerializationTest { private List stacktrace; - private StacktraceConfiguration stacktraceConfiguration; + private StacktraceConfigurationImpl stacktraceConfiguration; private DslJsonSerializer.Writer serializer; private ObjectMapper objectMapper; private ElasticApmTracer tracer; @@ -56,7 +56,7 @@ class StacktraceSerializationTest { @BeforeEach void setUp() throws IOException { tracer = MockTracer.createRealTracer(); - stacktraceConfiguration = tracer.getConfig(StacktraceConfiguration.class); + stacktraceConfiguration = tracer.getConfig(StacktraceConfigurationImpl.class); // always enable doReturn(0L).when(stacktraceConfiguration).getSpanStackTraceMinDurationMs(); serializer = new DslJsonSerializer(stacktraceConfiguration, mock(ApmServerClient.class), tracer.getMetaDataFuture()) @@ -143,8 +143,8 @@ void testStackTraceElementSerialization() throws IOException { private List getStackTrace() throws IOException { - final Transaction transaction = tracer.startRootTransaction(getClass().getClassLoader()); - final Span span = transaction.createSpan(); + final TransactionImpl transaction = tracer.startRootTransaction(getClass().getClassLoader()); + final SpanImpl span = transaction.createSpan(); span.end(); transaction.end(); return StreamSupport.stream(objectMapper diff --git a/apm-agent-core/src/test/java/specs/OutcomeStepsDefinitions.java b/apm-agent-core/src/test/java/specs/OutcomeStepsDefinitions.java index 7ba00b5f35..72f1460873 100644 --- a/apm-agent-core/src/test/java/specs/OutcomeStepsDefinitions.java +++ b/apm-agent-core/src/test/java/specs/OutcomeStepsDefinitions.java @@ -18,11 +18,11 @@ */ package specs; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.util.ResultUtil; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; @@ -62,31 +62,31 @@ public void thenOutcomeIs(String context, String outcome) { @Given("a HTTP call is made that returns {int}") public void httpSpanWithStatus(int code) { - Span span = state.getSpan(); + SpanImpl span = state.getSpan(); span.withName(String.format("HTTP span status = %d", code)); span.withOutcome(ResultUtil.getOutcomeByHttpClientStatus(code)); } @Given("a HTTP call is received that returns {int}") public void httpTransactionWithStatus(int code) { - Transaction transaction = state.getTransaction(); + TransactionImpl transaction = state.getTransaction(); transaction.withName(String.format("HTTP transaction status = %d", code)); transaction.withOutcome(ResultUtil.getOutcomeByHttpServerStatus(code)); } // utilities - static void setUserOutcome(AbstractSpan context, Outcome outcome) { + static void setUserOutcome(AbstractSpanImpl context, Outcome outcome) { assertThat(context).isNotNull(); context.withUserOutcome(outcome); } - static void setInternalOutcome(AbstractSpan context, Outcome outcome) { + static void setInternalOutcome(AbstractSpanImpl context, Outcome outcome) { assertThat(context).isNotNull(); context.withOutcome(outcome); } - static void checkOutcome(AbstractSpan context, Outcome outcome) { + static void checkOutcome(AbstractSpanImpl context, Outcome outcome) { assertThat(context).isNotNull(); assertThat(context.getOutcome()) .describedAs("expected outcome = %s for context = %s", outcome, context) diff --git a/apm-agent-core/src/test/java/specs/ScenarioState.java b/apm-agent-core/src/test/java/specs/ScenarioState.java index 03ed2ea55e..d88b1a0651 100644 --- a/apm-agent-core/src/test/java/specs/ScenarioState.java +++ b/apm-agent-core/src/test/java/specs/ScenarioState.java @@ -20,9 +20,9 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.report.Reporter; import org.stagemonitor.configuration.ConfigurationOption; import org.stagemonitor.configuration.ConfigurationOptionProvider; @@ -53,8 +53,8 @@ public class ScenarioState { @Nullable private JsonNode apmServerResponse; - private Transaction transaction; - private Span span; + private TransactionImpl transaction; + private SpanImpl span; public ElasticApmTracer getTracer() { return Objects.requireNonNull(tracer); @@ -112,7 +112,7 @@ public void startRootTransactionIfRequired() { } } - public Transaction startTransaction() { + public TransactionImpl startTransaction() { if (transaction != null) { transaction.end(); } @@ -121,7 +121,7 @@ public Transaction startTransaction() { return transaction; } - public Span startSpan() { + public SpanImpl startSpan() { if (span != null) { span.end(); } @@ -134,11 +134,11 @@ public Span startSpan() { return span; } - public Transaction getTransaction() { + public TransactionImpl getTransaction() { return transaction; } - public Span getSpan() { + public SpanImpl getSpan() { return span; } @@ -147,7 +147,7 @@ public Span getSpan() { * @param contextType type name of the required context * @return the current span or transaction, based on the provided type name */ - public AbstractSpan getContext(String contextType) { + public AbstractSpanImpl getContext(String contextType) { return contextType.equals("span") ? getSpan() : getTransaction(); } } diff --git a/apm-agent-lambda-layer/pom.xml b/apm-agent-lambda-layer/pom.xml index a420d97983..efd720b954 100644 --- a/apm-agent-lambda-layer/pom.xml +++ b/apm-agent-lambda-layer/pom.xml @@ -3,7 +3,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugin-sdk/pom.xml b/apm-agent-plugin-sdk/pom.xml index ad6ce3eb48..7217eddb6f 100644 --- a/apm-agent-plugin-sdk/pom.xml +++ b/apm-agent-plugin-sdk/pom.xml @@ -3,7 +3,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/bytebuddy/MethodHierarchyMatcher.java b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/bytebuddy/MethodHierarchyMatcher.java index 84ec59657c..3d8a228afa 100644 --- a/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/bytebuddy/MethodHierarchyMatcher.java +++ b/apm-agent-plugin-sdk/src/main/java/co/elastic/apm/agent/sdk/bytebuddy/MethodHierarchyMatcher.java @@ -48,7 +48,7 @@ public class MethodHierarchyMatcher extends ElementMatcher.Junction.AbstractBase private final ElementMatcher hierarchyMatcher; MethodHierarchyMatcher(ElementMatcher extraMethodMatcher) { - this(extraMethodMatcher, not(is(TypeDescription.ForLoadedType.OBJECT)), any()); + this(extraMethodMatcher, not(is(TypeDescription.ForLoadedType.of(Object.class))), any()); } private MethodHierarchyMatcher(ElementMatcher extraMethodMatcher, ElementMatcher superClassMatcher, ElementMatcher hierachyMatcher) { diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/pom.xml b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/pom.xml index a6adc91895..6439fadad8 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/pom.xml +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/pom.xml @@ -5,7 +5,7 @@ apm-apache-httpclient co.elastic.apm - 1.50.0 + 1.51.0 apm-apache-httpclient-common diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/AbstractApacheHttpClientAdvice.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/AbstractApacheHttpClientAdvice.java index aa6c60f04d..1998180c3b 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/AbstractApacheHttpClientAdvice.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/AbstractApacheHttpClientAdvice.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.Tracer; @@ -34,15 +34,15 @@ public abstract class AbstractApacheHttpClientAdvice { public static & - TextHeaderGetter> Object startSpan(final Tracer tracer, + TextHeaderGetter> Span startSpan(final Tracer tracer, final ApacheHttpClientApiAdapter adapter, final WRAPPER request, @Nullable final HTTPHOST httpHost, final HeaderAccessor headerAccessor) throws URISyntaxException { - ElasticContext elasticContext = tracer.currentContext(); + TraceState traceState = tracer.currentContext(); Span span = null; - if (elasticContext.getSpan() != null) { - span = HttpClientHelper.startHttpClientSpan(elasticContext, adapter.getMethod(request), adapter.getUri(request), adapter.getHostName(httpHost, request)); + if (traceState.getSpan() != null) { + span = HttpClientHelper.startHttpClientSpan(traceState, adapter.getMethod(request), adapter.getUri(request), adapter.getHostName(httpHost, request)); if (span != null) { span.activate(); } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/AbstractApacheHttpClientAsyncAdvice.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/AbstractApacheHttpClientAsyncAdvice.java index 08aab1d912..a4fd57dbff 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/AbstractApacheHttpClientAsyncAdvice.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/AbstractApacheHttpClientAsyncAdvice.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.tracer.ElasticContext; import co.elastic.apm.agent.tracer.Span; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Tracer; public abstract class AbstractApacheHttpClientAsyncAdvice { @@ -30,16 +30,17 @@ public static asyncHelper, PRODUCER asyncRequestProducer, CONTEXT context, CALLBACK futureCallback) { - ElasticContext parentContext = tracer.currentContext(); + TraceState parentContext = tracer.currentContext(); if (parentContext.isEmpty()) { // performance optimization, no need to wrap if we have nothing to propagate // empty context means also we will not create an exit span return null; } CALLBACK wrappedFutureCallback = futureCallback; - ElasticContext activeContext = tracer.currentContext(); + TraceState activeContext = tracer.currentContext(); Span span = activeContext.createExitSpan(); if (span != null) { + span.getContext().getHttp().getRequestBody().markEligibleForCapturing(); span.withType(HttpClientHelper.EXTERNAL_TYPE) .withSubtype(HttpClientHelper.HTTP_SUBTYPE) .withSync(false) diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/ApacheHttpClientAsyncHelper.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/ApacheHttpClientAsyncHelper.java index 7f213dcc84..b7510f2901 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/ApacheHttpClientAsyncHelper.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient-common/src/main/java/co/elastic/apm/agent/httpclient/common/ApacheHttpClientAsyncHelper.java @@ -19,12 +19,12 @@ package co.elastic.apm.agent.httpclient.common; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Span; public interface ApacheHttpClientAsyncHelper { - AsyncProducerWrapper wrapRequestProducer(AsyncProducer asyncRequestProducer, Span span, ElasticContext toPropagate); + AsyncProducerWrapper wrapRequestProducer(AsyncProducer asyncRequestProducer, Span span, TraceState toPropagate); FutureCallbackWrapper wrapFutureCallback(FutureCallback futureCallback, HttpContext httpContext, Span span); diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/pom.xml b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/pom.xml index 10989b775f..ff116aeeb6 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/pom.xml +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/pom.xml @@ -5,7 +5,7 @@ apm-apache-httpclient co.elastic.apm - 1.50.0 + 1.51.0 apm-apache-httpclient3-plugin diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3Instrumentation.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3Instrumentation.java index 4f178a6df1..870045df09 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3Instrumentation.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient3-plugin/src/main/java/co/elastic/apm/agent/httpclient/v3/HttpClient3Instrumentation.java @@ -23,7 +23,7 @@ import co.elastic.apm.agent.sdk.internal.util.LoggerUtils; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; @@ -96,7 +96,7 @@ public static Object onEnter(@Advice.Argument(0) HttpMethod httpMethod, @Nullable private static Span startClientSpan(HttpMethod httpMethod, HostConfiguration hostConfiguration) { - final ElasticContext activeContext = tracer.currentContext(); + final TraceState activeContext = tracer.currentContext(); if (activeContext.getSpan() == null) { return null; } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/pom.xml b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/pom.xml index 755a3e3bc9..53336fe3ab 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/pom.xml +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/pom.xml @@ -5,7 +5,7 @@ apm-apache-httpclient co.elastic.apm - 1.50.0 + 1.51.0 apm-apache-httpclient4-plugin diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentation.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentation.java index 1d60900984..2bc725c95b 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentation.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentation.java @@ -20,7 +20,11 @@ import co.elastic.apm.agent.httpclient.common.AbstractApacheHttpClientAdvice; import co.elastic.apm.agent.httpclient.v4.helper.ApacheHttpClient4ApiAdapter; +import co.elastic.apm.agent.httpclient.v4.helper.RequestBodyCaptureRegistry; import co.elastic.apm.agent.httpclient.v4.helper.RequestHeaderAccessor; +import co.elastic.apm.agent.sdk.logging.Logger; +import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.method.MethodDescription; @@ -47,13 +51,17 @@ public class ApacheHttpClientInstrumentation extends BaseApacheHttpClientInstrumentation { public static class ApacheHttpClient4Advice extends AbstractApacheHttpClientAdvice { + private static final Logger logger = LoggerFactory.getLogger(ApacheHttpClient4Advice.class); + private static final ApacheHttpClient4ApiAdapter adapter = ApacheHttpClient4ApiAdapter.get(); @Nullable @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object onBeforeExecute(@Advice.Argument(0) HttpRoute route, @Advice.Argument(1) HttpRequestWrapper request) throws URISyntaxException { - return startSpan(tracer, adapter, request, route.getTargetHost(), RequestHeaderAccessor.INSTANCE); + Span span = startSpan(tracer, adapter, request, route.getTargetHost(), RequestHeaderAccessor.INSTANCE); + RequestBodyCaptureRegistry.potentiallyCaptureRequestBody(request, tracer.getActive()); + return span; } @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpEntityGetContentInstrumentation.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpEntityGetContentInstrumentation.java new file mode 100644 index 0000000000..b08ea36da9 --- /dev/null +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpEntityGetContentInstrumentation.java @@ -0,0 +1,94 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.httpclient.v4; + +import co.elastic.apm.agent.httpclient.RequestBodyRecordingInputStream; +import co.elastic.apm.agent.httpclient.RequestBodyRecordingOutputStream; +import co.elastic.apm.agent.httpclient.v4.helper.RequestBodyCaptureRegistry; +import co.elastic.apm.agent.sdk.logging.Logger; +import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.Span; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.NamedElement; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.http.HttpEntity; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URISyntaxException; + +import static co.elastic.apm.agent.sdk.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; +import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; +import static net.bytebuddy.matcher.ElementMatchers.isBootstrapClassLoader; +import static net.bytebuddy.matcher.ElementMatchers.nameContains; +import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.not; +import static net.bytebuddy.matcher.ElementMatchers.returns; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +public class ApacheHttpEntityGetContentInstrumentation extends BaseApacheHttpClientInstrumentation { + + public static class ApacheHttpEntityGetContentAdvice { + + private static final Logger logger = LoggerFactory.getLogger(ApacheHttpEntityGetContentAdvice.class); + + @Advice.OnMethodExit(suppress = Throwable.class, inline = false) + @Advice.AssignReturned.ToReturned + public static InputStream onExit(@Advice.This HttpEntity thiz, @Advice.Return InputStream content) throws URISyntaxException { + Span clientSpan = RequestBodyCaptureRegistry.removeSpanFor(thiz); + if (clientSpan != null) { + logger.debug("Wrapping input stream for request body capture for HttpEntity {} ({}) for span {}", thiz.getClass().getName(), System.identityHashCode(thiz), clientSpan); + return new RequestBodyRecordingInputStream(content, clientSpan); + } + return content; + } + } + + @Override + public String getAdviceClassName() { + return "co.elastic.apm.agent.httpclient.v4.ApacheHttpEntityGetContentInstrumentation$ApacheHttpEntityGetContentAdvice"; + } + + @Override + public ElementMatcher.Junction getClassLoaderMatcher() { + return not(isBootstrapClassLoader()) + .and(classLoaderCanLoadClass("org.apache.http.HttpEntity")); + } + + @Override + public ElementMatcher getTypeMatcherPreFilter() { + return nameStartsWith("org.apache.http").and(nameContains("Entity")); + } + + @Override + public ElementMatcher getTypeMatcher() { + return hasSuperType(named("org.apache.http.HttpEntity")); + } + + @Override + public ElementMatcher getMethodMatcher() { + return named("getContent") + .and(takesArguments(0)); + } + +} diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpEntityWriteToInstrumentation.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpEntityWriteToInstrumentation.java new file mode 100644 index 0000000000..0b06c8b9fc --- /dev/null +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpEntityWriteToInstrumentation.java @@ -0,0 +1,99 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.httpclient.v4; + +import co.elastic.apm.agent.httpclient.RequestBodyRecordingOutputStream; +import co.elastic.apm.agent.httpclient.v4.helper.RequestBodyCaptureRegistry; +import co.elastic.apm.agent.sdk.logging.Logger; +import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.Span; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.NamedElement; +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.http.HttpEntity; + +import java.io.OutputStream; +import java.net.URISyntaxException; + +import static co.elastic.apm.agent.sdk.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; +import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; +import static net.bytebuddy.matcher.ElementMatchers.isBootstrapClassLoader; +import static net.bytebuddy.matcher.ElementMatchers.nameContains; +import static net.bytebuddy.matcher.ElementMatchers.nameStartsWith; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.not; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; + +public class ApacheHttpEntityWriteToInstrumentation extends BaseApacheHttpClientInstrumentation { + + public static class ApacheHttpEntityWriteToAdvice { + + private static final Logger logger = LoggerFactory.getLogger(ApacheHttpEntityWriteToAdvice.class); + + @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) + @Advice.AssignReturned.ToArguments(@Advice.AssignReturned.ToArguments.ToArgument(0)) + public static OutputStream onEnter(@Advice.This HttpEntity thiz, @Advice.Argument(0) OutputStream drain) throws URISyntaxException { + Span clientSpan = RequestBodyCaptureRegistry.removeSpanFor(thiz); + if (clientSpan != null) { + logger.debug("Wrapping output stream for request body capture for HttpEntity {} ({}) for span {}", thiz.getClass().getName(), System.identityHashCode(thiz), clientSpan); + return new RequestBodyRecordingOutputStream(drain, clientSpan); + } + return drain; + } + + @Advice.OnMethodExit(suppress = Throwable.class, inline = false) + public static void onExit(@Advice.Enter OutputStream potentiallyWrappedStream) throws URISyntaxException { + if (potentiallyWrappedStream instanceof RequestBodyRecordingOutputStream) { + ((RequestBodyRecordingOutputStream) potentiallyWrappedStream).releaseSpan(); + } + } + } + + @Override + public String getAdviceClassName() { + return "co.elastic.apm.agent.httpclient.v4.ApacheHttpEntityWriteToInstrumentation$ApacheHttpEntityWriteToAdvice"; + } + + @Override + public ElementMatcher.Junction getClassLoaderMatcher() { + return not(isBootstrapClassLoader()) + .and(classLoaderCanLoadClass("org.apache.http.HttpEntity")); + } + + @Override + public ElementMatcher getTypeMatcherPreFilter() { + return nameStartsWith("org.apache.http").and(nameContains("Entity")); + } + + @Override + public ElementMatcher getTypeMatcher() { + return hasSuperType(named("org.apache.http.HttpEntity")); + } + + @Override + public ElementMatcher getMethodMatcher() { + return named("writeTo") + .and(takesArguments(1)) + .and(takesArgument(0, OutputStream.class)); + } + +} diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientInstrumentation.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientInstrumentation.java index 5125477133..21fe4ad545 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientInstrumentation.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientInstrumentation.java @@ -19,10 +19,11 @@ package co.elastic.apm.agent.httpclient.v4; import co.elastic.apm.agent.httpclient.HttpClientHelper; +import co.elastic.apm.agent.httpclient.v4.helper.RequestBodyCaptureRegistry; import co.elastic.apm.agent.httpclient.v4.helper.RequestHeaderAccessor; -import co.elastic.apm.agent.tracer.ElasticContext; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.configuration.CoreConfiguration; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; @@ -80,7 +81,7 @@ public static class LegacyApacheHttpClientAdvice { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object onBeforeExecute(@Advice.Argument(0) @Nullable HttpHost host, @Advice.Argument(1) HttpRequest request) { - final ElasticContext activeContext = tracer.currentContext(); + final TraceState activeContext = tracer.currentContext(); Span span = null; if (activeContext.getSpan() != null) { String hostName = (host != null) ? host.getHostName() : null; @@ -105,6 +106,7 @@ public static Object onBeforeExecute(@Advice.Argument(0) @Nullable HttpHost host } } + RequestBodyCaptureRegistry.potentiallyCaptureRequestBody(request, tracer.getActive()); tracer.currentContext().propagateContext(request, RequestHeaderAccessor.INSTANCE, RequestHeaderAccessor.INSTANCE); return span; } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/ApacheHttpClient4AsyncHelper.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/ApacheHttpClient4AsyncHelper.java index ed4ef3c8cb..1f638cd3b4 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/ApacheHttpClient4AsyncHelper.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/ApacheHttpClient4AsyncHelper.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.httpclient.v4.helper; import co.elastic.apm.agent.httpclient.common.ApacheHttpClientAsyncHelper; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.Tracer; @@ -66,7 +66,7 @@ public FutureCallbackWrapper createInstance() { } public HttpAsyncRequestProducerWrapper wrapRequestProducer(HttpAsyncRequestProducer requestProducer, @Nullable Span span, - ElasticContext toPropagate) { + TraceState toPropagate) { return requestProducerWrapperObjectPool.createInstance().with(requestProducer, span, toPropagate); } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/HttpAsyncRequestProducerWrapper.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/HttpAsyncRequestProducerWrapper.java index 4d749ffce7..a8648894ba 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/HttpAsyncRequestProducerWrapper.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/HttpAsyncRequestProducerWrapper.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.httpclient.v4.helper; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.apache.http.HttpException; @@ -39,7 +39,7 @@ public class HttpAsyncRequestProducerWrapper implements HttpAsyncRequestProducer private volatile HttpAsyncRequestProducer delegate; @Nullable - private ElasticContext toPropagate; + private TraceState toPropagate; @Nullable private Span span; @@ -59,7 +59,7 @@ public class HttpAsyncRequestProducerWrapper implements HttpAsyncRequestProducer * @return the {@link HttpAsyncRequestProducer} wrapper */ public HttpAsyncRequestProducerWrapper with(HttpAsyncRequestProducer delegate, @Nullable Span span, - ElasticContext toPropagate) { + TraceState toPropagate) { // Order is important due to visibility - write to delegate last on this (initiating) thread this.span = span; toPropagate.incrementReferences(); @@ -85,6 +85,7 @@ public HttpRequest generateRequest() throws IOException, HttpException { // trace context propagation if (request != null) { if (span != null) { + RequestBodyCaptureRegistry.potentiallyCaptureRequestBody(request, span); RequestLine requestLine = request.getRequestLine(); if (requestLine != null) { String method = requestLine.getMethod(); diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/RequestBodyCaptureRegistry.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/RequestBodyCaptureRegistry.java new file mode 100644 index 0000000000..009cc1fe9b --- /dev/null +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/java/co/elastic/apm/agent/httpclient/v4/helper/RequestBodyCaptureRegistry.java @@ -0,0 +1,76 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.httpclient.v4.helper; + +import co.elastic.apm.agent.httpclient.HttpClientHelper; +import co.elastic.apm.agent.sdk.logging.Logger; +import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.sdk.state.GlobalState; +import co.elastic.apm.agent.tracer.AbstractSpan; +import co.elastic.apm.agent.tracer.GlobalTracer; +import co.elastic.apm.agent.tracer.Span; +import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; +import org.apache.http.HttpEntity; +import org.apache.http.HttpEntityEnclosingRequest; +import org.apache.http.HttpRequest; + +import javax.annotation.Nullable; + +public class RequestBodyCaptureRegistry { + + private static final Logger logger = LoggerFactory.getLogger(RequestBodyCaptureRegistry.class); + + @GlobalState + public static class MapHolder { + private static final ReferenceCountedMap> entityToClientSpan = GlobalTracer.get().newReferenceCountedMap(); + + + public static void captureBodyFor(Object entity, Span httpClientSpan) { + entityToClientSpan.put(entity, httpClientSpan); + } + + @Nullable + public static Span removeSpanFor(Object entity) { + return entityToClientSpan.remove(entity); + } + } + + + public static void potentiallyCaptureRequestBody(HttpRequest request, @Nullable AbstractSpan span) { + if (HttpClientHelper.startRequestBodyCapture(span, request, RequestHeaderAccessor.INSTANCE)) { + if (request instanceof HttpEntityEnclosingRequest) { + HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity(); + if (entity != null) { + logger.debug("Enabling request capture for entity {}() for span {}", entity.getClass().getName(), System.identityHashCode(entity), span); + MapHolder.captureBodyFor(entity, (Span) span); + } else { + logger.debug("HttpEntity is null for span {}", span); + } + } else { + logger.debug("Not capturing request body because {} is not an HttpEntityEnclosingRequest", request.getClass().getName()); + } + } + } + + @Nullable + public static Span removeSpanFor(HttpEntity entity) { + return MapHolder.removeSpanFor(entity); + } + +} diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation index 753c7c4605..8d04c1a373 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation @@ -2,3 +2,5 @@ co.elastic.apm.agent.httpclient.v4.ApacheHttpClientInstrumentation co.elastic.apm.agent.httpclient.v4.ApacheHttpAsyncClientInstrumentation co.elastic.apm.agent.httpclient.v4.ApacheHttpAsyncClientRedirectInstrumentation co.elastic.apm.agent.httpclient.v4.LegacyApacheHttpClientInstrumentation +co.elastic.apm.agent.httpclient.v4.ApacheHttpEntityWriteToInstrumentation +co.elastic.apm.agent.httpclient.v4.ApacheHttpEntityGetContentInstrumentation diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientInstrumentationTest.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientInstrumentationTest.java index 9a62a4bd9c..b2698ebc2e 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientInstrumentationTest.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpAsyncClientInstrumentationTest.java @@ -19,14 +19,16 @@ package co.elastic.apm.agent.httpclient.v4; import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.Outcome; import org.apache.http.HttpResponse; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.concurrent.FutureCallback; import org.apache.http.conn.UnsupportedSchemeException; +import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClients; import org.assertj.core.api.Assertions; @@ -34,6 +36,7 @@ import org.junit.BeforeClass; import org.junit.Test; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.concurrent.CompletableFuture; @@ -89,6 +92,39 @@ public void cancelled() { responseFuture.get(); } + @Override + protected boolean isBodyCapturingSupported() { + return true; + } + + @Override + protected void performPost(String path, byte[] data, String contentTypeHeader) throws Exception { + final CompletableFuture responseFuture = new CompletableFuture<>(); + + HttpClientContext httpClientContext = HttpClientContext.create(); + HttpPost request = new HttpPost(path); + request.setEntity(new InputStreamEntity(new ByteArrayInputStream(data))); + request.setHeader("Content-Type", contentTypeHeader); + client.execute(request, httpClientContext, new FutureCallback<>() { + @Override + public void completed(HttpResponse result) { + responseFuture.complete(result); + } + + @Override + public void failed(Exception ex) { + responseFuture.completeExceptionally(ex); + } + + @Override + public void cancelled() { + responseFuture.cancel(true); + } + }); + + responseFuture.get(); + } + @Test public void testSpanFinishOnEarlyException() throws Exception { @@ -119,11 +155,10 @@ public void testSpanWithIllegalProtocol() throws Exception { setUp(); reporter.resetChecks(); } - Span firstSpan = reporter.getFirstSpan(500); + SpanImpl firstSpan = reporter.getFirstSpan(500); assertThat(firstSpan).isNotNull(); assertThat(firstSpan.getOutcome()).isEqualTo(Outcome.FAILURE); Assertions.assertThat(reporter.getSpans()).hasSize(1); } - } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentationTest.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentationTest.java index 91189c295d..cfa20bd6a0 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentationTest.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/ApacheHttpClientInstrumentationTest.java @@ -21,11 +21,14 @@ import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.junit.AfterClass; import org.junit.BeforeClass; +import java.io.ByteArrayInputStream; import java.io.IOException; public class ApacheHttpClientInstrumentationTest extends AbstractHttpClientInstrumentationTest { @@ -49,4 +52,18 @@ protected void performGet(String path) throws Exception { response.close(); } + @Override + protected boolean isBodyCapturingSupported() { + return true; + } + + @Override + protected void performPost(String path, byte[] content, String contentTypeHeader) throws Exception { + HttpPost request = new HttpPost(path); + request.setEntity(new InputStreamEntity(new ByteArrayInputStream(content))); + request.setHeader("Content-Type", contentTypeHeader); + + client.execute(request); + } + } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientBasicHttpRequestInstrumentationTest.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientBasicHttpRequestInstrumentationTest.java index 72a3828ac3..62e8088ce7 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientBasicHttpRequestInstrumentationTest.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientBasicHttpRequestInstrumentationTest.java @@ -59,4 +59,6 @@ protected void performGet(String path) throws Exception { throw (Exception) e.getTargetException(); } } + + } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientHttpUriRequestInstrumentationTest.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientHttpUriRequestInstrumentationTest.java index 499f1d9032..16c56da974 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientHttpUriRequestInstrumentationTest.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient4-plugin/src/test/java/co/elastic/apm/agent/httpclient/v4/LegacyApacheHttpClientHttpUriRequestInstrumentationTest.java @@ -19,14 +19,18 @@ package co.elastic.apm.agent.httpclient.v4; import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; +import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.entity.InputStreamEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.BeforeClass; +import java.io.ByteArrayInputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -48,12 +52,30 @@ public static void close() { @Override protected void performGet(String path) throws Exception { + HttpGet request = new HttpGet(path); + performRequest(request); + } + + private static void performRequest(HttpRequest request) throws Exception { Method execute = client.getClass().getMethod("execute", HttpUriRequest.class); try { - HttpResponse response = (HttpResponse) execute.invoke(client, new HttpGet(path)); + HttpResponse response = (HttpResponse) execute.invoke(client, request); EntityUtils.consume(response.getEntity()); } catch (InvocationTargetException e) { throw (Exception) e.getTargetException(); } } + + @Override + protected boolean isBodyCapturingSupported() { + return true; + } + + @Override + protected void performPost(String path, byte[] content, String contentTypeHeader) throws Exception { + HttpPost request = new HttpPost(path); + request.setEntity(new InputStreamEntity(new ByteArrayInputStream(content))); + request.setHeader("Content-Type", contentTypeHeader); + performRequest(request); + } } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/pom.xml b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/pom.xml index 0634043aca..4d3590271f 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/pom.xml +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm apm-apache-httpclient - 1.50.0 + 1.51.0 apm-apache-httpclient5-plugin diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/ApacheHttpClient5AsyncHelper.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/ApacheHttpClient5AsyncHelper.java index 9c2a4462f5..3fe2166dfb 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/ApacheHttpClient5AsyncHelper.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/ApacheHttpClient5AsyncHelper.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.httpclient.common.ApacheHttpClientAsyncHelper; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.Tracer; @@ -73,7 +73,7 @@ public RequestChannelWrapper createInstance() { } public AsyncRequestProducerWrapper wrapRequestProducer(AsyncRequestProducer requestProducer, @Nullable Span span, - @Nullable ElasticContext toPropagate) { + @Nullable TraceState toPropagate) { return requestProducerWrapperObjectPool.createInstance().with(requestProducer, span, toPropagate); } @@ -87,7 +87,7 @@ public void failedBeforeRequestStarted(FutureCallbackWrapper cb, Throwable t) cb.failedWithoutExecution(t); } - public RequestChannelWrapper wrapRequestChannel(RequestChannel requestChannel, @Nullable Span span, @Nullable ElasticContext toPropagate) { + public RequestChannelWrapper wrapRequestChannel(RequestChannel requestChannel, @Nullable Span span, @Nullable TraceState toPropagate) { return requestChannelWrapperObjectPool.createInstance().with(requestChannel, span, toPropagate); } diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/AsyncRequestProducerWrapper.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/AsyncRequestProducerWrapper.java index 9000796fda..a475ecbd4f 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/AsyncRequestProducerWrapper.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/AsyncRequestProducerWrapper.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.httpclient.v5.helper; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; @@ -38,7 +38,7 @@ public class AsyncRequestProducerWrapper implements AsyncRequestProducer, Recycl private volatile AsyncRequestProducer delegate; @Nullable - private ElasticContext toPropagate; + private TraceState toPropagate; @Nullable private Span span; @@ -48,7 +48,7 @@ public class AsyncRequestProducerWrapper implements AsyncRequestProducer, Recycl } public AsyncRequestProducerWrapper with(AsyncRequestProducer delegate, @Nullable Span span, - ElasticContext toPropagate) { + TraceState toPropagate) { this.span = span; toPropagate.incrementReferences(); this.toPropagate = toPropagate; diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/RequestChannelWrapper.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/RequestChannelWrapper.java index 9b9844f37a..0edd80e85e 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/RequestChannelWrapper.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/main/java/co/elastic/apm/agent/httpclient/v5/helper/RequestChannelWrapper.java @@ -22,7 +22,7 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.pooling.Recyclable; import org.apache.hc.core5.http.EntityDetails; @@ -41,7 +41,7 @@ public class RequestChannelWrapper implements RequestChannel, Recyclable { private volatile RequestChannel delegate; @Nullable - private ElasticContext toPropagate; + private TraceState toPropagate; @Nullable private Span span; @@ -51,7 +51,7 @@ public RequestChannelWrapper() { public RequestChannelWrapper with(RequestChannel delegate, @Nullable Span span, - ElasticContext toPropagate) { + TraceState toPropagate) { this.span = span; toPropagate.incrementReferences(); this.toPropagate = toPropagate; diff --git a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/test/java/co/elastic/apm/agent/httpclient/v5/ApacheHttpAsyncClientInstrumentationTest.java b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/test/java/co/elastic/apm/agent/httpclient/v5/ApacheHttpAsyncClientInstrumentationTest.java index 4b0ccc72eb..ed117da025 100644 --- a/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/test/java/co/elastic/apm/agent/httpclient/v5/ApacheHttpAsyncClientInstrumentationTest.java +++ b/apm-agent-plugins/apm-apache-httpclient/apm-apache-httpclient5-plugin/src/test/java/co/elastic/apm/agent/httpclient/v5/ApacheHttpAsyncClientInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.httpclient.v5; import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.Outcome; import org.apache.hc.client5.http.async.methods.SimpleHttpRequest; import org.apache.hc.client5.http.async.methods.SimpleHttpResponse; @@ -112,7 +112,7 @@ public void testSpanFinishWithIllegalProtocol() throws Exception { String url = getBaseUrl().replaceAll("http", "ottp") + "/"; performGet(url); - Span firstSpan = reporter.getFirstSpan(500); + SpanImpl firstSpan = reporter.getFirstSpan(500); assertThat(firstSpan).isNotNull(); assertThat(firstSpan.getOutcome()).isEqualTo(Outcome.FAILURE); assertThat(firstSpan.getNameAsString()).isEqualTo("GET localhost"); @@ -133,7 +133,7 @@ public void testSpanFinishWithIllegalUrl() throws Exception { reporter.resetChecks(); } - Span firstSpan = reporter.getFirstSpan(500); + SpanImpl firstSpan = reporter.getFirstSpan(500); assertThat(firstSpan).isNotNull(); assertThat(firstSpan.getOutcome()).isEqualTo(Outcome.FAILURE); assertThat(firstSpan.getNameAsString()).isEqualTo("GET "); diff --git a/apm-agent-plugins/apm-apache-httpclient/pom.xml b/apm-agent-plugins/apm-apache-httpclient/pom.xml index c8dd64408b..a8374d09fc 100644 --- a/apm-agent-plugins/apm-apache-httpclient/pom.xml +++ b/apm-agent-plugins/apm-apache-httpclient/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-apache-httpclient diff --git a/apm-agent-plugins/apm-api-plugin/pom.xml b/apm-agent-plugins/apm-api-plugin/pom.xml index ac41395b1f..9f3cbf2225 100644 --- a/apm-agent-plugins/apm-api-plugin/pom.xml +++ b/apm-agent-plugins/apm-api-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 @@ -16,7 +16,6 @@ ${project.groupId}:${project.artifactId} - ${project.groupId} apm-agent-core diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/AbstractSpanInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/AbstractSpanInstrumentation.java index 7c71246e7c..a99e8e3e04 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/AbstractSpanInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/AbstractSpanInstrumentation.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.pluginapi; -import co.elastic.apm.agent.impl.context.ServiceTarget; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.ServiceTargetImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; @@ -71,8 +71,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setName(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(0) String name) { - if (context instanceof AbstractSpan) { - ((AbstractSpan) context).withName(name, PRIORITY_USER_SUPPLIED); + if (context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).withName(name, PRIORITY_USER_SUPPLIED); } } } @@ -87,10 +87,10 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setType(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(0) String type) { - if (context instanceof Transaction) { - ((Transaction) context).withType(type); - } else if (context instanceof Span) { - ((Span) context).setType(type, null, null); + if (context instanceof TransactionImpl) { + ((TransactionImpl) context).withType(type); + } else if (context instanceof SpanImpl) { + ((SpanImpl) context).setType(type, null, null); } } } @@ -107,8 +107,8 @@ public static void setType(@Advice.Argument(0) Object span, @Advice.Argument(1) @Nullable String type, @Advice.Argument(2) @Nullable String subtype, @Advice.Argument(3) @Nullable String action) { - if (span instanceof Span) { - ((Span) span).setType(type, subtype, action); + if (span instanceof SpanImpl) { + ((SpanImpl) span).setType(type, subtype, action); } } } @@ -125,8 +125,8 @@ public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static Object doCreateSpan(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Return @Nullable Object returnValue) { - if (context instanceof AbstractSpan) { - return ((AbstractSpan) context).createSpan(); + if (context instanceof AbstractSpanImpl) { + return ((AbstractSpanImpl) context).createSpan(); } else { return returnValue; } @@ -145,8 +145,8 @@ public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static Object doCreateExitSpan(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Return @Nullable Object returnValue) { - if (context instanceof AbstractSpan) { - return ((AbstractSpan) context).createExitSpan(); + if (context instanceof AbstractSpanImpl) { + return ((AbstractSpanImpl) context).createExitSpan(); } else { return returnValue; } @@ -162,7 +162,7 @@ public InitializeInstrumentation() { public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void incrementReferences(@Advice.Argument(0) Object span) { - ((AbstractSpan) span).incrementReferences(); + ((AbstractSpanImpl) span).incrementReferences(); } } } @@ -176,8 +176,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setStartTimestamp(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(value = 0) long epochMicros) { - if (context instanceof AbstractSpan) { - ((AbstractSpan) context).setStartTimestamp(epochMicros); + if (context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).setStartTimestamp(epochMicros); } } } @@ -198,14 +198,14 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setOutcome(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(value = 0) @Nullable Enum apiOutcome) { - if (context instanceof AbstractSpan) { + if (context instanceof AbstractSpanImpl) { Outcome outcome = Outcome.UNKNOWN; if (apiOutcome != null) { // valueOf conversion is fast as Enum implementation is using a lookup map internally // thus we don't need to do this ourselves outcome = Outcome.valueOf(apiOutcome.name()); } - ((AbstractSpan) context).withUserOutcome(outcome); + ((AbstractSpanImpl) context).withUserOutcome(outcome); } } } @@ -219,8 +219,8 @@ public EndInstrumentation() { public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void end(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context) { - if (context instanceof AbstractSpan) { - ((AbstractSpan) context).end(); + if (context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).end(); } } } @@ -235,8 +235,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void end(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(value = 0) long epochMicros) { - if (context instanceof AbstractSpan) { - ((AbstractSpan) context).end(epochMicros); + if (context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).end(epochMicros); } } } @@ -259,8 +259,8 @@ public static class AdviceClass { public static String captureException(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(0) Throwable t, @Advice.Return @Nullable String returnValue) { - if (context instanceof AbstractSpan) { - return ((AbstractSpan) context).captureExceptionAndGetErrorId(t); + if (context instanceof AbstractSpanImpl) { + return ((AbstractSpanImpl) context).captureExceptionAndGetErrorId(t); } else { return returnValue; } @@ -283,8 +283,8 @@ public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void captureException(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(0) Throwable t) { - if (context instanceof AbstractSpan) { - ((AbstractSpan) context).captureException(t); + if (context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).captureException(t); } } } @@ -301,8 +301,8 @@ public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static String getId(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Return @Nullable String returnValue) { - if (context instanceof AbstractSpan) { - return ((AbstractSpan) context).getTraceContext().getId().toString(); + if (context instanceof AbstractSpanImpl) { + return ((AbstractSpanImpl) context).getTraceContext().getId().toString(); } else { return returnValue; } @@ -321,8 +321,8 @@ public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static String getTraceId(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Return @Nullable String returnValue) { - if (context instanceof AbstractSpan) { - return ((AbstractSpan) context).getTraceContext().getTraceId().toString(); + if (context instanceof AbstractSpanImpl) { + return ((AbstractSpanImpl) context).getTraceContext().getTraceId().toString(); } else { return returnValue; } @@ -340,8 +340,8 @@ public static class AdviceClass { public static void addLabel(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(0) String key, @Advice.Argument(1) @Nullable String value) { - if (value != null && context instanceof AbstractSpan) { - ((AbstractSpan) context).addLabel(key, value); + if (value != null && context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).addLabel(key, value); } } } @@ -357,8 +357,8 @@ public static class AdviceClass { public static void addLabel(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(0) String key, @Advice.Argument(1) @Nullable Number value) { - if (value != null && context instanceof AbstractSpan) { - ((AbstractSpan) context).addLabel(key, value); + if (value != null && context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).addLabel(key, value); } } } @@ -374,8 +374,8 @@ public static class AdviceClass { public static void addLabel(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(0) String key, @Advice.Argument(1) @Nullable Boolean value) { - if (value != null && context instanceof AbstractSpan) { - ((AbstractSpan) context).addLabel(key, value); + if (value != null && context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).addLabel(key, value); } } } @@ -389,8 +389,8 @@ public ActivateInstrumentation() { public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void activate(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context) { - if (context instanceof AbstractSpan) { - ((AbstractSpan) context).activate(); + if (context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).activate(); } } } @@ -406,8 +406,8 @@ public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static boolean isSampled(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Return boolean returnValue) { - if (context instanceof AbstractSpan) { - return ((AbstractSpan) context).isSampled(); + if (context instanceof AbstractSpanImpl) { + return ((AbstractSpanImpl) context).isSampled(); } else { return returnValue; } @@ -426,8 +426,8 @@ public static class AdviceClass { public static void injectTraceHeaders(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(0) MethodHandle addHeaderMethodHandle, @Advice.Argument(1) @Nullable Object headerInjector) { - if (headerInjector != null && context instanceof AbstractSpan) { - ((AbstractSpan) context).propagateContext(headerInjector, HeaderInjectorBridge.get(addHeaderMethodHandle), null); + if (headerInjector != null && context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).propagateContext(headerInjector, HeaderInjectorBridge.get(addHeaderMethodHandle), null); } } } @@ -444,8 +444,8 @@ public static class AdviceClass { public static void setDestinationAddress(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(0) @Nullable String address, @Advice.Argument(1) int port) { - if (context instanceof Span) { - ((Span) context).getContext().getDestination() + if (context instanceof SpanImpl) { + ((SpanImpl) context).getContext().getDestination() .withUserAddress(address) .withUserPort(port); } @@ -463,8 +463,8 @@ public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void setDestinationService(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(0) @Nullable String resource) { - if (context instanceof Span) { - ServiceTarget serviceTarget = ((Span) context).getContext().getServiceTarget(); + if (context instanceof SpanImpl) { + ServiceTargetImpl serviceTarget = ((SpanImpl) context).getContext().getServiceTarget(); if (resource == null || resource.isEmpty()) { serviceTarget.withUserType(null).withUserName(null); } else { @@ -491,8 +491,8 @@ public static class AdviceClass { public static void setServiceTarget(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context, @Advice.Argument(0) @Nullable String type, @Advice.Argument(1) @Nullable String name) { - if (context instanceof Span) { - ((Span) context).getContext().getServiceTarget() + if (context instanceof SpanImpl) { + ((SpanImpl) context).getContext().getServiceTarget() .withUserType(type) .withUserName(name); } @@ -509,8 +509,8 @@ public SetNonDiscardableInstrumentation() { public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void setNonDiscardable(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context) { - if (context instanceof AbstractSpan) { - ((AbstractSpan) context).setNonDiscardable(); + if (context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).setNonDiscardable(); } } } diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ApiScopeInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ApiScopeInstrumentation.java index 1a3c167bf9..94ef2dca68 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ApiScopeInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ApiScopeInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.pluginapi; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -32,8 +32,8 @@ public class ApiScopeInstrumentation extends ApiInstrumentation { public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void close(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object context) { - if (context instanceof AbstractSpan) { - ((AbstractSpan) context).deactivate(); + if (context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).deactivate(); } } } diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureSpanInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureSpanInstrumentation.java index d4b464d280..507d09b996 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureSpanInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureSpanInstrumentation.java @@ -18,15 +18,16 @@ */ package co.elastic.apm.agent.pluginapi; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.sdk.bytebuddy.AnnotationValueOffsetMappingFactory; import co.elastic.apm.agent.sdk.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; @@ -59,11 +60,11 @@ public class CaptureSpanInstrumentation extends ElasticApmInstrumentation { protected static final Tracer tracer = GlobalTracer.get(); private final CoreConfiguration coreConfig; - private final StacktraceConfiguration stacktraceConfig; + private final StacktraceConfigurationImpl stacktraceConfig; public CaptureSpanInstrumentation(ElasticApmTracer tracer) { coreConfig = tracer.getConfig(CoreConfiguration.class); - stacktraceConfig = tracer.getConfig(StacktraceConfiguration.class); + stacktraceConfig = tracer.getConfig(StacktraceConfigurationImpl.class); } public static class AdviceClass { @@ -86,7 +87,7 @@ public static Object onMethodEnter( defaultValueProvider = AnnotationValueOffsetMappingFactory.TrueDefaultValueProvider.class ) boolean discardable ) { - ElasticContext activeContext = tracer.currentContext(); + TraceState activeContext = tracer.currentContext(); final AbstractSpan parentSpan = activeContext.getSpan(); if (parentSpan == null) { logger.debug("Not creating span for {} because there is no currently active span.", signature); @@ -107,7 +108,7 @@ public static Object onMethodEnter( .activate(); // using deprecated API to keep compatibility with existing behavior - ((co.elastic.apm.agent.impl.transaction.Span) span).setType(type, subtype, action); + ((SpanImpl) span).setType(type, subtype, action); if (!discardable) { span.setNonDiscardable(); diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java index 4c1edd87f0..5a2461c873 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/CaptureTransactionInstrumentation.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.sdk.bytebuddy.AnnotationValueOffsetMappingFactory.AnnotationValueExtractor; import co.elastic.apm.agent.sdk.bytebuddy.SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Outcome; @@ -62,11 +62,11 @@ public class CaptureTransactionInstrumentation extends ElasticApmInstrumentation public static final Logger logger = LoggerFactory.getLogger(CaptureTransactionInstrumentation.class); private final CoreConfiguration coreConfig; - private final StacktraceConfiguration stacktraceConfig; + private final StacktraceConfigurationImpl stacktraceConfig; public CaptureTransactionInstrumentation(ElasticApmTracer tracer) { coreConfig = tracer.getConfig(CoreConfiguration.class); - stacktraceConfig = tracer.getConfig(StacktraceConfiguration.class); + stacktraceConfig = tracer.getConfig(StacktraceConfigurationImpl.class); } public static class AdviceClass { diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ElasticApmApiInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ElasticApmApiInstrumentation.java index 7723217d1c..dc1e75184f 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ElasticApmApiInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/ElasticApmApiInstrumentation.java @@ -18,14 +18,12 @@ */ package co.elastic.apm.agent.pluginapi; -import co.elastic.apm.agent.tracer.service.ServiceAwareTracer; -import co.elastic.apm.agent.tracer.service.ServiceInfo; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.Tracer; import co.elastic.apm.agent.tracer.ErrorCapture; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Transaction; import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils; +import co.elastic.apm.agent.tracer.service.ServiceInfo; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -167,7 +165,7 @@ public SetServiceInfoForClassLoaderInstrumentation() { public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void setServiceInfoForClassLoader(@Advice.Argument(0) @Nullable ClassLoader classLoader, @Advice.Argument(1) String serviceName, @Advice.Argument(2) @Nullable String serviceVersion) { - tracer.require(ServiceAwareTracer.class).setServiceInfoForClassLoader(classLoader, ServiceInfo.of(serviceName, serviceVersion)); + tracer.setServiceInfoForClassLoader(classLoader, ServiceInfo.of(serviceName, serviceVersion)); } } } diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/LegacySpanInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/LegacySpanInstrumentation.java index 7b6a79059a..0225f9e9a0 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/LegacySpanInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/LegacySpanInstrumentation.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.pluginapi; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; @@ -86,8 +87,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(inline = false) public static void setType(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object span, @Advice.Argument(0) String type) { - if (span instanceof co.elastic.apm.agent.impl.transaction.Span) { - ((co.elastic.apm.agent.impl.transaction.Span) span).setType(type, null, null); + if (span instanceof SpanImpl) { + ((SpanImpl) span).setType(type, null, null); } } } @@ -201,8 +202,8 @@ public static class AdviceClass { public static void addTag(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object span, @Advice.Argument(0) String key, @Advice.Argument(1) String value) { - if (span instanceof co.elastic.apm.agent.impl.transaction.Span) { - ((co.elastic.apm.agent.impl.transaction.Span) span).addLabel(key, value); + if (span instanceof SpanImpl) { + ((SpanImpl) span).addLabel(key, value); } } } diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java index 61eb1d2d68..4d1a587c45 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TracedInstrumentation.java @@ -21,12 +21,12 @@ import co.elastic.apm.agent.sdk.bytebuddy.AnnotationValueOffsetMappingFactory; import co.elastic.apm.agent.sdk.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; @@ -65,11 +65,11 @@ public class TracedInstrumentation extends ElasticApmInstrumentation { public static final Logger logger = LoggerFactory.getLogger(TracedInstrumentation.class); private final CoreConfiguration coreConfig; - private final StacktraceConfiguration stacktraceConfig; + private final StacktraceConfigurationImpl stacktraceConfig; public TracedInstrumentation(ElasticApmTracer tracer) { coreConfig = tracer.getConfig(CoreConfiguration.class); - stacktraceConfig = tracer.getConfig(StacktraceConfiguration.class); + stacktraceConfig = tracer.getConfig(StacktraceConfigurationImpl.class); } public static class AdviceClass { @@ -93,7 +93,7 @@ public static Object onMethodEnter( defaultValueProvider = AnnotationValueOffsetMappingFactory.TrueDefaultValueProvider.class ) boolean discardable) { - final ElasticContext activeContext = tracer.currentContext(); + final TraceState activeContext = tracer.currentContext(); final AbstractSpan parentSpan = activeContext.getSpan(); if (parentSpan != null) { if (activeContext.shouldSkipChildSpanCreation()) { diff --git a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TransactionInstrumentation.java b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TransactionInstrumentation.java index e6ce5c97a8..6d6015fdc1 100644 --- a/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TransactionInstrumentation.java +++ b/apm-agent-plugins/apm-api-plugin/src/main/java/co/elastic/apm/agent/pluginapi/TransactionInstrumentation.java @@ -18,12 +18,10 @@ */ package co.elastic.apm.agent.pluginapi; -import co.elastic.apm.agent.tracer.service.ServiceAwareTracer; +import co.elastic.apm.agent.impl.transaction.IdImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.service.ServiceInfo; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Id; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -64,8 +62,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setFrameworkName(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Argument(0) String frameworkName) { - if (transaction instanceof Transaction) { - ((Transaction) transaction).setUserFrameworkName(frameworkName); + if (transaction instanceof TransactionImpl) { + ((TransactionImpl) transaction).setUserFrameworkName(frameworkName); } } } @@ -80,8 +78,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setUser(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Argument(0) String id, @Advice.Argument(1) String email, @Advice.Argument(2) String username, @Advice.Argument(value = 3, optional = true) String domain) { - if (transaction instanceof Transaction) { - ((Transaction) transaction).setUser(id, email, username, domain); + if (transaction instanceof TransactionImpl) { + ((TransactionImpl) transaction).setUser(id, email, username, domain); } } } @@ -98,9 +96,9 @@ public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static String ensureParentId(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Return @Nullable String returnValue) { - if (transaction instanceof Transaction) { - final TraceContext traceContext = ((Transaction) transaction).getTraceContext(); - Id parentId = traceContext.getParentId(); + if (transaction instanceof TransactionImpl) { + final TraceContextImpl traceContext = ((TransactionImpl) transaction).getTraceContext(); + IdImpl parentId = traceContext.getParentId(); if (parentId.isEmpty()) { parentId.setToRandomValue(); } @@ -120,8 +118,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setResult(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Argument(0) String result) { - if (transaction instanceof Transaction) { - ((Transaction) transaction).withResult(result); + if (transaction instanceof TransactionImpl) { + ((TransactionImpl) transaction).withResult(result); } } } @@ -137,8 +135,8 @@ public static class AdviceClass { public static void addCustomContext(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transactionObj, @Advice.Argument(0) String key, @Advice.Argument(1) @Nullable Object value) { - if (value != null && transactionObj instanceof Transaction) { - Transaction transaction = (Transaction) transactionObj; + if (value != null && transactionObj instanceof TransactionImpl) { + TransactionImpl transaction = (TransactionImpl) transactionObj; if (value instanceof String) { transaction.addCustomContext(key, (String) value); } else if (value instanceof Number) { @@ -160,8 +158,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setServiceInfo(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Argument(0) String serviceName, @Advice.Argument(1) String serviceVersion) { - if (transaction instanceof Transaction) { - ((Transaction) transaction).getTraceContext().setServiceInfo(serviceName, serviceVersion); + if (transaction instanceof TransactionImpl) { + ((TransactionImpl) transaction).getTraceContext().setServiceInfo(serviceName, serviceVersion); } } } @@ -176,10 +174,10 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void useServiceInfoForClassLoader(@Advice.FieldValue(value = "span", typing = Assigner.Typing.DYNAMIC) Object transaction, @Advice.Argument(0) ClassLoader classLoader) { - if (transaction instanceof Transaction) { - ServiceInfo serviceInfo = tracer.require(ServiceAwareTracer.class).getServiceInfoForClassLoader(classLoader); + if (transaction instanceof TransactionImpl) { + ServiceInfo serviceInfo = tracer.getServiceInfoForClassLoader(classLoader); if (serviceInfo != null) { - ((Transaction) transaction).getTraceContext().setServiceInfo(serviceInfo.getServiceName(), serviceInfo.getServiceVersion()); + ((TransactionImpl) transaction).getTraceContext().setServiceInfo(serviceInfo.getServiceName(), serviceInfo.getServiceVersion()); } } } diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/agent/pluginapi/ConfigInstrumentationTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/agent/pluginapi/ConfigInstrumentationTest.java index 8af213b978..a038796647 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/agent/pluginapi/ConfigInstrumentationTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/agent/pluginapi/ConfigInstrumentationTest.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.api.ElasticApm; @@ -42,7 +42,6 @@ import static net.bytebuddy.matcher.ElementMatchers.named; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatException; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; class ConfigInstrumentationTest { @@ -51,13 +50,13 @@ class ConfigInstrumentationTest { private ElasticApmTracer tracer; private ConfigurationRegistry configurationRegistry; - private CoreConfiguration coreConfig; + private CoreConfigurationImpl coreConfig; @BeforeEach void setup() { tracer = MockTracer.createRealTracer(); configurationRegistry = tracer.getConfigurationRegistry(); - coreConfig = configurationRegistry.getConfig(CoreConfiguration.class); + coreConfig = configurationRegistry.getConfig(CoreConfigurationImpl.class); } @AfterEach diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/agent/pluginapi/SpanInstrumentationTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/agent/pluginapi/SpanInstrumentationTest.java index c08ad9089f..0b24193169 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/agent/pluginapi/SpanInstrumentationTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/agent/pluginapi/SpanInstrumentationTest.java @@ -20,7 +20,9 @@ import co.elastic.apm.AbstractApiTest; import co.elastic.apm.agent.impl.TextHeaderMapAccessor; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.objectpool.impl.BookkeeperObjectPool; import co.elastic.apm.api.ElasticApm; import co.elastic.apm.api.Scope; @@ -71,7 +73,7 @@ void testLegacyAPIs() { Span span = transaction.createSpan(); span.setType("foo.bar.baz"); endSpan(span); - co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan(); + SpanImpl internalSpan = reporter.getFirstSpan(); assertThat(internalSpan.getType()).isEqualTo("foo"); assertThat(internalSpan.getSubtype()).isEqualTo("bar"); assertThat(internalSpan.getAction()).isEqualTo("baz"); @@ -83,7 +85,7 @@ void testTypes() { Span span = transaction.startSpan("foo", "bar", "baz"); endSpan(span); - co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan(); + SpanImpl internalSpan = reporter.getFirstSpan(); assertThat(internalSpan.getType()).isEqualTo("foo"); assertThat(internalSpan.getSubtype()).isEqualTo("bar"); assertThat(internalSpan.getAction()).isEqualTo("baz"); @@ -96,7 +98,7 @@ void testExitSpanFromTransaction() { Span span = transaction.startExitSpan("foo", "bar", "baz"); endSpan(span); - co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan(); + SpanImpl internalSpan = reporter.getFirstSpan(); // relying on auto-inference of context.destination.service.resource assertThat(internalSpan.getContext().getServiceTarget()).hasDestinationResource("bar"); } @@ -109,7 +111,7 @@ void testExitSpanFromNonExitSpan() { Span parent = transaction.startSpan("foo", "bar", "baz"); Span span = parent.startExitSpan("foo", "bar", "baz"); endSpan(span); - co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan(); + SpanImpl internalSpan = reporter.getFirstSpan(); // relying on auto-inference of context.destination.service.resource assertThat(internalSpan.getContext().getServiceTarget()).hasDestinationResource("bar"); } @@ -128,7 +130,7 @@ void testExitSpanFromExitSpan() { assertThat(reporter.getSpans()).isEmpty(); endSpan(parent); - co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan(); + SpanImpl internalSpan = reporter.getFirstSpan(); // relying on auto-inference of context.destination.service.resource assertThat(internalSpan.getContext().getServiceTarget()).hasDestinationResource("bar"); } @@ -206,12 +208,12 @@ void testReferenceCounting() { span.end(); transaction.end(); - BookkeeperObjectPool spanPool = objectPoolFactory.getSpanPool(); + BookkeeperObjectPool spanPool = objectPoolFactory.getSpanPool(); assertThat( spanPool.getRecyclablesToReturn().stream().filter(span1 -> span1.getReferenceCount() > 1).collect(Collectors.toList())) .hasSize(spanPool.getRequestedObjectCount()); - BookkeeperObjectPool transactionPool = objectPoolFactory.getTransactionPool(); + BookkeeperObjectPool transactionPool = objectPoolFactory.getTransactionPool(); assertThat( transactionPool.getRecyclablesToReturn().stream().filter(transaction1 -> transaction1.getReferenceCount() > 1).collect(Collectors.toList())) .hasSize(transactionPool.getRequestedObjectCount()); @@ -245,7 +247,7 @@ private void assertContainsTracingHeaders(Span span) { final Map tracingHeaders = new HashMap<>(); span.injectTraceHeaders(tracingHeaders::put); span.injectTraceHeaders(null); - assertThat(TraceContext.containsTraceContextTextHeaders(tracingHeaders, TextHeaderMapAccessor.INSTANCE)).isTrue(); + assertThat(TraceContextImpl.containsTraceContextTextHeaders(tracingHeaders, TextHeaderMapAccessor.INSTANCE)).isTrue(); } } } diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AbstractSpanImplAccessor.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AbstractSpanImplAccessor.java index ada066ad77..1d46e474da 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AbstractSpanImplAccessor.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AbstractSpanImplAccessor.java @@ -20,7 +20,7 @@ public class AbstractSpanImplAccessor { - public static co.elastic.apm.agent.impl.transaction.Transaction accessTransaction(Transaction t) { - return (co.elastic.apm.agent.impl.transaction.Transaction) ((TransactionImpl) t).span; + public static co.elastic.apm.agent.impl.transaction.TransactionImpl accessTransaction(Transaction t) { + return (co.elastic.apm.agent.impl.transaction.TransactionImpl) ((TransactionImpl) t).span; } } diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AnnotationApiTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AnnotationApiTest.java index 46b173f8b0..ef681737fb 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AnnotationApiTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AnnotationApiTest.java @@ -20,7 +20,7 @@ import co.elastic.apm.AbstractApiTest; import co.elastic.apm.agent.impl.TracerInternalApiUtils; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -87,7 +87,7 @@ private void testTransactionAndSpanTypes(boolean useLegacyTyping) { assertThat(reporter.getFirstTransaction().getFrameworkName()).isEqualTo("API"); assertThat(reporter.getSpans()).hasSize(1); - Span internalSpan = reporter.getFirstSpan(); + SpanImpl internalSpan = reporter.getFirstSpan(); assertThat(internalSpan.getNameAsString()).isEqualTo("spanWithType"); assertThat(internalSpan.getType()).isEqualTo("external"); assertThat(internalSpan.getSubtype()).isEqualTo("http"); @@ -100,7 +100,7 @@ void testMissingSubtype() { AnnotationTestClass.transactionForMissingSpanSubtype(); assertThat(reporter.getSpans()).hasSize(1); - Span internalSpan = reporter.getFirstSpan(); + SpanImpl internalSpan = reporter.getFirstSpan(); assertThat(internalSpan.getNameAsString()).isEqualTo("spanWithMissingSubtype"); assertThat(internalSpan.getType()).isEqualTo("external.http"); assertThat(internalSpan.getSubtype()).isNull(); diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AnnotationInheritanceTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AnnotationInheritanceTest.java index 3ad2468ab7..5cd32bbc48 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AnnotationInheritanceTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/AnnotationInheritanceTest.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import net.bytebuddy.agent.ByteBuddyAgent; @@ -57,7 +57,7 @@ void cleanup() { private void init(boolean annotationInheritanceEnabled) { MockTracer.MockInstrumentationSetup mockInstrumentationSetup = MockTracer.createMockInstrumentationSetup(SpyConfiguration.createSpyConfig(), false); tracer = mockInstrumentationSetup.getTracer(); - doReturn(annotationInheritanceEnabled).when(tracer.getConfig(CoreConfiguration.class)).isEnablePublicApiAnnotationInheritance(); + doReturn(annotationInheritanceEnabled).when(tracer.getConfig(CoreConfigurationImpl.class)).isEnablePublicApiAnnotationInheritance(); reporter = mockInstrumentationSetup.getReporter(); ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install()); } diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/BlockingQueueContextPropagationTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/BlockingQueueContextPropagationTest.java index 9dd14d928f..e23bcd262d 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/BlockingQueueContextPropagationTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/BlockingQueueContextPropagationTest.java @@ -19,6 +19,8 @@ package co.elastic.apm.api; import co.elastic.apm.AbstractApiTest; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -87,7 +89,7 @@ public void testAsyncTransactionDelegation() throws ExecutionException, Interrup // important for waiting on the queue reader thread to finish the span assertThat(result.get()).isEqualTo(transaction.getId()); - co.elastic.apm.agent.impl.transaction.Transaction reportedTransaction = reporter.getFirstTransaction(); + TransactionImpl reportedTransaction = reporter.getFirstTransaction(); assertThat(reportedTransaction).isNotNull(); assertThat(reportedTransaction.getTraceContext().getId().toString()).isEqualTo(transaction.getId()); assertThat(reportedTransaction.getTimestamp()).isEqualTo(startTime); @@ -120,7 +122,7 @@ public void testAsyncSpanDelegation() throws ExecutionException, InterruptedExce // important for waiting on the queue reader thread to finish the span assertThat(result.get()).isEqualTo(asyncSpanId); - co.elastic.apm.agent.impl.transaction.Transaction reportedTransaction = reporter.getFirstTransaction(); + TransactionImpl reportedTransaction = reporter.getFirstTransaction(); assertThat(reportedTransaction).isNotNull(); long transactionTimestamp = reportedTransaction.getTimestamp(); assertThat(transactionTimestamp).isEqualTo(startTime); @@ -129,7 +131,7 @@ public void testAsyncSpanDelegation() throws ExecutionException, InterruptedExce TimeUnit.MILLISECONDS.toMicros(70) ); - co.elastic.apm.agent.impl.transaction.Span reportedSpan = reporter.getFirstSpan(); + SpanImpl reportedSpan = reporter.getFirstSpan(); assertThat(reportedSpan.getTraceContext().getTraceId()).isEqualTo(reportedTransaction.getTraceContext().getTraceId()); assertThat(reportedSpan).isNotNull(); assertThat(reportedSpan.getType()).isEqualTo("async"); diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java index b5a728eca6..1aa1e4acb9 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/ElasticApmApiInstrumentationTest.java @@ -19,11 +19,13 @@ package co.elastic.apm.api; import co.elastic.apm.AbstractApiTest; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.service.ServiceInfo; import co.elastic.apm.agent.impl.TextHeaderMapAccessor; import co.elastic.apm.agent.impl.TracerInternalApiUtils; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -99,14 +101,14 @@ void testTransactionWithError() { @Test void testCreateChildSpanOfCurrentTransaction() { - final co.elastic.apm.agent.impl.transaction.Transaction transaction = startTestRootTransaction(); + final TransactionImpl transaction = startTestRootTransaction(); final Span span = ElasticApm.currentSpan().startSpan("db", "mysql", "query"); span.setName("span"); span.end(); transaction.deactivate().end(); assertThat(reporter.getTransactions()).hasSize(1); assertThat(reporter.getSpans()).hasSize(1); - co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan(); + SpanImpl internalSpan = reporter.getFirstSpan(); assertThat(internalSpan.getTraceContext().getParentId()).isEqualTo(reporter.getFirstTransaction().getTraceContext().getId()); assertThat(internalSpan.getType()).isEqualTo("db"); assertThat(internalSpan.getSubtype()).isEqualTo("mysql"); @@ -115,7 +117,7 @@ void testCreateChildSpanOfCurrentTransaction() { @Test void testLegacySpanCreationAndTyping() { - final co.elastic.apm.agent.impl.transaction.Transaction transaction = startTestRootTransaction(); + final TransactionImpl transaction = startTestRootTransaction(); final Span span = ElasticApm.currentSpan().createSpan(); span.setName("span"); span.setType("db.mysql.query.etc"); @@ -123,7 +125,7 @@ void testLegacySpanCreationAndTyping() { transaction.deactivate().end(); assertThat(reporter.getTransactions()).hasSize(1); assertThat(reporter.getSpans()).hasSize(1); - co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan(); + SpanImpl internalSpan = reporter.getFirstSpan(); assertThat(internalSpan.getTraceContext().getParentId()).isEqualTo(reporter.getFirstTransaction().getTraceContext().getId()); assertThat(internalSpan.getType()).isEqualTo("db"); assertThat(internalSpan.getSubtype()).isEqualTo("mysql"); @@ -134,7 +136,7 @@ void testLegacySpanCreationAndTyping() { @Test void testAutomaticAndManualTransactions() { - final co.elastic.apm.agent.impl.transaction.Transaction transaction = startTestRootTransaction(); + final TransactionImpl transaction = startTestRootTransaction(); final Transaction manualTransaction = ElasticApm.startTransaction(); manualTransaction.setName("manual transaction"); manualTransaction.setType("request"); @@ -146,13 +148,13 @@ void testAutomaticAndManualTransactions() { @Test void testGetId_distributedTracingEnabled() { - co.elastic.apm.agent.impl.transaction.Transaction transaction = tracer.startRootTransaction(null).withType(Transaction.TYPE_REQUEST); + TransactionImpl transaction = tracer.startRootTransaction(null).withType(Transaction.TYPE_REQUEST); try (co.elastic.apm.agent.tracer.Scope scope = transaction.activateInScope()) { assertThat(ElasticApm.currentTransaction().getId()).isEqualTo(transaction.getTraceContext().getId().toString()); assertThat(ElasticApm.currentTransaction().getTraceId()).isEqualTo(transaction.getTraceContext().getTraceId().toString()); assertThat(ElasticApm.currentSpan().getId()).isEqualTo(transaction.getTraceContext().getId().toString()); assertThat(ElasticApm.currentSpan().getTraceId()).isEqualTo(transaction.getTraceContext().getTraceId().toString()); - co.elastic.apm.agent.impl.transaction.Span span = transaction.createSpan().withType("db").withSubtype("mysql").withName("SELECT"); + SpanImpl span = transaction.createSpan().withType("db").withSubtype("mysql").withName("SELECT"); try (co.elastic.apm.agent.tracer.Scope spanScope = span.activateInScope()) { assertThat(ElasticApm.currentSpan().getId()).isEqualTo(span.getTraceContext().getId().toString()); assertThat(ElasticApm.currentSpan().getTraceId()).isEqualTo(span.getTraceContext().getTraceId().toString()); @@ -262,7 +264,7 @@ void testEnsureParentId() { @Test void testTransactionWithRemoteParentFunction() { - AbstractSpan parent = tracer.startRootTransaction(null); + AbstractSpanImpl parent = tracer.startRootTransaction(null); assertThat(parent).isNotNull(); Map headerMap = new HashMap<>(); parent.propagateContext(headerMap, TextHeaderMapAccessor.INSTANCE, null); @@ -273,7 +275,7 @@ void testTransactionWithRemoteParentFunction() { @Test void testTransactionWithRemoteParentFunctions() { - AbstractSpan parent = tracer.startRootTransaction(null); + AbstractSpanImpl parent = tracer.startRootTransaction(null); assertThat(parent).isNotNull(); Map headerMap = new HashMap<>(); parent.propagateContext(headerMap, TextHeaderMapAccessor.INSTANCE, null); @@ -284,7 +286,7 @@ void testTransactionWithRemoteParentFunctions() { @Test void testTransactionWithRemoteParentHeaders() { - AbstractSpan parent = tracer.startRootTransaction(null); + AbstractSpanImpl parent = tracer.startRootTransaction(null); assertThat(parent).isNotNull(); Map headerMap = new HashMap<>(); parent.propagateContext(headerMap, TextHeaderMapAccessor.INSTANCE, null); @@ -359,7 +361,7 @@ void testOverrideServiceVersionForClassLoaderWithRemoteParent() { } private void checkTransactionServiceInfo(ServiceInfo expected){ - TraceContext traceContext = reporter.getFirstTransaction().getTraceContext(); + TraceContextImpl traceContext = reporter.getFirstTransaction().getTraceContext(); assertThat(traceContext.getServiceName()).isEqualTo(expected.getServiceName()); assertThat(traceContext.getServiceVersion()).isEqualTo(expected.getServiceVersion()); } diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanDestinationApiTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanDestinationApiTest.java index 633bb2b297..f13b4b9ea7 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanDestinationApiTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanDestinationApiTest.java @@ -19,7 +19,8 @@ package co.elastic.apm.api; import co.elastic.apm.AbstractApiTest; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,8 +35,8 @@ class SpanDestinationApiTest extends AbstractApiTest { public static final int INTERNAL_PORT = 9001; public static final String INTERNAL_RESOURCE = "internal-resource"; - private co.elastic.apm.agent.impl.transaction.Transaction internalTransaction; - private co.elastic.apm.agent.impl.transaction.Span internalSpan; + private TransactionImpl internalTransaction; + private SpanImpl internalSpan; @BeforeEach void setUp() { @@ -201,7 +202,7 @@ void testSetServiceTargetTypeNameAndServiceResource() { .hasDestinationResource("my-resource"); } - private Span getSpan() { + private SpanImpl getSpan() { internalSpan.deactivate().end(); return reporter.getFirstSpan(); } diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanDiscardingTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanDiscardingTest.java index 9eaa784d39..f3bf0bb2a3 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanDiscardingTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanDiscardingTest.java @@ -19,7 +19,8 @@ package co.elastic.apm.api; import co.elastic.apm.AbstractApiTest; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.configuration.TimeDuration; import org.junit.jupiter.api.Test; @@ -62,12 +63,12 @@ void testNonDiscarding_tracedAnnotation() { } private void doTest(Scenario scenario) { - doReturn(TimeDuration.of("100ms")).when(config.getConfig(CoreConfiguration.class)).getSpanMinDuration(); + doReturn(TimeDuration.of("100ms")).when(config.getConfig(CoreConfigurationImpl.class)).getSpanMinDuration(); Transaction transaction = ElasticApm.startTransaction(); try (Scope activate = transaction.activate()) { parentSpan(scenario); } - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); switch (scenario) { case DISCARD: case DISCARD_TRACED_ANNOTATION: diff --git a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanExitTest.java b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanExitTest.java index d99cef3e24..39ed9596a4 100644 --- a/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanExitTest.java +++ b/apm-agent-plugins/apm-api-plugin/src/test/java/co/elastic/apm/api/SpanExitTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.api; import co.elastic.apm.AbstractApiTest; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,7 +41,7 @@ void before() { @Test void captureSpan() { - Span span = scenario(this::doCaptureSpan); + SpanImpl span = scenario(this::doCaptureSpan); assertThat(span) .hasName("SpanExitTest#doCaptureSpan") .hasType("app") @@ -55,7 +55,7 @@ void doCaptureSpan() { @Test void captureSpanExit1() { - Span span = scenario(this::doCaptureSpanExit1); + SpanImpl span = scenario(this::doCaptureSpanExit1); assertThat(span) .hasName("SpanExitTest#doCaptureSpanExit1") .hasType("app") @@ -69,7 +69,7 @@ void doCaptureSpanExit1() { @Test void captureSpanExit2() { - Span span = scenario(this::doCaptureSpanExit2); + SpanImpl span = scenario(this::doCaptureSpanExit2); assertThat(span) .hasName("SpanExitTest#doCaptureSpanExit2") .hasType("app") @@ -84,7 +84,7 @@ void doCaptureSpanExit2() { @Test void captureSpanExit3() { - Span span = scenario(this::doCaptureSpanExit3); + SpanImpl span = scenario(this::doCaptureSpanExit3); assertThat(span) .hasName("SpanExitTest#doCaptureSpanExit3") .hasType("app") @@ -102,7 +102,7 @@ void doCaptureSpanExit3() { @Test void traced() { - Span span = scenario(this::doTraced); + SpanImpl span = scenario(this::doTraced); assertThat(span) .hasName("SpanExitTest#doTraced") .hasType("app") @@ -115,7 +115,7 @@ void doTraced() { @Test void tracedExit1() { - Span span = scenario(this::doTracedExit1); + SpanImpl span = scenario(this::doTracedExit1); assertThat(span) .hasName("SpanExitTest#doTracedExit1") .hasType("app") @@ -129,7 +129,7 @@ void doTracedExit1() { @Test void tracedExit2() { - Span span = scenario(this::doTracedExit2); + SpanImpl span = scenario(this::doTracedExit2); assertThat(span) .hasName("SpanExitTest#doTracedExit2") .hasType("other") @@ -144,7 +144,7 @@ void doTracedExit2() { @Test void tracedExit3() { - Span span = scenario(this::doTracedExit3); + SpanImpl span = scenario(this::doTracedExit3); assertThat(span) .hasName("SpanExitTest#doTracedExit3") .hasType("app") @@ -160,13 +160,13 @@ void doTracedExit3() { // common - private Span scenario(Runnable task) { + private SpanImpl scenario(Runnable task) { Transaction transaction = ElasticApm.startTransaction(); try (Scope activate = transaction.activate()) { task.run(); } transaction.end(); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans) .describedAs("only a single span is expected to be created") .hasSize(1); diff --git a/apm-agent-plugins/apm-asynchttpclient-plugin/pom.xml b/apm-agent-plugins/apm-asynchttpclient-plugin/pom.xml index 13c6f9cc4f..66e6229ccc 100644 --- a/apm-agent-plugins/apm-asynchttpclient-plugin/pom.xml +++ b/apm-agent-plugins/apm-asynchttpclient-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-asynchttpclient-plugin diff --git a/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/AbstractAsyncHttpClientInstrumentation.java b/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/AbstractAsyncHttpClientInstrumentation.java index e8fe41e590..e2cbfa840a 100644 --- a/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/AbstractAsyncHttpClientInstrumentation.java +++ b/apm-agent-plugins/apm-asynchttpclient-plugin/src/main/java/co/elastic/apm/agent/asynchttpclient/AbstractAsyncHttpClientInstrumentation.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; @@ -103,7 +103,7 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object onBeforeExecute(@Advice.Argument(value = 0) Request request, @Advice.Argument(value = 1) AsyncHandler asyncHandler) { - final ElasticContext activeContext = tracer.currentContext(); + final TraceState activeContext = tracer.currentContext(); final AbstractSpan parentSpan = tracer.getActive(); Span span = null; if (parentSpan != null) { diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/pom.xml b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/pom.xml index 95a46cb4ca..7f915e089f 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/pom.xml +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/pom.xml @@ -3,7 +3,7 @@ apm-aws-sdk co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 @@ -12,7 +12,7 @@ ${project.basedir}/../../.. - 1.12.215 + 1.12.755 1.1.0 diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java index d5b07530a2..05eeb59428 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/main/java/co/elastic/apm/agent/awssdk/v1/helper/SQSHelper.java @@ -22,7 +22,7 @@ import co.elastic.apm.agent.awssdk.v1.helper.sqs.wrapper.ReceiveMessageResultWrapper; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.Tracer; @@ -58,7 +58,7 @@ protected SQSHelper(Tracer tracer) { } - public void propagateContext(ElasticContext toPropagate, AmazonWebServiceRequest request) { + public void propagateContext(TraceState toPropagate, AmazonWebServiceRequest request) { if (request instanceof SendMessageRequest) { SendMessageRequest sendMessageRequest = (SendMessageRequest) request; toPropagate.propagateContext(sendMessageRequest.getMessageAttributes(), this, null); diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/AbstractAws1ClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/AbstractAws1ClientIT.java index d7b30d82d2..b5e7db306d 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/AbstractAws1ClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/AbstractAws1ClientIT.java @@ -22,7 +22,7 @@ public abstract class AbstractAws1ClientIT extends AbstractAwsClientIT { - public static final String LOCALSTACK_VERSION = "0.14.2"; + public static final String LOCALSTACK_VERSION = "3.5.0"; public AbstractAws1ClientIT() { super(LOCALSTACK_VERSION); diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/DynamoDbClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/DynamoDbClientIT.java index 1ebe829184..8185ef2e3e 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/DynamoDbClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/DynamoDbClientIT.java @@ -18,9 +18,8 @@ */ package co.elastic.apm.agent.awssdk.v1; -import co.elastic.apm.agent.awssdk.common.AbstractAwsClientIT; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.client.builder.AwsClientBuilder; @@ -55,7 +54,7 @@ public class DynamoDbClientIT extends AbstractAws1ClientIT { private AmazonDynamoDB dynamoDB; private AmazonDynamoDBAsync dynamoDBAsync; - private final Consumer dbAssert = span -> assertThat(span.getContext().getDb().getInstance()).isEqualTo(localstack.getRegion()); + private final Consumer dbAssert = span -> assertThat(span.getContext().getDb().getInstance()).isEqualTo(localstack.getRegion()); @BeforeEach @@ -72,7 +71,7 @@ public void setupClient() { @Test public void testDynamoDbClient() { - Transaction transaction = startTestRootTransaction("s3-test"); + TransactionImpl transaction = startTestRootTransaction("s3-test"); newTest(() -> dynamoDB.createTable(new CreateTableRequest().withTableName(TABLE_NAME) .withAttributeDefinitions(List.of( @@ -142,7 +141,7 @@ public void testDynamoDbClient() { @Test public void testDynamoDbClientAsync() { - Transaction transaction = startTestRootTransaction("s3-test"); + TransactionImpl transaction = startTestRootTransaction("s3-test"); newTest(() -> dynamoDBAsync.createTableAsync(new CreateTableRequest().withTableName(TABLE_NAME) .withAttributeDefinitions(List.of( diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/S3ClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/S3ClientIT.java index 05a6f1e282..d811f05fb0 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/S3ClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/S3ClientIT.java @@ -18,8 +18,7 @@ */ package co.elastic.apm.agent.awssdk.v1; -import co.elastic.apm.agent.awssdk.common.AbstractAwsClientIT; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.client.builder.AwsClientBuilder; @@ -50,7 +49,7 @@ public void setupClient() { @Test public void testS3Client() { - Transaction transaction = startTestRootTransaction("s3-test"); + TransactionImpl transaction = startTestRootTransaction("s3-test"); newTest(() -> s3.createBucket(BUCKET_NAME)) .operationName("CreateBucket") diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSClientIT.java index 7efb851088..af625db21f 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSClientIT.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.awssdk.v1; import co.elastic.apm.agent.awssdk.common.AbstractSQSClientIT; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; @@ -52,9 +52,9 @@ public class SQSClientIT extends AbstractSQSClientIT { private AmazonSQS sqs; private AmazonSQSAsync sqsAsync; - private final Consumer messagingAssert = span -> assertThat(span.getContext().getMessage().getQueueName()).isEqualTo(SQS_QUEUE_NAME); + private final Consumer messagingAssert = span -> assertThat(span.getContext().getMessage().getQueueName()).isEqualTo(SQS_QUEUE_NAME); - CoreConfiguration coreConfiguration; + CoreConfigurationImpl coreConfiguration; MessagingConfiguration messagingConfiguration; public SQSClientIT() { @@ -63,7 +63,7 @@ public SQSClientIT() { @BeforeEach public void setupClient() { - coreConfiguration = tracer.getConfig(CoreConfiguration.class); + coreConfiguration = tracer.getConfig(CoreConfigurationImpl.class); messagingConfiguration = tracer.getConfig(MessagingConfiguration.class); sqs = AmazonSQSClient.builder() @@ -79,7 +79,7 @@ public void setupClient() { @Test public void testSQSClient() { - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); newTest(() -> sqs.createQueue(SQS_QUEUE_NAME)) .operationName("CreateQueue") @@ -158,7 +158,7 @@ public void testSQSClient() { @Test public void testAsyncSQSClient() { - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); newTest(() -> sqsAsync.createQueueAsync(SQS_QUEUE_NAME)) .operationName("CreateQueue") diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSJmsClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSJmsClientIT.java index f8a2ebe393..ed5f1aa57b 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSJmsClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-1-plugin/src/test/java/co/elastic/apm/agent/awssdk/v1/SQSJmsClientIT.java @@ -18,15 +18,13 @@ */ package co.elastic.apm.agent.awssdk.v1; -import co.elastic.apm.agent.awssdk.common.AbstractAwsClientIT; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import co.elastic.apm.agent.tracer.Scope; import com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper; import com.amazon.sqs.javamessaging.ProviderConfiguration; @@ -61,12 +59,12 @@ public class SQSJmsClientIT extends AbstractAws1ClientIT { SQSConnection connection; SQSConnection receivingConnection; AmazonSQS sqs; - CoreConfiguration coreConfiguration; + CoreConfigurationImpl coreConfiguration; MessagingConfiguration messagingConfiguration; @BeforeEach public void setupClient() throws JMSException { - coreConfiguration = tracer.getConfig(CoreConfiguration.class); + coreConfiguration = tracer.getConfig(CoreConfigurationImpl.class); messagingConfiguration = tracer.getConfig(MessagingConfiguration.class); sqs = AmazonSQSClient.builder() @@ -92,7 +90,7 @@ public void tearDown() throws JMSException { public void testSend() throws JMSException { client.createQueue(SQS_QUEUE_NAME); - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(SQS_QUEUE_NAME); @@ -114,7 +112,7 @@ public void testReceiveWithinTransaction() throws JMSException { client.createQueue(SQS_QUEUE_NAME); // SEND message - Transaction sendTransaction = startTestRootTransaction("sqs-test-send"); + TransactionImpl sendTransaction = startTestRootTransaction("sqs-test-send"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(SQS_QUEUE_NAME); @@ -133,7 +131,7 @@ public void testReceiveWithinTransaction() throws JMSException { receivingConnection.start(); - Transaction receiveTransaction = startTestRootTransaction("sqs-test-receive"); + TransactionImpl receiveTransaction = startTestRootTransaction("sqs-test-receive"); Message receivedMessage = consumer.receive(2000); assertThat(receivedMessage.getStringProperty("traceparent")).isNotNull(); @@ -147,7 +145,7 @@ public void testReceiveWithinTransaction() throws JMSException { assertThat(reporter.getNumReportedTransactions()).isEqualTo(2); assertThat(reporter.getNumReportedSpans()).isEqualTo(4); - Span jmsReceiveSpan = reporter.getSpanByName("JMS RECEIVE from queue " + SQS_QUEUE_NAME); + SpanImpl jmsReceiveSpan = reporter.getSpanByName("JMS RECEIVE from queue " + SQS_QUEUE_NAME); assertThat(reporter.getSpanByName("SQS DELETE from " + SQS_QUEUE_NAME).isChildOf(jmsReceiveSpan)).isTrue(); assertThat(jmsReceiveSpan.isChildOf(receiveTransaction)).isTrue(); assertThat(reporter.getSpans()).allSatisfy(span -> assertThat(span).isSync()); @@ -159,7 +157,7 @@ public void testReceiveOutsideTransaction() throws JMSException { client.createQueue(SQS_QUEUE_NAME); // SEND message - Transaction sendTransaction = startTestRootTransaction("sqs-test-send"); + TransactionImpl sendTransaction = startTestRootTransaction("sqs-test-send"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(SQS_QUEUE_NAME); @@ -206,7 +204,7 @@ public void testOnMessage() throws JMSException { receivingConnection.start(); // SEND message - Transaction sendTransaction = startTestRootTransaction("sqs-test-send"); + TransactionImpl sendTransaction = startTestRootTransaction("sqs-test-send"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(SQS_QUEUE_NAME); @@ -222,9 +220,9 @@ public void testOnMessage() throws JMSException { receivingSession.close(); assertThat(reporter.getNumReportedTransactions()).isEqualTo(2); - Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().startsWith("JMS RECEIVE")).findAny(); + Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().startsWith("JMS RECEIVE")).findAny(); assertThat(optTransaction.isPresent()).isTrue(); - Transaction receivingTransaction = optTransaction.get(); + TransactionImpl receivingTransaction = optTransaction.get(); assertThat(reporter.getNumReportedSpans()).isEqualTo(3); assertThat(reporter.getSpanByName("on-message-child").isChildOf(receivingTransaction)).isTrue(); @@ -245,7 +243,7 @@ public void testOnMessageWithNonJmssender() throws JMSException { receivingConnection.start(); // SEND message - Transaction sendTransaction = startTestRootTransaction("sqs-test-send"); + TransactionImpl sendTransaction = startTestRootTransaction("sqs-test-send"); sqs.sendMessage(queueUrl, MESSAGE_BODY); @@ -256,9 +254,9 @@ public void testOnMessageWithNonJmssender() throws JMSException { receivingSession.close(); assertThat(reporter.getNumReportedTransactions()).isEqualTo(2); - Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().startsWith("JMS RECEIVE")).findAny(); + Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().startsWith("JMS RECEIVE")).findAny(); assertThat(optTransaction.isPresent()).isTrue(); - Transaction receivingTransaction = optTransaction.get(); + TransactionImpl receivingTransaction = optTransaction.get(); assertThat(reporter.getNumReportedSpans()).isEqualTo(2); assertThat(reporter.getSpanByName("on-message-child").isChildOf(receivingTransaction)).isTrue(); @@ -297,11 +295,11 @@ static class SQSListener implements MessageListener { @Override public void onMessage(Message message) { try { - Tracer tracer = GlobalTracer.get().require(ElasticApmTracer.class); + ElasticApmTracer tracer = GlobalTracer.get().require(ElasticApmTracer.class); assertThat(tracer).isNotNull(); - AbstractSpan parent = tracer.getActive(); + AbstractSpanImpl parent = tracer.getActive(); assertThat(parent).isNotNull(); - Span child = parent.createSpan(); + SpanImpl child = parent.createSpan(); assertThat(child).isNotNull(); child.withName("on-message-child"); try (Scope ignored = child.activateInScope()) { diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/pom.xml b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/pom.xml index f215b58542..c1ff02d58e 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/pom.xml +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/pom.xml @@ -3,7 +3,7 @@ apm-aws-sdk co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 @@ -13,7 +13,7 @@ ${project.basedir}/../../.. - 2.25.43 + 2.26.12 2.0.0 8 diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/SQSHelper.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/SQSHelper.java index 52652e47d7..58373b0045 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/SQSHelper.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/main/java/co/elastic/apm/agent/awssdk/v2/helper/SQSHelper.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.awssdk.v2.helper; import co.elastic.apm.agent.awssdk.common.AbstractSQSInstrumentationHelper; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.Tracer; @@ -57,7 +57,7 @@ public SQSHelper(Tracer tracer) { super(tracer, SdkV2DataSource.getInstance()); } - private SdkRequest propagateContext(ElasticContext toPropagate, SdkRequest sdkRequest) { + private SdkRequest propagateContext(TraceState toPropagate, SdkRequest sdkRequest) { if (sdkRequest instanceof SendMessageRequest) { SendMessageRequest sendMessageRequest = (SendMessageRequest) sdkRequest; Map attributesMap = new HashMap<>(sendMessageRequest.messageAttributes()); @@ -119,7 +119,7 @@ protected boolean isReceiveMessageRequest(SdkRequest request) { return request instanceof ReceiveMessageRequest; } - public void modifyRequestObject(ElasticContext toPropagate, ClientExecutionParams clientExecutionParams, ExecutionContext executionContext) { + public void modifyRequestObject(TraceState toPropagate, ClientExecutionParams clientExecutionParams, ExecutionContext executionContext) { SdkRequest sdkRequest = clientExecutionParams.getInput(); SdkRequest newRequestObj = null; if (!toPropagate.isEmpty() && clientExecutionParams.getOperationName().startsWith("SendMessage")) { diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/BaseSyncClientHandlerInstrumentationTest.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/BaseSyncClientHandlerInstrumentationTest.java index e6d0bf528e..cdbdc9052d 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/BaseSyncClientHandlerInstrumentationTest.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/BaseSyncClientHandlerInstrumentationTest.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.common.JvmRuntimeInfo; import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute; @@ -82,7 +82,7 @@ public Outcome exerciseRedactedException(Exception canBeNull) { MockTracer.MockInstrumentationSetup mockInstrumentationSetup = MockTracer.createMockInstrumentationSetup(); ElasticApmTracer tracer = mockInstrumentationSetup.getTracer(); - Transaction transaction = tracer.startRootTransaction(null); + TransactionImpl transaction = tracer.startRootTransaction(null); assertThat(transaction).isNotNull(); transaction .withName("exception-test") @@ -91,7 +91,7 @@ public Outcome exerciseRedactedException(Exception canBeNull) { .withOutcome(Outcome.SUCCESS) .activate(); - Span span = tracer.createExitChildSpan(); + SpanImpl span = tracer.createExitChildSpan(); span.withType("storage") .withSubtype("s3") .withAction("operationName"); diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/DynamoDbClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/DynamoDbClientIT.java index 6e9c6b7f29..d753bd91d4 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/DynamoDbClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/DynamoDbClientIT.java @@ -18,9 +18,8 @@ */ package co.elastic.apm.agent.awssdk.v2; -import co.elastic.apm.agent.awssdk.common.AbstractAwsClientIT; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.testcontainers.containers.localstack.LocalStackContainer; @@ -59,7 +58,7 @@ public class DynamoDbClientIT extends AbstractAws2ClientIT { private DynamoDbClient dynamoDB; private DynamoDbAsyncClient dynamoDBAsync; - private final Consumer dbAssert = span -> assertThat(span.getContext().getDb().getInstance()).isEqualTo(localstack.getRegion()); + private final Consumer dbAssert = span -> assertThat(span.getContext().getDb().getInstance()).isEqualTo(localstack.getRegion()); private static final Map ITEM = Stream.of( new AbstractMap.SimpleEntry<>("attributeOne", AttributeValue.builder().s("valueOne").build()), @@ -85,7 +84,7 @@ public void setupClient() { @Test public void testDynamoDbClient() { - Transaction transaction = startTestRootTransaction("s3-test"); + TransactionImpl transaction = startTestRootTransaction("s3-test"); newTest(() -> dynamoDB.createTable(CreateTableRequest.builder() .tableName(TABLE_NAME) @@ -159,7 +158,7 @@ public void testDynamoDbClient() { @Test public void testDynamoDbClientAsync() { - Transaction transaction = startTestRootTransaction("s3-test"); + TransactionImpl transaction = startTestRootTransaction("s3-test"); newTest(() -> dynamoDBAsync.createTable(CreateTableRequest.builder() .tableName(TABLE_NAME) @@ -209,7 +208,7 @@ public void testDynamoDbClientAsync() { .async() .execute(); - Span span = reporter.getSpanByName("DynamoDB Query " + TABLE_NAME); + SpanImpl span = reporter.getSpanByName("DynamoDB Query " + TABLE_NAME); assertThat(span.getContext().getDb()).hasStatement(KEY_CONDITION_EXPRESSION); newTest(() -> dynamoDBAsync.deleteTable(DeleteTableRequest.builder().tableName(TABLE_NAME).build())) diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/S3ClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/S3ClientIT.java index 5b369a396d..57ac737639 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/S3ClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/S3ClientIT.java @@ -18,8 +18,7 @@ */ package co.elastic.apm.agent.awssdk.v2; -import co.elastic.apm.agent.awssdk.common.AbstractAwsClientIT; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.testcontainers.containers.localstack.LocalStackContainer; @@ -65,7 +64,7 @@ public void setupClient() { @Test public void testS3Client() { - Transaction transaction = startTestRootTransaction("s3-test"); + TransactionImpl transaction = startTestRootTransaction("s3-test"); newTest(() -> s3.createBucket(CreateBucketRequest.builder().bucket(BUCKET_NAME).build())) .operationName("CreateBucket") .entityName(BUCKET_NAME) @@ -133,7 +132,7 @@ public void testS3Client() { @Test public void testAsyncS3Client() { - Transaction transaction = startTestRootTransaction("s3-test"); + TransactionImpl transaction = startTestRootTransaction("s3-test"); newTest(() -> s3Async.createBucket(CreateBucketRequest.builder().bucket(BUCKET_NAME).build())) .operationName("CreateBucket") diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSClientIT.java index da977bb9aa..10f955995c 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSClientIT.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.awssdk.v2; import co.elastic.apm.agent.awssdk.common.AbstractSQSClientIT; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -55,9 +55,9 @@ public class SQSClientIT extends AbstractSQSClientIT { private SqsClient sqs; private SqsAsyncClient sqsAsync; - private final Consumer messagingAssert = span -> assertThat(span.getContext().getMessage().getQueueName()).isEqualTo(SQS_QUEUE_NAME); + private final Consumer messagingAssert = span -> assertThat(span.getContext().getMessage().getQueueName()).isEqualTo(SQS_QUEUE_NAME); - CoreConfiguration coreConfiguration; + CoreConfigurationImpl coreConfiguration; MessagingConfiguration messagingConfiguration; public SQSClientIT() { @@ -66,7 +66,7 @@ public SQSClientIT() { @BeforeEach public void setupClient() { - coreConfiguration = tracer.getConfig(CoreConfiguration.class); + coreConfiguration = tracer.getConfig(CoreConfigurationImpl.class); messagingConfiguration = tracer.getConfig(MessagingConfiguration.class); sqs = SqsClient.builder().endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.SQS)) @@ -84,7 +84,7 @@ public void setupClient() { @Test public void testSQSClient() { - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); newTest(() -> sqs.createQueue(CreateQueueRequest.builder().queueName(SQS_QUEUE_NAME).build())) .operationName("CreateQueue") @@ -163,7 +163,7 @@ public void testSQSClient() { @Test public void testAsyncSQSClient() { - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); newTest(() -> sqsAsync.createQueue(CreateQueueRequest.builder().queueName(SQS_QUEUE_NAME).build())) .operationName("CreateQueue") @@ -253,7 +253,7 @@ public void testNonReceiveMessageWithinMessagingTransaction() { final StringBuilder queueUrl = new StringBuilder(); queueUrl.append(sqs.getQueueUrl(GetQueueUrlRequest.builder().queueName(SQS_QUEUE_NAME).build()).queueUrl()); - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); transaction.withType("messaging"); sqs.sendMessage(SendMessageRequest.builder() @@ -276,7 +276,7 @@ public void testAsnycNonReceiveMessageWithinMessagingTransaction() { final StringBuilder queueUrl = new StringBuilder(); queueUrl.append(sqsAsync.getQueueUrl(GetQueueUrlRequest.builder().queueName(SQS_QUEUE_NAME).build()).join().queueUrl()); - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); transaction.withType("messaging"); sqsAsync.sendMessage(SendMessageRequest.builder() @@ -300,7 +300,7 @@ public void testReceiveMessageWithinMessagingTransaction() { final StringBuilder queueUrl = new StringBuilder(); queueUrl.append(sqs.getQueueUrl(GetQueueUrlRequest.builder().queueName(SQS_QUEUE_NAME).build()).queueUrl()); - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); transaction.withType("messaging"); sqs.receiveMessage(ReceiveMessageRequest.builder().queueUrl(queueUrl.toString()).build()); diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSJmsClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSJmsClientIT.java index 3286c10644..475e6f5dd1 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSJmsClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-2-plugin/src/test/java/co/elastic/apm/agent/awssdk/v2/SQSJmsClientIT.java @@ -18,15 +18,13 @@ */ package co.elastic.apm.agent.awssdk.v2; -import co.elastic.apm.agent.awssdk.common.AbstractAwsClientIT; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import co.elastic.apm.agent.tracer.Scope; import com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper; import com.amazon.sqs.javamessaging.ProviderConfiguration; @@ -62,12 +60,12 @@ public class SQSJmsClientIT extends AbstractAws2ClientIT { SQSConnection connection; SQSConnection receivingConnection; SqsClient sqs; - CoreConfiguration coreConfiguration; + CoreConfigurationImpl coreConfiguration; MessagingConfiguration messagingConfiguration; @BeforeEach public void setupClient() throws JMSException { - coreConfiguration = tracer.getConfig(CoreConfiguration.class); + coreConfiguration = tracer.getConfig(CoreConfigurationImpl.class); messagingConfiguration = tracer.getConfig(MessagingConfiguration.class); sqs = SqsClient.builder().endpointOverride(localstack.getEndpointOverride(LocalStackContainer.Service.SQS)) @@ -94,7 +92,7 @@ public void tearDown() throws JMSException { public void testSend() throws JMSException { client.createQueue(SQS_QUEUE_NAME); - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(SQS_QUEUE_NAME); @@ -116,7 +114,7 @@ public void testReceiveWithinTransaction() throws JMSException { client.createQueue(SQS_QUEUE_NAME); // SEND message - Transaction sendTransaction = startTestRootTransaction("sqs-test-send"); + TransactionImpl sendTransaction = startTestRootTransaction("sqs-test-send"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(SQS_QUEUE_NAME); @@ -135,7 +133,7 @@ public void testReceiveWithinTransaction() throws JMSException { receivingConnection.start(); - Transaction receiveTransaction = startTestRootTransaction("sqs-test-receive"); + TransactionImpl receiveTransaction = startTestRootTransaction("sqs-test-receive"); Message receivedMessage = consumer.receive(2000); assertThat(receivedMessage.getStringProperty("traceparent")).isNotNull(); @@ -149,7 +147,7 @@ public void testReceiveWithinTransaction() throws JMSException { assertThat(reporter.getNumReportedTransactions()).isEqualTo(2); assertThat(reporter.getNumReportedSpans()).isEqualTo(4); - Span jmsReceiveSpan = reporter.getSpanByName("JMS RECEIVE from queue " + SQS_QUEUE_NAME); + SpanImpl jmsReceiveSpan = reporter.getSpanByName("JMS RECEIVE from queue " + SQS_QUEUE_NAME); assertThat(reporter.getSpanByName("SQS DELETE from " + SQS_QUEUE_NAME).isChildOf(jmsReceiveSpan)).isTrue(); assertThat(jmsReceiveSpan.isChildOf(receiveTransaction)).isTrue(); assertThat(reporter.getSpans()).allSatisfy(span -> assertThat(span).isSync()); @@ -161,7 +159,7 @@ public void testReceiveOutsideTransaction() throws JMSException { client.createQueue(SQS_QUEUE_NAME); // SEND message - Transaction sendTransaction = startTestRootTransaction("sqs-test-send"); + TransactionImpl sendTransaction = startTestRootTransaction("sqs-test-send"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(SQS_QUEUE_NAME); @@ -207,7 +205,7 @@ public void testOnMessage() throws JMSException { receivingConnection.start(); // SEND message - Transaction sendTransaction = startTestRootTransaction("sqs-test-send"); + TransactionImpl sendTransaction = startTestRootTransaction("sqs-test-send"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(SQS_QUEUE_NAME); @@ -223,9 +221,9 @@ public void testOnMessage() throws JMSException { receivingSession.close(); assertThat(reporter.getNumReportedTransactions()).isEqualTo(2); - Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().startsWith("JMS RECEIVE")).findAny(); + Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().startsWith("JMS RECEIVE")).findAny(); assertThat(optTransaction.isPresent()).isTrue(); - Transaction receivingTransaction = optTransaction.get(); + TransactionImpl receivingTransaction = optTransaction.get(); assertThat(reporter.getNumReportedSpans()).isEqualTo(3); assertThat(reporter.getSpanByName("on-message-child").isChildOf(receivingTransaction)).isTrue(); @@ -246,7 +244,7 @@ public void testOnMessageWithNonJmssender() throws JMSException { receivingConnection.start(); // SEND message - Transaction sendTransaction = startTestRootTransaction("sqs-test-send"); + TransactionImpl sendTransaction = startTestRootTransaction("sqs-test-send"); sqs.sendMessage(software.amazon.awssdk.services.sqs.model.SendMessageRequest.builder() .queueUrl(queueUrl) @@ -261,9 +259,9 @@ public void testOnMessageWithNonJmssender() throws JMSException { receivingSession.close(); assertThat(reporter.getNumReportedTransactions()).isEqualTo(2); - Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().startsWith("JMS RECEIVE")).findAny(); + Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().startsWith("JMS RECEIVE")).findAny(); assertThat(optTransaction.isPresent()).isTrue(); - Transaction receivingTransaction = optTransaction.get(); + TransactionImpl receivingTransaction = optTransaction.get(); assertThat(reporter.getNumReportedSpans()).isEqualTo(2); assertThat(reporter.getSpanByName("on-message-child").isChildOf(receivingTransaction)).isTrue(); @@ -302,11 +300,11 @@ static class SQSListener implements MessageListener { @Override public void onMessage(Message message) { try { - Tracer tracer = GlobalTracer.get().require(ElasticApmTracer.class); + ElasticApmTracer tracer = GlobalTracer.get().require(ElasticApmTracer.class); assertThat(tracer).isNotNull(); - AbstractSpan parent = tracer.getActive(); + AbstractSpanImpl parent = tracer.getActive(); assertThat(parent).isNotNull(); - Span child = parent.createSpan(); + SpanImpl child = parent.createSpan(); assertThat(child).isNotNull(); child.withName("on-message-child"); try (Scope ignored = child.activateInScope()) { diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/pom.xml b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/pom.xml index 26c8782e98..3dc2c1668b 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/pom.xml +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/pom.xml @@ -3,7 +3,7 @@ apm-aws-sdk co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/test/java/co/elastic/apm/agent/awssdk/common/AbstractAwsClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/test/java/co/elastic/apm/agent/awssdk/common/AbstractAwsClientIT.java index 622d56be20..41fe65546e 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/test/java/co/elastic/apm/agent/awssdk/common/AbstractAwsClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/test/java/co/elastic/apm/agent/awssdk/common/AbstractAwsClientIT.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.awssdk.common; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.context.ServiceTarget; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.context.ServiceTargetImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.Outcome; import org.testcontainers.containers.localstack.LocalStackContainer; import org.testcontainers.junit.jupiter.Container; @@ -55,7 +55,7 @@ public abstract class AbstractAwsClientIT extends AbstractInstrumentationTest { public AbstractAwsClientIT(String localstackVersion) { DockerImageName localstackImage = DockerImageName.parse("localstack/localstack:" + localstackVersion); - localstack = new LocalStackContainer(localstackImage).withServices(localstackService()); + localstack = new LocalStackContainer(localstackImage).withServices(localstackService()).withEnv("SQS_ENDPOINT_STRATEGY", "dynamic"); } protected abstract String awsService(); @@ -86,7 +86,7 @@ public class TestBuilder { private final Map otelAttributes; @Nullable - private Consumer spanAssertions; + private Consumer spanAssertions; private boolean asyncSpans; private TestBuilder(Supplier test) { @@ -119,7 +119,7 @@ public TestBuilder async() { return this; } - public TestBuilder withSpanAssertions(Consumer assertions) { + public TestBuilder withSpanAssertions(Consumer assertions) { this.spanAssertions = assertions; return this; } @@ -127,7 +127,7 @@ public TestBuilder withSpanAssertions(Consumer assertions) { public void execute() { doExecute(); - Span span = getSpan(); + SpanImpl span = getSpan(); commonSpanAssertions(span); assertThat(span).hasOutcome(Outcome.SUCCESS); @@ -137,7 +137,7 @@ public void executeWithException(Class exceptionType) { assertThatExceptionOfType(exceptionType) .isThrownBy(this::doExecute); - Span span = getSpan(); + SpanImpl span = getSpan(); commonSpanAssertions(span); assertThat(span).hasOutcome(Outcome.FAILURE); @@ -157,10 +157,10 @@ private void doExecute() { } } - private Span getSpan() { + private SpanImpl getSpan() { String spanName = awsService() + " " + operationName + (entityName != null ? " " + entityName : ""); - Span span = reporter.getSpanByName(spanName); + SpanImpl span = reporter.getSpanByName(spanName); assertThat(span) .describedAs("span with name '%s' is expected", spanName) .isNotNull(); @@ -168,7 +168,7 @@ private Span getSpan() { return span; } - private void commonSpanAssertions(Span span) { + private void commonSpanAssertions(SpanImpl span) { assertThat(span) .isExit() @@ -179,7 +179,7 @@ private void commonSpanAssertions(Span span) { assertThat(span).hasAction(action); } - ServiceTarget serviceTarget = span.getContext().getServiceTarget(); + ServiceTargetImpl serviceTarget = span.getContext().getServiceTarget(); String targetName = expectedTargetName(entityName); diff --git a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/test/java/co/elastic/apm/agent/awssdk/common/AbstractSQSClientIT.java b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/test/java/co/elastic/apm/agent/awssdk/common/AbstractSQSClientIT.java index dd8368ed51..1796e36ab5 100644 --- a/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/test/java/co/elastic/apm/agent/awssdk/common/AbstractSQSClientIT.java +++ b/apm-agent-plugins/apm-aws-sdk/apm-aws-sdk-common/src/test/java/co/elastic/apm/agent/awssdk/common/AbstractSQSClientIT.java @@ -18,11 +18,11 @@ */ package co.elastic.apm.agent.awssdk.common; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; @@ -35,7 +35,7 @@ import static org.mockito.Mockito.doReturn; public abstract class AbstractSQSClientIT extends AbstractAwsClientIT { - protected CoreConfiguration coreConfiguration; + protected CoreConfigurationImpl coreConfiguration; protected MessagingConfiguration messagingConfiguration; public AbstractSQSClientIT(String localstackVersion) { @@ -44,18 +44,18 @@ public AbstractSQSClientIT(String localstackVersion) { @BeforeEach public void setupConfig() { - coreConfiguration = tracer.getConfig(CoreConfiguration.class); + coreConfiguration = tracer.getConfig(CoreConfigurationImpl.class); messagingConfiguration = tracer.getConfig(MessagingConfiguration.class); } @ParameterizedTest @ValueSource(strings = {"sync", "async"}) public void testReceiveOneMessageWithinTransaction(String clientType) { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); String queueUrl = setupQueue(); - Transaction parentTransaction = startTestRootTransaction("parent-transaction"); + TransactionImpl parentTransaction = startTestRootTransaction("parent-transaction"); sendMessage(queueUrl); parentTransaction.deactivate().end(); @@ -66,7 +66,7 @@ public void testReceiveOneMessageWithinTransaction(String clientType) { e.printStackTrace(); } - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); if (clientType.equals("async")) { receiveMessagesAsync(queueUrl); @@ -79,11 +79,11 @@ public void testReceiveOneMessageWithinTransaction(String clientType) { assertThat(reporter.getNumReportedTransactions()).isEqualTo(2); assertThat(reporter.getNumReportedSpans()).isEqualTo(3); - Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().equals("sqs-test")).findFirst(); + Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().equals("sqs-test")).findFirst(); assertThat(optTransaction.isPresent()).isTrue(); - Transaction sqsTransaction = optTransaction.get(); + TransactionImpl sqsTransaction = optTransaction.get(); - Span receivingSpan = reporter.getSpanByName("SQS POLL from " + SQS_QUEUE_NAME); + SpanImpl receivingSpan = reporter.getSpanByName("SQS POLL from " + SQS_QUEUE_NAME); assertThat(receivingSpan.getContext().getMessage().getQueueName()).isEqualTo(SQS_QUEUE_NAME); assertThat(receivingSpan.getContext().getMessage().getAge()).isGreaterThan(0); assertThat(receivingSpan.getContext().getMessage().getBodyForRead()).isNotNull(); @@ -98,11 +98,11 @@ public void testReceiveOneMessageWithinTransaction(String clientType) { @ParameterizedTest @ValueSource(strings = {"sync", "async"}) public void testReceiveOneMessageOutsideATransaction(String clientType) { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); String queueUrl = setupQueue(); - Transaction parentTransaction = startTestRootTransaction("parent-transaction"); + TransactionImpl parentTransaction = startTestRootTransaction("parent-transaction"); sendMessage(queueUrl); parentTransaction.deactivate().end(); @@ -122,15 +122,15 @@ public void testReceiveOneMessageOutsideATransaction(String clientType) { assertThat(reporter.getNumReportedTransactions()).isEqualTo(2); assertThat(reporter.getNumReportedSpans()).isEqualTo(2); - Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().startsWith("SQS RECEIVE from")).findFirst(); + Optional optTransaction = reporter.getTransactions().stream().filter(t -> t.getNameAsString().startsWith("SQS RECEIVE from")).findFirst(); assertThat(optTransaction.isPresent()).isTrue(); - Transaction sqsTransaction = optTransaction.get(); + TransactionImpl sqsTransaction = optTransaction.get(); assertThat(sqsTransaction.getSpanLinks()).isEmpty(); - Span childSpan = reporter.getSpanByName("custom-child-span"); + SpanImpl childSpan = reporter.getSpanByName("custom-child-span"); assertThat(childSpan.isChildOf(sqsTransaction)).isTrue(); - Span sendingSpan = reporter.getSpanByName("SQS SEND to " + SQS_QUEUE_NAME); + SpanImpl sendingSpan = reporter.getSpanByName("SQS SEND to " + SQS_QUEUE_NAME); assertThat(sqsTransaction.getContext().getMessage().getQueueName()).isEqualTo(SQS_QUEUE_NAME); assertThat(sqsTransaction.getContext().getMessage().getAge()).isGreaterThan(0); @@ -142,11 +142,11 @@ public void testReceiveOneMessageOutsideATransaction(String clientType) { @ParameterizedTest @ValueSource(strings = {"sync", "async"}) public void testReceiveMultipleMessagesOutsideATransaction(String clientType) { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); String queueUrl = setupQueue(); - Transaction parentTransaction = startTestRootTransaction("parent-transaction"); + TransactionImpl parentTransaction = startTestRootTransaction("parent-transaction"); sendMessage(queueUrl); sendMessage(queueUrl); sendMessage(queueUrl); @@ -184,11 +184,11 @@ public void testReceiveMultipleMessagesOutsideATransaction(String clientType) { @ParameterizedTest @ValueSource(strings = {"sync", "async"}) public void testReceiveMultipleMessagesWithinATransaction(String clientType) { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); String queueUrl = setupQueue(); - Transaction parentTransaction = startTestRootTransaction("parent-transaction"); + TransactionImpl parentTransaction = startTestRootTransaction("parent-transaction"); sendMessage(queueUrl); sendMessage(queueUrl); sendMessage(queueUrl); @@ -201,7 +201,7 @@ public void testReceiveMultipleMessagesWithinATransaction(String clientType) { e.printStackTrace(); } - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); if (clientType.equals("async")) { receiveMessagesAsync(queueUrl, 3); @@ -213,7 +213,7 @@ public void testReceiveMultipleMessagesWithinATransaction(String clientType) { assertThat(reporter.getNumReportedTransactions()).isEqualTo(2); assertThat(reporter.getNumReportedSpans()).isEqualTo(7); - Span receivingSpan = reporter.getSpanByName("SQS POLL from some-test-sqs-queue"); + SpanImpl receivingSpan = reporter.getSpanByName("SQS POLL from some-test-sqs-queue"); assertThat(receivingSpan.getSpanLinks()).isNotNull(); assertThat(receivingSpan.getSpanLinks()).hasSize(3); long numCustomSpans = reporter.getSpans().stream().filter(t -> t.getNameAsString().startsWith("custom")).count(); @@ -232,7 +232,7 @@ public void testQueueExclusion(String clientType) { String queueUrl = setupQueue(); String ignoredQueueUrl = setupIgnoreQueue(); - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); if (clientType.equals("async")) { executeAsyncQueueExclusion(queueUrl, ignoredQueueUrl); @@ -253,7 +253,7 @@ public void testEmptyReceiveWithinTransaction(String clientType) { String queueUrl = setupQueue(); - Transaction transaction = startTestRootTransaction("sqs-test"); + TransactionImpl transaction = startTestRootTransaction("sqs-test"); if (clientType.equals("async")) { receiveMessagesAsync(queueUrl); @@ -283,9 +283,9 @@ public void testEmptyReceiveOutsideTransaction(String clientType) { } protected void executeChildSpan() { - AbstractSpan active = tracer.getActive(); + AbstractSpanImpl active = tracer.getActive(); assertThat(active).isNotNull(); - Span childSpan = active.createSpan(); + SpanImpl childSpan = active.createSpan(); assertThat(childSpan).isNotNull(); childSpan.withName("custom-child-span"); childSpan.activate(); diff --git a/apm-agent-plugins/apm-aws-sdk/pom.xml b/apm-agent-plugins/apm-aws-sdk/pom.xml index bfe3c3b3f6..61dd193c09 100644 --- a/apm-agent-plugins/apm-aws-sdk/pom.xml +++ b/apm-agent-plugins/apm-aws-sdk/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-awslambda-plugin/pom.xml b/apm-agent-plugins/apm-awslambda-plugin/pom.xml index 4611f84312..8b4eca780b 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/pom.xml +++ b/apm-agent-plugins/apm-awslambda-plugin/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractLambdaTest.java b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractLambdaTest.java index 9722136ae1..58cff35723 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractLambdaTest.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractLambdaTest.java @@ -23,14 +23,13 @@ import co.elastic.apm.agent.awslambda.lambdas.AbstractFunction; import co.elastic.apm.agent.awslambda.lambdas.TestContext; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.ServerlessConfiguration; +import co.elastic.apm.agent.configuration.ServerlessConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.metadata.MetaDataMock; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Faas; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import co.elastic.apm.agent.impl.transaction.TraceState; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.report.ApmServerClient; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import co.elastic.apm.agent.tracer.Outcome; @@ -85,8 +84,8 @@ public abstract class AbstractLambdaTest extends AbstractInstrumenta HEADER_2_KEY, HEADER_2_VALUE, CONTENT_TYPE_HEADER, TEXT_CONTENT_TYPE, "Host", API_GATEWAY_HOST, - TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, TRACEPARENT_EXAMPLE, - TraceContext.TRACESTATE_HEADER_NAME, TRACESTATE_EXAMPLE + TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, TRACEPARENT_EXAMPLE, + TraceContextImpl.TRACESTATE_HEADER_NAME, TRACESTATE_EXAMPLE ); protected static final String PATH = "/some/url/path"; @@ -117,7 +116,7 @@ public abstract class AbstractLambdaTest extends AbstractInstrumenta protected static final String S3_BUCKET_ARN = "arn:aws:s3:::" + S3_BUCKET_NAME; @Nullable - static ServerlessConfiguration serverlessConfiguration; + static ServerlessConfigurationImpl serverlessConfiguration; @Nullable protected TestContext context; @@ -131,7 +130,7 @@ public abstract class AbstractLambdaTest extends AbstractInstrumenta public AbstractLambdaTest() { jsonSerializer = new DslJsonSerializer( - mock(StacktraceConfiguration.class), + mock(StacktraceConfigurationImpl.class), mock(ApmServerClient.class), MetaDataMock.create() ).newWriter(); @@ -153,7 +152,7 @@ protected boolean supportsContextPropagation() { static synchronized void initAllButInstrumentation() { config = SpyConfiguration.createSpyConfig(); - serverlessConfiguration = config.getConfig(ServerlessConfiguration.class); + serverlessConfiguration = config.getConfig(ServerlessConfigurationImpl.class); doReturn(true).when(serverlessConfiguration).runsOnAwsLambda(); MockTracer.MockInstrumentationSetup mockInstrumentationSetup = MockTracer.createMockInstrumentationSetup(config); tracer = mockInstrumentationSetup.getTracer(); @@ -184,7 +183,7 @@ protected void verifyFailure() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getOutcome()).isEqualTo(Outcome.FAILURE); assertThat(transaction.getResult()).isEqualTo("failure"); assertThat(reporter.getPartialTransactions()).containsExactly(transaction); @@ -197,18 +196,18 @@ public void testTraceContext() { return; } getFunction().handleRequest(input, context); - Transaction transaction = reporter.getFirstTransaction(); - TraceContext traceContext = transaction.getTraceContext(); + TransactionImpl transaction = reporter.getFirstTransaction(); + TraceContextImpl traceContext = transaction.getTraceContext(); verifyDistributedTracing(traceContext); } - protected void verifyDistributedTracing(TraceContext traceContext) { + protected void verifyDistributedTracing(TraceContextImpl traceContext) { assertThat(traceContext.getTraceId().toString()).isEqualTo(TRACE_ID_EXAMPLE); assertThat(traceContext.getParentId().toString()).isEqualTo(PARENT_ID_EXAMPLE); assertThat(traceContext.getTraceState().getSampleRate()).isEqualTo(0.77d); } - protected void printTransactionJson(Transaction transaction) { + protected void printTransactionJson(TransactionImpl transaction) { String transactionJson = jsonSerializer.toJsonString(transaction); try { System.out.println(objectMapper.readTree(transactionJson).toPrettyString()); diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractPlainLambdaTest.java b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractPlainLambdaTest.java index 8eae63d31a..0e02f02375 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractPlainLambdaTest.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractPlainLambdaTest.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.awslambda.lambdas.TestContext; import co.elastic.apm.agent.impl.metadata.MetaData; -import co.elastic.apm.agent.impl.transaction.Faas; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.FaasImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.sdk.internal.util.VersionUtils; import com.amazonaws.services.lambda.runtime.RequestHandler; @@ -58,7 +58,7 @@ protected void verifyTransactionDetails() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getOutcome()).isEqualTo(Outcome.SUCCESS); @@ -73,7 +73,7 @@ protected void verifyTransactionDetails() { assertThat(transaction.getContext().getServiceOrigin().hasContent()).isFalse(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getId()).isEqualTo(TestContext.FUNCTION_ARN); assertThat(faas.getName()).isEqualTo(TestContext.FUNCTION_NAME); diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractStreamHandlerLambdaTest.java b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractStreamHandlerLambdaTest.java index ab1f533b4e..1265480d9c 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractStreamHandlerLambdaTest.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/AbstractStreamHandlerLambdaTest.java @@ -21,8 +21,8 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.awslambda.lambdas.TestContext; import co.elastic.apm.agent.impl.metadata.MetaData; -import co.elastic.apm.agent.impl.transaction.Faas; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.FaasImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.sdk.internal.util.VersionUtils; import com.amazonaws.services.lambda.runtime.Context; @@ -70,7 +70,7 @@ public void testBasicCall() throws Throwable { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getOutcome()).isEqualTo(Outcome.SUCCESS); @@ -85,7 +85,7 @@ public void testBasicCall() throws Throwable { assertThat(transaction.getContext().getServiceOrigin().hasContent()).isFalse(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getId()).isEqualTo(TestContext.FUNCTION_ARN); assertThat(faas.getTrigger().getType()).isEqualTo("other"); @@ -101,7 +101,7 @@ public void testCallWithHandlerError() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getOutcome()).isEqualTo(Outcome.FAILURE); assertThat(transaction.getResult()).isEqualTo("failure"); } diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApiGatewayV1LambdaTest.java b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApiGatewayV1LambdaTest.java index 6006e85979..a684b33f13 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApiGatewayV1LambdaTest.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApiGatewayV1LambdaTest.java @@ -21,13 +21,13 @@ import co.elastic.apm.agent.awslambda.lambdas.AbstractFunction; import co.elastic.apm.agent.awslambda.lambdas.ApiGatewayV1LambdaFunction; import co.elastic.apm.agent.awslambda.lambdas.TestContext; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.context.Url; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.context.RequestImpl; +import co.elastic.apm.agent.impl.context.ResponseImpl; +import co.elastic.apm.agent.impl.context.UrlImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.Faas; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.FaasImpl; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; @@ -90,25 +90,25 @@ private APIGatewayProxyRequestEvent createRequestEvent(String httpMethod, @Nulla @Test public void testBasicCall() { - doReturn(CoreConfiguration.EventType.ALL).when(config.getConfig(CoreConfiguration.class)).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(config.getConfig(CoreConfigurationImpl.class)).getCaptureBody(); getFunction().handleRequest(createInput(), context); reporter.awaitTransactionCount(1); reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(HTTP_METHOD + " /" + API_GATEWAY_STAGE + API_GATEWAY_RESOURCE_PATH); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getResult()).isEqualTo("HTTP 2xx"); assertThat(transaction.getOutcome()).isEqualTo(Outcome.SUCCESS); assertThat(reporter.getPartialTransactions()).containsExactly(transaction); - Request request = transaction.getContext().getRequest(); + RequestImpl request = transaction.getContext().getRequest(); assertThat(request.getMethod()).isEqualTo(HTTP_METHOD); assertThat(String.valueOf(request.getBody())).isEqualTo(BODY); assertThat(request.getHttpVersion()).isNull(); - Url url = request.getUrl(); + UrlImpl url = request.getUrl(); assertThat(url.getHostname()).isEqualTo(API_GATEWAY_HOST); assertThat(url.getPort()).isEqualTo(443); assertThat(url.getPathname()).isEqualTo(PATH); @@ -121,7 +121,7 @@ public void testBasicCall() { assertThat(headers.get(HEADER_1_KEY)).isEqualTo(HEADER_1_VALUE); assertThat(headers.get(HEADER_2_KEY)).isEqualTo(HEADER_2_VALUE); - Response response = transaction.getContext().getResponse(); + ResponseImpl response = transaction.getContext().getResponse(); assertThat(response.getStatusCode()).isEqualTo(ApiGatewayV1LambdaFunction.EXPECTED_STATUS_CODE); assertThat(response.getHeaders()).isNotNull(); assertThat(response.getHeaders().get(ApiGatewayV1LambdaFunction.EXPECTED_RESPONSE_HEADER_1_KEY)).isEqualTo(ApiGatewayV1LambdaFunction.EXPECTED_RESPONSE_HEADER_1_VALUE); @@ -137,7 +137,7 @@ public void testBasicCall() { assertThat(transaction.getContext().getServiceOrigin().getId()).isEqualTo(API_ID); assertThat(transaction.getContext().getServiceOrigin().getVersion()).isEqualTo("1.0"); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getId()).isEqualTo(TestContext.FUNCTION_ARN); assertThat(faas.getTrigger().getType()).isEqualTo("http"); @@ -155,7 +155,7 @@ public void testCallWithNullRequestContext(boolean isObjectNull) { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getResult()).isEqualTo("HTTP 2xx"); @@ -171,7 +171,7 @@ public void testCallWithNullRequestContext(boolean isObjectNull) { assertThat(transaction.getContext().getCloudOrigin().getAccountId()).isNull(); assertThat(transaction.getContext().getServiceOrigin().hasContent()).isEqualTo(!isObjectNull); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); if (isObjectNull) { @@ -222,7 +222,7 @@ public void testServiceNameAsLambdaUrl() { getFunction().handleRequest(event, context); reporter.awaitTransactionCount(1); reporter.awaitSpanCount(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getContext().getCloudOrigin().getServiceName()).isEqualTo("lambda url"); } diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApiGatewayV2LambdaTest.java b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApiGatewayV2LambdaTest.java index 4315ca4d3f..85b4317b69 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApiGatewayV2LambdaTest.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApiGatewayV2LambdaTest.java @@ -22,14 +22,13 @@ import co.elastic.apm.agent.awslambda.lambdas.ApiGatewayV1LambdaFunction; import co.elastic.apm.agent.awslambda.lambdas.ApiGatewayV2LambdaFunction; import co.elastic.apm.agent.awslambda.lambdas.TestContext; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.context.Url; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.context.RequestImpl; +import co.elastic.apm.agent.impl.context.ResponseImpl; +import co.elastic.apm.agent.impl.context.UrlImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.Faas; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.tracer.Outcome; +import co.elastic.apm.agent.impl.transaction.FaasImpl; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent; @@ -97,25 +96,25 @@ private APIGatewayV2HTTPEvent createRequestEvent(@Nullable APIGatewayV2HTTPEvent @Test public void testBasicCall() { - doReturn(CoreConfiguration.EventType.ALL).when(config.getConfig(CoreConfiguration.class)).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(config.getConfig(CoreConfigurationImpl.class)).getCaptureBody(); getFunction().handleRequest(createInput(), context); reporter.awaitTransactionCount(1); reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(HTTP_METHOD + " /" + API_GATEWAY_STAGE + API_GATEWAY_RESOURCE_PATH); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getResult()).isEqualTo("HTTP 2xx"); assertThat(reporter.getPartialTransactions()).containsExactly(transaction); - Request request = transaction.getContext().getRequest(); + RequestImpl request = transaction.getContext().getRequest(); assertThat(request.getMethod()).isEqualTo(HTTP_METHOD); assertThat(String.valueOf(request.getBody())).isEqualTo(BODY); assertThat(request.getHttpVersion()).isEqualTo("1.1"); - Url url = request.getUrl(); + UrlImpl url = request.getUrl(); assertThat(url.getHostname()).isEqualTo(API_GATEWAY_HOST); assertThat(url.getPort()).isEqualTo(443); assertThat(url.getPathname()).isEqualTo(PATH); @@ -128,7 +127,7 @@ public void testBasicCall() { assertThat(headers.get(HEADER_1_KEY)).isEqualTo(HEADER_1_VALUE); assertThat(headers.get(HEADER_2_KEY)).isEqualTo(HEADER_2_VALUE); - Response response = transaction.getContext().getResponse(); + ResponseImpl response = transaction.getContext().getResponse(); assertThat(response.getStatusCode()).isEqualTo(ApiGatewayV1LambdaFunction.EXPECTED_STATUS_CODE); assertThat(response.getHeaders()).isNotNull(); assertThat(response.getHeaders().get(ApiGatewayV1LambdaFunction.EXPECTED_RESPONSE_HEADER_1_KEY)).isEqualTo(ApiGatewayV1LambdaFunction.EXPECTED_RESPONSE_HEADER_1_VALUE); @@ -144,7 +143,7 @@ public void testBasicCall() { assertThat(transaction.getContext().getServiceOrigin().getId()).isEqualTo(API_ID); assertThat(transaction.getContext().getServiceOrigin().getVersion()).isEqualTo("2.0"); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getId()).isEqualTo(TestContext.FUNCTION_ARN); assertThat(faas.getTrigger().getType()).isEqualTo("http"); @@ -162,7 +161,7 @@ public void testCallWithNullRequestContext(boolean isObjectNull) { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getResult()).isEqualTo("HTTP 2xx"); @@ -177,7 +176,7 @@ public void testCallWithNullRequestContext(boolean isObjectNull) { assertThat(transaction.getContext().getServiceOrigin().hasContent()).isFalse(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getTrigger().getType()).isEqualTo("other"); @@ -216,7 +215,7 @@ public void testServiceNameAsLambdaUrl() { getFunction().handleRequest(event, context); reporter.awaitTransactionCount(1); reporter.awaitSpanCount(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getContext().getCloudOrigin().getServiceName()).isEqualTo("lambda url"); } diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApplicationLoadBalancerRequestEventLambdaTest.java b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApplicationLoadBalancerRequestEventLambdaTest.java index 5583ba1834..a84bb69f0b 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApplicationLoadBalancerRequestEventLambdaTest.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/ApplicationLoadBalancerRequestEventLambdaTest.java @@ -22,24 +22,20 @@ import co.elastic.apm.agent.awslambda.lambdas.ApiGatewayV1LambdaFunction; import co.elastic.apm.agent.awslambda.lambdas.ApplicationLoadBalancerRequestLambdaFunction; import co.elastic.apm.agent.awslambda.lambdas.TestContext; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.context.Url; -import co.elastic.apm.agent.impl.transaction.Faas; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.context.RequestImpl; +import co.elastic.apm.agent.impl.context.ResponseImpl; +import co.elastic.apm.agent.impl.context.UrlImpl; +import co.elastic.apm.agent.impl.transaction.FaasImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; -import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent; import com.amazonaws.services.lambda.runtime.events.ApplicationLoadBalancerRequestEvent; import com.amazonaws.services.lambda.runtime.events.ApplicationLoadBalancerResponseEvent; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import javax.annotation.Nonnull; import java.util.Arrays; import java.util.Map; import java.util.Objects; @@ -94,25 +90,25 @@ protected boolean supportsContextPropagation() { @Test public void testBasicCall() { - doReturn(CoreConfiguration.EventType.ALL).when(config.getConfig(CoreConfiguration.class)).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(config.getConfig(CoreConfigurationImpl.class)).getCaptureBody(); getFunction().handleRequest(createInput(), context); reporter.awaitTransactionCount(1); reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo("FUNCTION_NAME"); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getResult()).isEqualTo("HTTP 2xx"); assertThat(transaction.getOutcome()).isEqualTo(Outcome.SUCCESS); assertThat(reporter.getPartialTransactions()).containsExactly(transaction); - Request request = transaction.getContext().getRequest(); + RequestImpl request = transaction.getContext().getRequest(); assertThat(request.getMethod()).isEqualTo(HTTP_METHOD); assertThat(request.getBody()).isNull(); assertThat(request.getHttpVersion()).isNull(); - Url url = request.getUrl(); + UrlImpl url = request.getUrl(); assertThat(url.getHostname()).isEqualTo("blabla.com"); assertThat(url.getPort()).isEqualTo(443); assertThat(url.getPathname()).isEqualTo("/toolz/api/v2.0/downloadPDF/PDF_2020-09-11_11-06-01.pdf"); @@ -128,7 +124,7 @@ public void testBasicCall() { assertThat(headers.get("connection")).isEqualTo("Keep-Alive"); assertThat(headers.get("accept-encoding")).isEqualTo("gzip,deflate"); - Response response = transaction.getContext().getResponse(); + ResponseImpl response = transaction.getContext().getResponse(); assertThat(response.getStatusCode()).isEqualTo(ApiGatewayV1LambdaFunction.EXPECTED_STATUS_CODE); assertThat(response.getHeaders()).isNotNull(); assertThat(response.getHeaders().get(ApiGatewayV1LambdaFunction.EXPECTED_RESPONSE_HEADER_1_KEY)).isEqualTo(ApiGatewayV1LambdaFunction.EXPECTED_RESPONSE_HEADER_1_VALUE); @@ -145,7 +141,7 @@ public void testBasicCall() { assertThat(transaction.getContext().getServiceOrigin().getId()).isEqualTo("arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/lambda-279XGJDqGZ5rsrHC2Fjr/49e9d65c45c6791a"); assertThat(transaction.getContext().getServiceOrigin().getVersion()).isNull(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getId()).isEqualTo(TestContext.FUNCTION_ARN); assertThat(faas.getTrigger().getType()).isEqualTo("http"); @@ -163,7 +159,7 @@ public void testCallWithNullRequestContext() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getResult()).isEqualTo("HTTP 2xx"); @@ -178,7 +174,7 @@ public void testCallWithNullRequestContext() { assertThat(transaction.getContext().getServiceOrigin().hasContent()).isFalse(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getTrigger().getType()).isEqualTo("http"); diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/BaseGatewayLambdaTest.java b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/BaseGatewayLambdaTest.java index 22394fb6d6..7493babe05 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/BaseGatewayLambdaTest.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/BaseGatewayLambdaTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.awslambda; import co.elastic.apm.agent.awslambda.lambdas.TestContext; -import co.elastic.apm.agent.impl.transaction.Faas; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.FaasImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import org.junit.jupiter.api.Test; @@ -38,7 +38,7 @@ public void testCallWithNullInput() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getResult()).isEqualTo("HTTP 2xx"); @@ -51,7 +51,7 @@ public void testCallWithNullInput() { assertThat(transaction.getContext().getServiceOrigin().hasContent()).isFalse(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getTrigger().getType()).isEqualTo("other"); @@ -67,7 +67,7 @@ public void testCallWithErrorStatusCode() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getResult()).isEqualTo("HTTP 5xx"); assertThat(transaction.getOutcome()).isEqualTo(Outcome.FAILURE); } diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/S3EventLambdaTest.java b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/S3EventLambdaTest.java index 82c737523c..045d375f88 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/S3EventLambdaTest.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/S3EventLambdaTest.java @@ -21,8 +21,8 @@ import co.elastic.apm.agent.awslambda.lambdas.AbstractFunction; import co.elastic.apm.agent.awslambda.lambdas.S3EventLambdaFunction; import co.elastic.apm.agent.awslambda.lambdas.TestContext; -import co.elastic.apm.agent.impl.transaction.Faas; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.FaasImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import com.amazonaws.services.lambda.runtime.events.S3Event; import com.amazonaws.services.lambda.runtime.events.models.s3.S3EventNotification; @@ -80,7 +80,7 @@ public void testBasicCall() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(S3_EVENT_NAME + " " + S3_BUCKET_NAME); assertThat(transaction.getType()).isEqualTo("messaging"); assertThat(transaction.getResult()).isEqualTo("success"); @@ -98,7 +98,7 @@ public void testBasicCall() { assertThat(transaction.getContext().getCloudOrigin().getRegion()).isEqualTo(EVENT_SOURCE_REGION); assertThat(transaction.getContext().getCloudOrigin().getAccountId()).isNull(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getId()).isEqualTo(TestContext.FUNCTION_ARN); assertThat(faas.getTrigger().getType()).isEqualTo("datasource"); @@ -115,7 +115,7 @@ public void testCallWithNullInput() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getResult()).isEqualTo("success"); @@ -129,7 +129,7 @@ public void testCallWithNullInput() { assertThat(transaction.getContext().getServiceOrigin().hasContent()).isFalse(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getTrigger().getType()).isEqualTo("other"); @@ -157,7 +157,7 @@ private void validateResultsForUnspecifiedRecord() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("messaging"); assertThat(transaction.getResult()).isEqualTo("success"); @@ -171,14 +171,14 @@ private void validateResultsForUnspecifiedRecord() { assertThat(transaction.getContext().getServiceOrigin().hasContent()).isFalse(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getTrigger().getType()).isEqualTo("datasource"); assertThat(faas.getTrigger().getRequestId()).isNull(); } - private void verifyOtelAttributes(Transaction transaction) { + private void verifyOtelAttributes(TransactionImpl transaction) { Object s3keyAttribute = transaction.getOtelAttributes().get("aws.s3.key"); assertThat(s3keyAttribute).isInstanceOf(String.class).isEqualTo("b21b84d653bb07b05b1e6b33684dc11b"); diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/SNSEventLambdaTest.java b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/SNSEventLambdaTest.java index f85e58c5fa..c6fb10632a 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/SNSEventLambdaTest.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/SNSEventLambdaTest.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.awslambda.lambdas.AbstractFunction; import co.elastic.apm.agent.awslambda.lambdas.SNSEventLambdaFunction; import co.elastic.apm.agent.awslambda.lambdas.TestContext; -import co.elastic.apm.agent.impl.transaction.Faas; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.FaasImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import com.amazonaws.services.lambda.runtime.events.SNSEvent; import org.joda.time.DateTime; @@ -80,8 +80,8 @@ private SNSEvent.SNSRecord createSnsRecord(boolean useDefaultTraceparent) { sns.setMessageAttributes(Map.of( HEADER_1_KEY,header_1_Attribute, HEADER_2_KEY, header_2_Attribute, - TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, traceparent_Attribute, - TraceContext.TRACESTATE_HEADER_NAME, tracestate_Attribute + TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, traceparent_Attribute, + TraceContextImpl.TRACESTATE_HEADER_NAME, tracestate_Attribute )); SNSEvent.SNSRecord record = new SNSEvent.SNSRecord(); @@ -93,7 +93,7 @@ private SNSEvent.SNSRecord createSnsRecord(boolean useDefaultTraceparent) { } @Override - protected void verifyDistributedTracing(TraceContext traceContext) { + protected void verifyDistributedTracing(TraceContextImpl traceContext) { // batch processing root transaction, distributed tracing is supported through span links assertThat(traceContext.getParentId().isEmpty()).isTrue(); assertThat(traceContext.getTraceState().getSampleRate()).isEqualTo(1d); @@ -107,9 +107,9 @@ public void testBasicCall() { } private void verifySpanLink(String traceId, String parentId) { - Transaction transaction = reporter.getFirstTransaction(); - List spanLinks = transaction.getSpanLinks(); - List matchedSpanLinks = spanLinks.stream().filter(spanLink -> spanLink.getParentId().toString().equals(parentId)).collect(Collectors.toList()); + TransactionImpl transaction = reporter.getFirstTransaction(); + List spanLinks = transaction.getSpanLinks(); + List matchedSpanLinks = spanLinks.stream().filter(spanLink -> spanLink.getParentId().toString().equals(parentId)).collect(Collectors.toList()); assertThat(matchedSpanLinks).hasSize(1); assertThat(matchedSpanLinks.get(0).getTraceId().toString()).isEqualTo(traceId); } @@ -119,7 +119,7 @@ private void verifyTransactionDetails() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(reporter.getPartialTransactions()).containsExactly(transaction); printTransactionJson(transaction); @@ -141,7 +141,7 @@ private void verifyTransactionDetails() { assertThat(transaction.getContext().getCloudOrigin().getRegion()).isEqualTo(EVENT_SOURCE_REGION); assertThat(transaction.getContext().getCloudOrigin().getAccountId()).isEqualTo(EVENT_SOURCE_ACCOUNT_ID); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getId()).isEqualTo(TestContext.FUNCTION_ARN); assertThat(faas.getTrigger().getType()).isEqualTo("pubsub"); @@ -155,7 +155,7 @@ public void testCallWithNullInput() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getResult()).isEqualTo("success"); @@ -169,7 +169,7 @@ public void testCallWithNullInput() { assertThat(transaction.getContext().getServiceOrigin().hasContent()).isFalse(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getTrigger().getType()).isEqualTo("other"); @@ -209,7 +209,7 @@ private void validateResultsForUnspecifiedRecord() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("messaging"); assertThat(transaction.getResult()).isEqualTo("success"); @@ -223,7 +223,7 @@ private void validateResultsForUnspecifiedRecord() { assertThat(transaction.getContext().getServiceOrigin().hasContent()).isFalse(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getTrigger().getType()).isEqualTo("pubsub"); diff --git a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/SQSEventLambdaTest.java b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/SQSEventLambdaTest.java index 89f01618b3..36c448d808 100644 --- a/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/SQSEventLambdaTest.java +++ b/apm-agent-plugins/apm-awslambda-plugin/src/test/java/co/elastic/apm/agent/awslambda/SQSEventLambdaTest.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.awslambda.lambdas.AbstractFunction; import co.elastic.apm.agent.awslambda.lambdas.SQSEventLambdaFunction; import co.elastic.apm.agent.awslambda.lambdas.TestContext; -import co.elastic.apm.agent.impl.transaction.Faas; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.FaasImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import com.amazonaws.services.lambda.runtime.events.SQSEvent; import org.junit.jupiter.api.BeforeAll; @@ -78,8 +78,8 @@ private SQSEvent.SQSMessage createSqsMessage(boolean useDefaultTraceparent) { sqsMessage.setMessageAttributes(Map.of( "SentTimestamp", sentTimestampAttribute, HEADER_1_KEY, header_1_Attribute, - TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, traceparent_Attribute, - TraceContext.TRACESTATE_HEADER_NAME, tracestate_Attribute + TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, traceparent_Attribute, + TraceContextImpl.TRACESTATE_HEADER_NAME, tracestate_Attribute )); sqsMessage.setBody(MESSAGE_BODY); return sqsMessage; @@ -92,7 +92,7 @@ private SQSEvent createSQSEventWithNulls() { } @Override - protected void verifyDistributedTracing(TraceContext traceContext) { + protected void verifyDistributedTracing(TraceContextImpl traceContext) { // batch processing root transaction, distributed tracing is supported through span links assertThat(traceContext.getParentId().isEmpty()).isTrue(); assertThat(traceContext.getTraceState().getSampleRate()).isEqualTo(1d); @@ -106,9 +106,9 @@ public void testBasicCall() { } private void verifySpanLink(String traceId, String parentId) { - Transaction transaction = reporter.getFirstTransaction(); - List spanLinks = transaction.getSpanLinks(); - List matchedSpanLinks = spanLinks.stream().filter(spanLink -> spanLink.getParentId().toString().equals(parentId)).collect(Collectors.toList()); + TransactionImpl transaction = reporter.getFirstTransaction(); + List spanLinks = transaction.getSpanLinks(); + List matchedSpanLinks = spanLinks.stream().filter(spanLink -> spanLink.getParentId().toString().equals(parentId)).collect(Collectors.toList()); assertThat(matchedSpanLinks).hasSize(1); assertThat(matchedSpanLinks.get(0).getTraceId().toString()).isEqualTo(traceId); } @@ -118,7 +118,7 @@ private void verifyTransactionDetails() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(reporter.getPartialTransactions()).containsExactly(transaction); printTransactionJson(transaction); @@ -140,7 +140,7 @@ private void verifyTransactionDetails() { assertThat(transaction.getContext().getCloudOrigin().getRegion()).isEqualTo(EVENT_SOURCE_REGION); assertThat(transaction.getContext().getCloudOrigin().getAccountId()).isEqualTo(EVENT_SOURCE_ACCOUNT_ID); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getId()).isEqualTo(TestContext.FUNCTION_ARN); assertThat(faas.getTrigger().getType()).isEqualTo("pubsub"); @@ -154,7 +154,7 @@ public void testCallWithNullInput() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getResult()).isEqualTo("success"); @@ -168,7 +168,7 @@ public void testCallWithNullInput() { assertThat(transaction.getContext().getServiceOrigin().hasContent()).isFalse(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getTrigger().getType()).isEqualTo("other"); @@ -196,7 +196,7 @@ private void validateResultsForUnspecifiedMessage() { reporter.awaitSpanCount(1); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("child-span"); assertThat(reporter.getFirstSpan().getTransaction()).isEqualTo(reporter.getFirstTransaction()); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo(TestContext.FUNCTION_NAME); assertThat(transaction.getType()).isEqualTo("messaging"); assertThat(transaction.getResult()).isEqualTo("success"); @@ -210,7 +210,7 @@ private void validateResultsForUnspecifiedMessage() { assertThat(transaction.getContext().getServiceOrigin().hasContent()).isFalse(); - Faas faas = transaction.getFaas(); + FaasImpl faas = transaction.getFaas(); assertThat(faas.getExecution()).isEqualTo(TestContext.AWS_REQUEST_ID); assertThat(faas.getTrigger().getType()).isEqualTo("pubsub"); diff --git a/apm-agent-plugins/apm-cassandra/apm-cassandra-core-plugin/pom.xml b/apm-agent-plugins/apm-cassandra/apm-cassandra-core-plugin/pom.xml index c94715beb5..9cd920e9a2 100644 --- a/apm-agent-plugins/apm-cassandra/apm-cassandra-core-plugin/pom.xml +++ b/apm-agent-plugins/apm-cassandra/apm-cassandra-core-plugin/pom.xml @@ -3,7 +3,7 @@ apm-cassandra co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/pom.xml b/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/pom.xml index ee0d87ee35..4cc7446cab 100644 --- a/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/pom.xml +++ b/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/pom.xml @@ -3,7 +3,7 @@ apm-cassandra co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/src/test/java/co/elastic/apm/agent/cassandra/Cassandra3InstrumentationIT.java b/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/src/test/java/co/elastic/apm/agent/cassandra/Cassandra3InstrumentationIT.java index 5f87afb60c..b78ea2dc43 100644 --- a/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/src/test/java/co/elastic/apm/agent/cassandra/Cassandra3InstrumentationIT.java +++ b/apm-agent-plugins/apm-cassandra/apm-cassandra3-plugin/src/test/java/co/elastic/apm/agent/cassandra/Cassandra3InstrumentationIT.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.cassandra; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.testutils.TestContainersUtils; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Session; @@ -56,7 +56,7 @@ class Cassandra3InstrumentationIT extends AbstractInstrumentationTest { .withEnv("JAVA_TOOL_OPTIONS", "-Dcassandra.skip_wait_for_gossip_to_settle=0"); private static Session session; private static Cluster cluster; - private Transaction transaction; + private TransactionImpl transaction; @BeforeAll @@ -93,19 +93,19 @@ void test() throws Exception { reporter.awaitSpanCount(3); - Span createSpan = reporter.getSpanByName("CREATE"); + SpanImpl createSpan = reporter.getSpanByName("CREATE"); assertThat(createSpan).isSync(); assertThat(createSpan.getContext().getDb()) .hasStatement("CREATE TABLE users (id UUID, name text, PRIMARY KEY(name, id))") .hasInstance(KEYSPACE); - Span insertSpan = reporter.getSpanByName("INSERT INTO users"); + SpanImpl insertSpan = reporter.getSpanByName("INSERT INTO users"); assertThat(insertSpan).isSync(); assertThat(insertSpan.getContext().getDb()) .hasStatement("INSERT INTO users (id, name) values (?, ?)") .hasInstance(KEYSPACE); - Span selectSpan = reporter.getSpanByName("SELECT FROM users"); + SpanImpl selectSpan = reporter.getSpanByName("SELECT FROM users"); assertThat(selectSpan).isAsync(); assertThat(selectSpan.getContext().getDb()) .hasStatement("SELECT * FROM users where name = 'alice' ALLOW FILTERING") diff --git a/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/pom.xml b/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/pom.xml index e526b2d258..f7dbbbf480 100644 --- a/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/pom.xml +++ b/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/pom.xml @@ -3,7 +3,7 @@ apm-cassandra co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/src/test/java/co/elastic/apm/agent/cassandra/Cassandra4InstrumentationIT.java b/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/src/test/java/co/elastic/apm/agent/cassandra/Cassandra4InstrumentationIT.java index 398d6cfdad..4785ec6513 100644 --- a/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/src/test/java/co/elastic/apm/agent/cassandra/Cassandra4InstrumentationIT.java +++ b/apm-agent-plugins/apm-cassandra/apm-cassandra4-plugin/src/test/java/co/elastic/apm/agent/cassandra/Cassandra4InstrumentationIT.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.cassandra; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.testutils.TestContainersUtils; import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.config.DefaultDriverOption; @@ -59,7 +59,7 @@ class Cassandra4InstrumentationIT extends AbstractInstrumentationTest { .withEnv("JAVA_TOOL_OPTIONS", "-Dcassandra.skip_wait_for_gossip_to_settle=0"); private static CqlSession session; private static int cassandraPort; - private Transaction transaction; + private TransactionImpl transaction; @BeforeAll @@ -103,19 +103,19 @@ void test() throws Exception { reporter.awaitSpanCount(3); - Span createSpan = reporter.getSpanByName("CREATE"); + SpanImpl createSpan = reporter.getSpanByName("CREATE"); assertThat(createSpan).isSync(); assertThat(createSpan.getContext().getDb()) .hasStatement("CREATE TABLE users (id UUID PRIMARY KEY, name text)") .hasInstance(KEYSPACE); - Span insertSpan = reporter.getSpanByName("INSERT INTO users"); + SpanImpl insertSpan = reporter.getSpanByName("INSERT INTO users"); assertThat(insertSpan).isSync(); assertThat(insertSpan.getContext().getDb()) .hasStatement("INSERT INTO users (id, name) values (?, ?)") .hasInstance(KEYSPACE); - Span selectSpan = reporter.getSpanByName("SELECT FROM users"); + SpanImpl selectSpan = reporter.getSpanByName("SELECT FROM users"); assertThat(selectSpan).isAsync(); assertThat(selectSpan.getContext().getDb()) .hasStatement("SELECT * FROM users where name = 'alice' ALLOW FILTERING") diff --git a/apm-agent-plugins/apm-cassandra/pom.xml b/apm-agent-plugins/apm-cassandra/pom.xml index 636c421dd1..fab826204d 100644 --- a/apm-agent-plugins/apm-cassandra/pom.xml +++ b/apm-agent-plugins/apm-cassandra/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-dubbo-plugin/pom.xml b/apm-agent-plugins/apm-dubbo-plugin/pom.xml index 35f6b39c19..a707d06b56 100644 --- a/apm-agent-plugins/apm-dubbo-plugin/pom.xml +++ b/apm-agent-plugins/apm-dubbo-plugin/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/AbstractDubboInstrumentationTest.java b/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/AbstractDubboInstrumentationTest.java index 68a240955f..75c5778d8e 100644 --- a/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/AbstractDubboInstrumentationTest.java +++ b/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/AbstractDubboInstrumentationTest.java @@ -19,13 +19,13 @@ package co.elastic.apm.agent.dubbo; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.dubbo.api.DubboTestApi; import co.elastic.apm.agent.dubbo.api.exception.BizException; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.test.TestPort; import co.elastic.apm.agent.tracer.Outcome; import org.junit.jupiter.api.AfterAll; @@ -45,7 +45,7 @@ public abstract class AbstractDubboInstrumentationTest extends AbstractInstrumentationTest { - private static CoreConfiguration coreConfig; + private static CoreConfigurationImpl coreConfig; @Nullable private static DubboTestApi dubboTestApi; @@ -54,7 +54,7 @@ public abstract class AbstractDubboInstrumentationTest extends AbstractInstrumen @BeforeAll static void initInstrumentation() { - coreConfig = tracer.getConfig(CoreConfiguration.class); + coreConfig = tracer.getConfig(CoreConfigurationImpl.class); } @BeforeEach @@ -71,14 +71,14 @@ void beforeEach() { dubboTestApi = buildDubboTestApi(port, backendPort); } - doReturn(CoreConfiguration.EventType.OFF).when(coreConfig).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.OFF).when(coreConfig).getCaptureBody(); startTestRootTransaction("dubbo test"); } @AfterEach void afterEach() { - Transaction transaction = tracer.currentTransaction(); + TransactionImpl transaction = tracer.currentTransaction(); if (transaction != null) { transaction.deactivate().end(); } @@ -125,15 +125,15 @@ public void testNormalReturn() { // transaction on the receiving side reporter.awaitTransactionCount(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); validateDubboTransaction(transaction, "normalReturn"); // span on the emitting side (outgoing from this method) reporter.awaitSpanCount(1); - Span span = validateDubboSpan(reporter.getFirstSpan(), "normalReturn"); + SpanImpl span = validateDubboSpan(reporter.getFirstSpan(), "normalReturn"); assertThat(span).isSync(); - List errors = reporter.getErrors(); + List errors = reporter.getErrors(); assertThat(errors.size()).isEqualTo(0); } @@ -147,9 +147,9 @@ public void testBizException() { assertThat(e).isInstanceOf(BizException.class); } - List errors = reporter.getErrors(); + List errors = reporter.getErrors(); assertThat(errors).hasSize(2); - for (ErrorCapture error : errors) { + for (ErrorCaptureImpl error : errors) { assertThat(error.getException()).isInstanceOf(BizException.class); } @@ -179,20 +179,20 @@ public void testAsyncNoReturnException() throws Exception { assertThat(reporter.getFirstSpan(5000)).isNotNull(); assertThat(reporter.getTransactions()).hasSize(1); assertThat(reporter.getSpans()).hasSize(2); - List errors = reporter.getErrors(); + List errors = reporter.getErrors(); assertThat(errors).hasSize(1); assertThat(errors.get(0).getException()).isInstanceOf(BizException.class); assertThat(reporter.getSpanByName("DubboTestApi#asyncNoReturn")).isAsync(); } - public void validateDubboTransaction(Transaction transaction, String methodName) { + public void validateDubboTransaction(TransactionImpl transaction, String methodName) { assertThat(transaction) .hasType("request") .hasName("DubboTestApi#" + methodName); } - public static Span validateDubboSpan(Span span, String methodName) { + public static SpanImpl validateDubboSpan(SpanImpl span, String methodName) { assertThat(span) .hasName("DubboTestApi#" + methodName) .hasType("external") @@ -225,8 +225,8 @@ public void testBothProviderAndConsumer() { assertThat(reporter.getTransactions()).hasSize(2); assertThat(reporter.getSpans()).hasSize(2); - Map transactionMap = buildMap(reporter.getTransactions()); - Map spanMap = buildMap(reporter.getSpans()); + Map transactionMap = buildMap(reporter.getTransactions()); + Map spanMap = buildMap(reporter.getSpans()); String testApiName = "DubboTestApi#willInvokeAnotherApi"; String anotherApiName = "AnotherApi#echo"; @@ -241,7 +241,7 @@ public void testBothProviderAndConsumer() { .isEqualTo(transactionMap.get(anotherApiName).getTraceContext().getParentId().toString()); } - public > Map buildMap(List list) { + public > Map buildMap(List list) { Map map = new HashMap<>(); for (T t : list) { map.put(t.getNameAsString(), t); diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/AlibabaDubboInstrumentationTest.java b/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/AlibabaDubboInstrumentationTest.java index f48be7115d..be3dfb0a5e 100644 --- a/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/AlibabaDubboInstrumentationTest.java +++ b/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/AlibabaDubboInstrumentationTest.java @@ -23,9 +23,9 @@ import co.elastic.apm.agent.dubbo.api.exception.BizException; import co.elastic.apm.agent.dubbo.api.impl.AnotherApiImpl; import co.elastic.apm.agent.dubbo.api.impl.DubboTestApiImpl; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import com.alibaba.dubbo.config.ApplicationConfig; import com.alibaba.dubbo.config.MethodConfig; import com.alibaba.dubbo.config.ProtocolConfig; @@ -143,14 +143,14 @@ public void testAsync() throws Exception { ret = (String) future.get(); assertThat(ret).isEqualTo(arg); - Transaction transaction = reporter.getFirstTransaction(1000); + TransactionImpl transaction = reporter.getFirstTransaction(1000); validateDubboTransaction(transaction, "async"); assertThat(reporter.getFirstSpan(500)).isNotNull(); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(1); - Span span = validateDubboSpan(spans.get(0), "async"); + SpanImpl span = validateDubboSpan(spans.get(0), "async"); assertThat(span).isAsync(); } @@ -167,16 +167,16 @@ public void testAsyncException() throws Exception { } catch (Exception e) { // exception from Future will be wrapped as RpcException by dubbo implementation assertThat(e.getCause()).isInstanceOf(BizException.class); - Transaction transaction = reporter.getFirstTransaction(1000); + TransactionImpl transaction = reporter.getFirstTransaction(1000); assertThat(transaction).isNotNull(); assertThat(reporter.getFirstSpan(500)).isNotNull(); assertThat(reporter.getSpans()).hasSize(1); assertThat(reporter.getFirstSpan()).isAsync(); - List errors = reporter.getErrors(); + List errors = reporter.getErrors(); assertThat(errors.size()).isEqualTo(2); - for (ErrorCapture error : errors) { + for (ErrorCaptureImpl error : errors) { assertThat(error.getException()).isInstanceOf(BizException.class); } } diff --git a/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/ApacheDubboInstrumentationTest.java b/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/ApacheDubboInstrumentationTest.java index 42787b1d4b..8747d6ffa4 100644 --- a/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/ApacheDubboInstrumentationTest.java +++ b/apm-agent-plugins/apm-dubbo-plugin/src/test/java/co/elastic/apm/agent/dubbo/ApacheDubboInstrumentationTest.java @@ -23,9 +23,9 @@ import co.elastic.apm.agent.dubbo.api.exception.BizException; import co.elastic.apm.agent.dubbo.api.impl.AnotherApiImpl; import co.elastic.apm.agent.dubbo.api.impl.DubboTestApiImpl; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.MethodConfig; import org.apache.dubbo.config.ProtocolConfig; @@ -146,7 +146,7 @@ public void testAsync() throws Exception { ret = (String) future.get(); assertThat(ret).isEqualTo(arg); - Transaction transaction = reporter.getFirstTransaction(1000); + TransactionImpl transaction = reporter.getFirstTransaction(1000); validateDubboTransaction(transaction, "async"); assertThat(reporter.getFirstSpan(500)) @@ -168,14 +168,14 @@ public void testAsyncException() throws Exception { } catch (Exception e) { // exception from Future will be wrapped as RpcException by dubbo implementation assertThat(e.getCause()).isInstanceOf(BizException.class); - Transaction transaction = reporter.getFirstTransaction(1000); + TransactionImpl transaction = reporter.getFirstTransaction(1000); assertThat(reporter.getFirstSpan(500)).isNotNull(); assertThat(reporter.getSpans()).hasSize(1); assertThat(reporter.getSpanByName("DubboTestApi#async")).isAsync(); - List errors = reporter.getErrors(); + List errors = reporter.getErrors(); assertThat(errors.size()).isEqualTo(2); - for (ErrorCapture error : errors) { + for (ErrorCaptureImpl error : errors) { assertThat(error.getException()).isInstanceOf(BizException.class); } } @@ -189,7 +189,7 @@ public void testAsyncByFuture() throws Exception { assertThat(future).isNotNull(); assertThat(future.get()).isEqualTo(arg); - Transaction transaction = reporter.getFirstTransaction(1000); + TransactionImpl transaction = reporter.getFirstTransaction(1000); validateDubboTransaction(transaction, "asyncByFuture"); assertThat(reporter.getFirstSpan(500)).isNotNull(); @@ -208,7 +208,7 @@ public void testAsyncByFutureException() { future.get(); fail("not ok"); } catch (Exception e) { - Transaction transaction = reporter.getFirstTransaction(1000); + TransactionImpl transaction = reporter.getFirstTransaction(1000); validateDubboTransaction(transaction, "asyncByFuture"); assertThat(reporter.getFirstSpan(500)).isNotNull(); @@ -217,9 +217,9 @@ public void testAsyncByFutureException() { assertThat(reporter.getSpanByName("DubboTestApi#asyncByFuture")) .isAsync(); - List errors = reporter.getErrors(); + List errors = reporter.getErrors(); assertThat(errors).hasSize(2); - for (ErrorCapture error : errors) { + for (ErrorCaptureImpl error : errors) { assertThat(error.getException()).isInstanceOf(BizException.class); } } @@ -232,11 +232,11 @@ public void testAsyncByAsyncContext() throws Exception { String ret = dubboTestApi.asyncByAsyncContext(arg); assertThat(ret).isEqualTo(arg); - Transaction transaction = reporter.getFirstTransaction(1000); + TransactionImpl transaction = reporter.getFirstTransaction(1000); validateDubboTransaction(transaction, "asyncByAsyncContext"); assertThat(reporter.getFirstSpan(500)).isNotNull(); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans.size()).isEqualTo(2); assertThat(reporter.getSpanByName("DubboTestApi#asyncByAsyncContext")).isNotNull(); @@ -249,18 +249,18 @@ public void testAsyncByAsyncContextException() throws Exception { dubboTestApi.asyncByAsyncContext("error"); fail("not ok"); } catch (BizException e) { - Transaction transaction = reporter.getFirstTransaction(1000); + TransactionImpl transaction = reporter.getFirstTransaction(1000); validateDubboTransaction(transaction, "asyncByAsyncContext"); assertThat(reporter.getFirstSpan(5000)).isNotNull(); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans.size()).isEqualTo(2); assertThat(reporter.getSpanByName("DubboTestApi#asyncByAsyncContext")).isNotNull(); - List errors = reporter.getErrors(); + List errors = reporter.getErrors(); assertThat(errors).hasSize(2); - for (ErrorCapture error : errors) { + for (ErrorCaptureImpl error : errors) { assertThat(error.getException()).isInstanceOf(BizException.class); } } diff --git a/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml b/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml index 05362c6d82..ffc9e4033d 100644 --- a/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml +++ b/apm-agent-plugins/apm-ecs-logging-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-ecs-logging-plugin diff --git a/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/EcsLoggingUtils.java b/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/EcsLoggingUtils.java index bfae79d419..d2116bd018 100644 --- a/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/EcsLoggingUtils.java +++ b/apm-agent-plugins/apm-ecs-logging-plugin/src/main/java/co/elastic/apm/agent/ecs_logging/EcsLoggingUtils.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.ecs_logging; -import co.elastic.apm.agent.tracer.service.ServiceAwareTracer; +import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.service.ServiceInfo; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -38,7 +38,7 @@ public class EcsLoggingUtils { private static final WeakSet versionChecked = WeakConcurrent.buildSet(); private static final WeakSet environmentChecked = WeakConcurrent.buildSet(); - private static final ServiceAwareTracer tracer = GlobalTracer.get().require(ServiceAwareTracer.class); + private static final Tracer tracer = GlobalTracer.get(); @Nullable public static String getServiceName() { diff --git a/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceEnvironmentTest.java b/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceEnvironmentTest.java index 915975ebac..77065b3a57 100644 --- a/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceEnvironmentTest.java +++ b/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceEnvironmentTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.ecs_logging; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,7 +29,7 @@ public abstract class EcsServiceEnvironmentTest extends EcsLoggingTest { @BeforeEach public void setUp() { - doReturn("test").when(tracer.getConfig(CoreConfiguration.class)).getEnvironment(); + doReturn("test").when(tracer.getConfig(CoreConfigurationImpl.class)).getEnvironment(); } @Test diff --git a/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceNameTest.java b/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceNameTest.java index 5684ef159f..8b1e825156 100644 --- a/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceNameTest.java +++ b/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceNameTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.ecs_logging; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,7 +29,7 @@ public abstract class EcsServiceNameTest extends EcsLoggingTest { @BeforeEach public void setUp() { - doReturn("foo").when(tracer.getConfig(CoreConfiguration.class)).getServiceName(); + doReturn("foo").when(tracer.getConfig(CoreConfigurationImpl.class)).getServiceName(); } @Test diff --git a/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceVersionTest.java b/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceVersionTest.java index a2864c5e8c..e86393d442 100644 --- a/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceVersionTest.java +++ b/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/EcsServiceVersionTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.ecs_logging; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,7 +29,7 @@ public abstract class EcsServiceVersionTest extends EcsLoggingTest { @BeforeEach public void setUp() { - doReturn("1.0").when(tracer.getConfig(CoreConfiguration.class)).getServiceVersion(); + doReturn("1.0").when(tracer.getConfig(CoreConfigurationImpl.class)).getServiceVersion(); } @Test diff --git a/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/jul/JulEcsMdcInstrumentationTest.java b/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/jul/JulEcsMdcInstrumentationTest.java index 3fc362644b..73d3ce9e4e 100644 --- a/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/jul/JulEcsMdcInstrumentationTest.java +++ b/apm-agent-plugins/apm-ecs-logging-plugin/src/test/java/co/elastic/apm/agent/ecs_logging/jul/JulEcsMdcInstrumentationTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.ecs_logging.jul; import co.elastic.apm.agent.ecs_logging.EcsLoggingTest; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.logging.jul.EcsFormatter; import org.junit.jupiter.api.Test; @@ -42,7 +42,7 @@ void testNoCorrelation() { @Test void testActiveTransaction() { - Transaction transaction = startTestRootTransaction("log"); + TransactionImpl transaction = startTestRootTransaction("log"); try { String json = createLogMsg(); assertThat(getJson(json, "transaction.id")).isEqualTo(transaction.getTraceContext().getTransactionId().toString()); @@ -54,7 +54,7 @@ void testActiveTransaction() { @Test void testActiveError() { - ErrorCapture error = new ErrorCapture(tracer); + ErrorCaptureImpl error = new ErrorCaptureImpl(tracer); error.activate(); try { diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/pom.xml b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/pom.xml index cec243e0f6..758569046c 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/pom.xml +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/pom.xml @@ -5,7 +5,7 @@ apm-es-restclient-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-es-restclient-plugin-5_6 diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/test/java/co/elastic/apm/agent/esrestclient/v5_6/ElasticsearchRestClientInstrumentationIT.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/test/java/co/elastic/apm/agent/esrestclient/v5_6/ElasticsearchRestClientInstrumentationIT.java index 76916bf9c6..b3da07daf2 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/test/java/co/elastic/apm/agent/esrestclient/v5_6/ElasticsearchRestClientInstrumentationIT.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-5_6/src/test/java/co/elastic/apm/agent/esrestclient/v5_6/ElasticsearchRestClientInstrumentationIT.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.esrestclient.v5_6; import co.elastic.apm.agent.esrestclient.AbstractEsClientInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.Outcome; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; @@ -185,10 +185,10 @@ public void testDocumentScenario() throws IOException, ExecutionException, Inter assertThat(sr.getHits().getAt(0).getSourceAsMap().get(FOO)).isEqualTo(BAZ); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(2); boolean updateSpanFound = false; - for (Span span : spans) { + for (SpanImpl span : spans) { if (span.getNameAsString().contains("_update")) { updateSpanFound = true; break; diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/pom.xml b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/pom.xml index 47d3f69bc9..300ccab1b1 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/pom.xml +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/pom.xml @@ -5,7 +5,7 @@ apm-es-restclient-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-es-restclient-plugin-6_4 diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/test/java/co/elastic/apm/agent/esrestclient/v6_4/AbstractEs6_4ClientInstrumentationTest.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/test/java/co/elastic/apm/agent/esrestclient/v6_4/AbstractEs6_4ClientInstrumentationTest.java index e3e0aa498d..83200e69d0 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/test/java/co/elastic/apm/agent/esrestclient/v6_4/AbstractEs6_4ClientInstrumentationTest.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/test/java/co/elastic/apm/agent/esrestclient/v6_4/AbstractEs6_4ClientInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.esrestclient.v6_4; import co.elastic.apm.agent.esrestclient.AbstractEsClientInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; @@ -139,10 +139,10 @@ public void testDocumentScenario() throws Exception { SearchResponse sr = doSearch(new SearchRequest(INDEX)); assertThat(sr.getHits().getAt(0).getSourceAsMap().get(FOO)).isEqualTo(BAZ); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(2); boolean updateSpanFound = false; - for (Span span : spans) { + for (SpanImpl span : spans) { if (span.getNameAsString().contains("_update")) { updateSpanFound = true; break; diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/test/java/co/elastic/apm/agent/esrestclient/v6_4/ElasticsearchRestClientInstrumentationIT_RealReporter.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/test/java/co/elastic/apm/agent/esrestclient/v6_4/ElasticsearchRestClientInstrumentationIT_RealReporter.java index 01c17eed8a..675828e842 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/test/java/co/elastic/apm/agent/esrestclient/v6_4/ElasticsearchRestClientInstrumentationIT_RealReporter.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-6_4/src/test/java/co/elastic/apm/agent/esrestclient/v6_4/ElasticsearchRestClientInstrumentationIT_RealReporter.java @@ -19,24 +19,20 @@ package co.elastic.apm.agent.esrestclient.v6_4; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; import co.elastic.apm.agent.impl.metadata.Agent; import co.elastic.apm.agent.impl.metadata.MetaDataMock; import co.elastic.apm.agent.impl.metadata.ProcessInfo; -import co.elastic.apm.agent.impl.metadata.Service; +import co.elastic.apm.agent.impl.metadata.ServiceImpl; import co.elastic.apm.agent.impl.metadata.SystemInfo; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.objectpool.ObjectPoolFactory; -import co.elastic.apm.agent.report.ApmServerClient; -import co.elastic.apm.agent.report.ApmServerReporter; -import co.elastic.apm.agent.report.IntakeV2ReportingEventHandler; -import co.elastic.apm.agent.report.Reporter; -import co.elastic.apm.agent.report.ReporterConfiguration; -import co.elastic.apm.agent.report.ReporterMonitor; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; +import co.elastic.apm.agent.objectpool.ObjectPoolFactoryImpl; +import co.elastic.apm.agent.report.*; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.report.processor.ProcessorEventHandler; import co.elastic.apm.agent.report.serialize.DslJsonSerializer; import net.bytebuddy.agent.ByteBuddyAgent; @@ -126,19 +122,19 @@ public static void startElasticsearchContainerAndClient() throws IOException { client.indices().create(new CreateIndexRequest(INDEX), RequestOptions.DEFAULT); final ConfigurationRegistry configurationRegistry = SpyConfiguration.createSpyConfig(); - ReporterConfiguration reporterConfiguration = configurationRegistry.getConfig(ReporterConfiguration.class); - CoreConfiguration coreConfiguration = configurationRegistry.getConfig(CoreConfiguration.class); + ReporterConfigurationImpl reporterConfiguration = configurationRegistry.getConfig(ReporterConfigurationImpl.class); + CoreConfigurationImpl coreConfiguration = configurationRegistry.getConfig(CoreConfigurationImpl.class); doReturn(0).when(reporterConfiguration).getMaxQueueSize(); - StacktraceConfiguration stacktraceConfiguration = configurationRegistry.getConfig(StacktraceConfiguration.class); + StacktraceConfigurationImpl stacktraceConfiguration = configurationRegistry.getConfig(StacktraceConfigurationImpl.class); doReturn(30).when(stacktraceConfiguration).getStackTraceLimit(); SystemInfo system = new SystemInfo("x64", "localhost", null, "platform"); - final Service service = new Service().withName("Eyal-ES-client-test").withAgent(new Agent("java", "Test")); + final ServiceImpl service = new ServiceImpl().withName("Eyal-ES-client-test").withAgent(new Agent("java", "Test")); final ProcessInfo title = new ProcessInfo("title"); final ProcessorEventHandler processorEventHandler = ProcessorEventHandler.loadProcessors(configurationRegistry); ApmServerClient apmServerClient = new ApmServerClient(configurationRegistry); apmServerClient.start(); DslJsonSerializer payloadSerializer = new DslJsonSerializer( - mock(StacktraceConfiguration.class), + mock(StacktraceConfigurationImpl.class), apmServerClient, MetaDataMock.create(title, service, system, null, Collections.emptyMap(), null) ); @@ -147,7 +143,7 @@ public static void startElasticsearchContainerAndClient() throws IOException { processorEventHandler, payloadSerializer, apmServerClient); - realReporter = new ApmServerReporter(true, reporterConfiguration, coreConfiguration, v2handler, ReporterMonitor.NOOP, apmServerClient, payloadSerializer, new ObjectPoolFactory()); + realReporter = new ApmServerReporter(true, reporterConfiguration, coreConfiguration, v2handler, ReporterMonitor.NOOP, apmServerClient, payloadSerializer, new ObjectPoolFactoryImpl()); realReporter.start(); tracer = new ElasticApmTracerBuilder() @@ -177,7 +173,7 @@ public void startTransaction() { @After public void endTransaction() { - Transaction currentTransaction = tracer.currentTransaction(); + TransactionImpl currentTransaction = tracer.currentTransaction(); if (currentTransaction != null) { currentTransaction.end(); } diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/pom.xml b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/pom.xml index ade41f7246..7660076c6f 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/pom.xml +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/pom.xml @@ -5,7 +5,7 @@ apm-es-restclient-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-es-restclient-plugin-7_x diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/src/test/java/co/elastic/apm/agent/esrestclient/v7_x/ElasticsearchRestClientInstrumentationIT.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/src/test/java/co/elastic/apm/agent/esrestclient/v7_x/ElasticsearchRestClientInstrumentationIT.java index cafbb85d1a..6a54a7b879 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/src/test/java/co/elastic/apm/agent/esrestclient/v7_x/ElasticsearchRestClientInstrumentationIT.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-7_x/src/test/java/co/elastic/apm/agent/esrestclient/v7_x/ElasticsearchRestClientInstrumentationIT.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.esrestclient.v7_x; import co.elastic.apm.agent.esrestclient.v6_4.AbstractEs6_4ClientInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; @@ -137,7 +137,7 @@ public void onFailure(Exception e) { // This ends the span synchronously cancellable.cancel(); - Span searchSpan = reporter.getFirstSpan(500); + SpanImpl searchSpan = reporter.getFirstSpan(500); validateSpan(searchSpan) .method("POST").pathName("/%s/_search", INDEX) .statusCode(-1) @@ -160,12 +160,12 @@ public void testRestClientAsyncContextPropagation() throws InterruptedException, return; } - AbstractSpan active = tracer.getActive(); - assertThat(active).isInstanceOf(Transaction.class); + AbstractSpanImpl active = tracer.getActive(); + assertThat(active).isInstanceOf(TransactionImpl.class); reporter.reset(); - AtomicReference> observedActive = new AtomicReference<>(); + AtomicReference> observedActive = new AtomicReference<>(); CountDownLatch endLatch = new CountDownLatch(1); RestClient restClient = clientBuilder.build(); diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-8_x/pom.xml b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-8_x/pom.xml index 178126c31e..7a4a7b46fd 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-8_x/pom.xml +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-8_x/pom.xml @@ -3,7 +3,7 @@ apm-es-restclient-plugin co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-8_x/src/test/java/co/elastic/apm/agent/esrestclient/v8_x/Elasticsearch8JavaIT.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-8_x/src/test/java/co/elastic/apm/agent/esrestclient/v8_x/Elasticsearch8JavaIT.java index 0381d5eb6a..7827ed87b3 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-8_x/src/test/java/co/elastic/apm/agent/esrestclient/v8_x/Elasticsearch8JavaIT.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-8_x/src/test/java/co/elastic/apm/agent/esrestclient/v8_x/Elasticsearch8JavaIT.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.esrestclient.v8_x; import co.elastic.apm.agent.esrestclient.AbstractEsClientInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient; import co.elastic.clients.elasticsearch.ElasticsearchClient; @@ -187,7 +187,7 @@ public void testTryToDeleteNonExistingIndex() { // todo: investigate this - no errors captured, because in this case ResponseListener#onSuccess is invoked instead of onFailure // assertThatErrorsExistWhenDeleteNonExistingIndex(); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span.getOutcome()).isEqualTo(Outcome.FAILURE); validateSpan(span) .method("DELETE") @@ -201,7 +201,7 @@ public void testTryToDeleteNonExistingIndex() { public void testDocumentScenario() throws Exception { // 1. Index a document and validate span content prepareDefaultDocumentAndIndex(); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); try { assertThat(spans).hasSize(1); validateSpan(spans.get(0)) @@ -223,7 +223,7 @@ public void testDocumentScenario() throws Exception { verifyTotalHits(response.hits()); spans = reporter.getSpans(); assertThat(spans).hasSize(1); - Span searchSpan = spans.get(0); + SpanImpl searchSpan = spans.get(0); validateSpan(searchSpan) .method("POST") @@ -248,7 +248,7 @@ public void testDocumentScenario() throws Exception { spans = reporter.getSpans(); assertThat(spans).hasSize(2); - Span updateSpan = spans.get(0); + SpanImpl updateSpan = spans.get(0); validateSpan(updateSpan) .method("POST") .endpointName("update") @@ -436,9 +436,9 @@ public void testMultisearchTemplateRequest_validateSpanContentAndDbContext() thr assertThat(items.size()).isEqualTo(1); MultiSearchItem multiSearchItem = (MultiSearchItem) items.get(0)._get(); verifyTotalHits(multiSearchItem.hits()); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(1); - Span span = spans.get(0); + SpanImpl span = spans.get(0); validateSpan(span) .method("POST") diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/pom.xml b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/pom.xml index 8de5c8078b..2778da0d9f 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/pom.xml +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/pom.xml @@ -5,7 +5,7 @@ apm-es-restclient-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-es-restclient-plugin-common diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/AbstractEsClientInstrumentationTest.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/AbstractEsClientInstrumentationTest.java index 0c967a1a44..2220df1bf9 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/AbstractEsClientInstrumentationTest.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/AbstractEsClientInstrumentationTest.java @@ -19,12 +19,12 @@ package co.elastic.apm.agent.esrestclient; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.context.Db; -import co.elastic.apm.agent.impl.context.Destination; -import co.elastic.apm.agent.impl.context.Http; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.DbImpl; +import co.elastic.apm.agent.impl.context.DestinationImpl; +import co.elastic.apm.agent.impl.context.HttpImpl; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.testutils.TestContainersUtils; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; @@ -87,25 +87,25 @@ public void startTransaction() { @After public void endTransaction() { - Transaction currentTransaction = tracer.currentTransaction(); + TransactionImpl currentTransaction = tracer.currentTransaction(); if (currentTransaction != null) { currentTransaction.deactivate().end(); } } public void assertThatErrorsExistWhenDeleteNonExistingIndex() { - List errorCaptures = reporter.getErrors(); + List errorCaptures = reporter.getErrors(); assertThat(errorCaptures).hasSize(1); - ErrorCapture errorCapture = errorCaptures.get(0); + ErrorCaptureImpl errorCapture = errorCaptures.get(0); assertThat(errorCapture.getException()).isNotNull(); } - protected EsSpanValidationBuilder validateSpan(Span spanToValidate) { + protected EsSpanValidationBuilder validateSpan(SpanImpl spanToValidate) { return new EsSpanValidationBuilder(spanToValidate, async); } protected EsSpanValidationBuilder validateSpan() { - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(1); return validateSpan(spans.get(0)); } @@ -114,7 +114,7 @@ protected static class EsSpanValidationBuilder { private static final ObjectMapper jackson = new ObjectMapper(); - private final Span span; + private final SpanImpl span; private boolean statementExpectedNonNull = false; @@ -140,7 +140,7 @@ protected static class EsSpanValidationBuilder { private boolean isAsyncRequest; - public EsSpanValidationBuilder(Span spanToValidate, boolean isAsyncRequest) { + public EsSpanValidationBuilder(SpanImpl spanToValidate, boolean isAsyncRequest) { this.span = spanToValidate; this.isAsyncRequest = isAsyncRequest; } @@ -238,7 +238,7 @@ public void check() { private void checkHttpContext() { - Http http = span.getContext().getHttp(); + HttpImpl http = span.getContext().getHttp(); assertThat(http).isNotNull(); if (expectedHttpMethod != null) { assertThat(http.getMethod()).isEqualTo(expectedHttpMethod); @@ -250,7 +250,7 @@ private void checkHttpContext() { } private void checkDbContext() { - Db db = span.getContext().getDb(); + DbImpl db = span.getContext().getDb(); assertThat(db.getType()).isEqualTo(ELASTICSEARCH); CharSequence statement = db.getStatementBuffer(); if (statementExpectedNonNull) { @@ -284,7 +284,7 @@ private void checkPathPartAttributes() { } private void checkDestinationContext() { - Destination destination = span.getContext().getDestination(); + DestinationImpl destination = span.getContext().getDestination(); assertThat(destination).isNotNull(); if (reporter.checkDestinationAddress()) { assertThat(destination.getAddress().toString()).isEqualTo(container.getContainerIpAddress()); diff --git a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelperTest.java b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelperTest.java index 5fbce1c02e..e4420f0d33 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelperTest.java +++ b/apm-agent-plugins/apm-es-restclient-plugin/apm-es-restclient-plugin-common/src/test/java/co/elastic/apm/agent/esrestclient/ElasticsearchRestClientInstrumentationHelperTest.java @@ -20,9 +20,9 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.impl.context.Db; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.DbImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.impl.transaction.TransactionTest; import co.elastic.apm.agent.testutils.assertions.SpanAssert; import org.apache.http.HttpHost; @@ -37,9 +37,7 @@ import java.util.List; import java.util.Map; -import java.util.function.Consumer; import java.util.function.Function; -import java.util.function.Supplier; import static co.elastic.apm.agent.esrestclient.ElasticsearchRestClientInstrumentationHelper.ELASTICSEARCH; import static co.elastic.apm.agent.testutils.assertions.Assertions.assertThat; @@ -52,7 +50,7 @@ class ElasticsearchRestClientInstrumentationHelperTest extends AbstractInstrumen private final ElasticsearchRestClientInstrumentationHelper helper = ElasticsearchRestClientInstrumentationHelper.get(); - private Transaction transaction; + private TransactionImpl transaction; @BeforeEach void before() { @@ -66,7 +64,7 @@ void after(){ @Test void testCreateSpan() { - Span span = (Span) helper.createClientSpan("GET", "/_test", null, true); + SpanImpl span = (SpanImpl) helper.createClientSpan("GET", "/_test", null, true); assertThat(span).isNotNull(); assertThat(tracer.getActive()).isEqualTo(span); @@ -91,7 +89,7 @@ void testCreateSpan() { @Test void testCreateSpanWithClusterName() { - Span span = (Span) helper.createClientSpan("GET", "/_test", null, true); + SpanImpl span = (SpanImpl) helper.createClientSpan("GET", "/_test", null, true); assertThat(span).isNotNull(); assertThat(tracer.getActive()).isEqualTo(span); @@ -131,7 +129,7 @@ private static Response mockResponse(Map headers) { @Test void testNonSampledSpan() { TransactionTest.setRecorded(false, transaction); - Span esSpan = (Span) helper.createClientSpan("SEARCH", "/test", null, true); + SpanImpl esSpan = (SpanImpl) helper.createClientSpan("SEARCH", "/test", null, true); assertThat(esSpan).isNotNull(); try { assertThat(esSpan.isSampled()).isFalse(); @@ -160,7 +158,7 @@ public void testCaptureBodyUrls(boolean captureEverything) throws Exception { assertThat(config.getConfig(ElasticsearchConfiguration.class).getCaptureBodyUrls()).hasSizeGreaterThan(5); } - Span span = (Span) helper.createClientSpan("GET", "/_test", + SpanImpl span = (SpanImpl) helper.createClientSpan("GET", "/_test", new ByteArrayEntity(new byte[0]), true); assertThat(span).isNotNull(); assertThat(tracer.getActive()).isEqualTo(span); @@ -175,7 +173,7 @@ public void testCaptureBodyUrls(boolean captureEverything) throws Exception { .hasType("elasticsearch") .hasNoName(); - Db db = span.getContext().getDb(); + DbImpl db = span.getContext().getDb(); Assertions.assertThat(db.getType()).isEqualTo(ELASTICSEARCH); if (captureEverything) { assertThat((CharSequence) db.getStatementBuffer()).isNotNull(); @@ -194,8 +192,8 @@ public void testSpanIsSync() { testSpanSyncAttribute(true, (span -> assertThat(span).isSync())); } - private void testSpanSyncAttribute(boolean isSync, Function checkSyncAttribute) { - Span span = (Span) helper.createClientSpan("GET", "/_test", null, isSync); + private void testSpanSyncAttribute(boolean isSync, Function checkSyncAttribute) { + SpanImpl span = (SpanImpl) helper.createClientSpan("GET", "/_test", null, isSync); assertThat(span).isNotNull(); assertThat(tracer.getActive()).isEqualTo(span); diff --git a/apm-agent-plugins/apm-es-restclient-plugin/pom.xml b/apm-agent-plugins/apm-es-restclient-plugin/pom.xml index 333aa7dc0c..09250d1596 100644 --- a/apm-agent-plugins/apm-es-restclient-plugin/pom.xml +++ b/apm-agent-plugins/apm-es-restclient-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-es-restclient-plugin diff --git a/apm-agent-plugins/apm-finagle-httpclient-plugin/pom.xml b/apm-agent-plugins/apm-finagle-httpclient-plugin/pom.xml index 9a4fa121cb..d25f5d4319 100644 --- a/apm-agent-plugins/apm-finagle-httpclient-plugin/pom.xml +++ b/apm-agent-plugins/apm-finagle-httpclient-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-finagle-httpclient-plugin @@ -15,6 +15,20 @@ ${project.basedir}/../.. + + + + + + com.fasterxml.jackson + jackson-bom + 2.13.3 + import + pom + + + + @@ -28,14 +42,6 @@ 22.7.0 provided - - - com.fasterxml.jackson.core - jackson-databind - 2.13.3 - test - - ${project.groupId} apm-httpclient-core diff --git a/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinaglePayloadSizeFilterInstrumentation.java b/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinaglePayloadSizeFilterInstrumentation.java index 657f7bb444..5f4cf92195 100644 --- a/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinaglePayloadSizeFilterInstrumentation.java +++ b/apm-agent-plugins/apm-finagle-httpclient-plugin/src/main/java/co/elastic/apm/agent/finaglehttpclient/FinaglePayloadSizeFilterInstrumentation.java @@ -23,7 +23,7 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.sdk.logging.Logger; @@ -31,7 +31,6 @@ import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import co.elastic.apm.agent.tracer.Tracer; -import co.elastic.apm.agent.tracer.dispatch.HeaderUtils; import com.twitter.finagle.http.Request; import com.twitter.finagle.http.Response; import com.twitter.finagle.tracing.Trace; @@ -128,7 +127,7 @@ public static Object onBeforeExecute(@Nullable @Advice.Argument(0) Request reque if (request == null || INBOUND_REQUEST_CLASS.isInstance(request)) { return null; } - ElasticContext parentContext = tracer.currentContext(); + TraceState parentContext = tracer.currentContext(); AbstractSpan parent = parentContext.getSpan(); Span span = null; if (parent != null) { diff --git a/apm-agent-plugins/apm-finagle-httpclient-plugin/src/test/java/co/elastic/apm/agent/finaglehttpclient/FinagleHttpClientTest.java b/apm-agent-plugins/apm-finagle-httpclient-plugin/src/test/java/co/elastic/apm/agent/finaglehttpclient/FinagleHttpClientTest.java index a30d90627c..23e4e8ab5f 100644 --- a/apm-agent-plugins/apm-finagle-httpclient-plugin/src/test/java/co/elastic/apm/agent/finaglehttpclient/FinagleHttpClientTest.java +++ b/apm-agent-plugins/apm-finagle-httpclient-plugin/src/test/java/co/elastic/apm/agent/finaglehttpclient/FinagleHttpClientTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.finaglehttpclient; import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import com.twitter.finagle.Http; import com.twitter.finagle.Service; import com.twitter.finagle.http.Request; @@ -72,7 +72,7 @@ public void getWithTls() throws Exception { service.close(); } - Span span = expectSpan("/") + SpanImpl span = expectSpan("/") .withHost("sub-host") .withStatus(0) .withHttps() @@ -80,7 +80,7 @@ public void getWithTls() throws Exception { .withoutTraceContextHeaders() .verify(); assertThat(reporter.getErrors()).hasSize(1); - ErrorCapture error = reporter.getFirstError(); + ErrorCaptureImpl error = reporter.getFirstError(); assertThat(error.getTraceContext().getTraceId()).isEqualTo(span.getTraceContext().getTraceId()); assertThat(error.getTraceContext().getParentId()).isEqualTo(span.getTraceContext().getId()); assertThat(error.getException()).hasStackTraceContaining("SSLHandshakeException"); diff --git a/apm-agent-plugins/apm-grails-plugin/pom.xml b/apm-agent-plugins/apm-grails-plugin/pom.xml index 46d9bc2c3f..4017aadf9a 100644 --- a/apm-agent-plugins/apm-grails-plugin/pom.xml +++ b/apm-agent-plugins/apm-grails-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-grails-plugin diff --git a/apm-agent-plugins/apm-grails-plugin/src/test/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentationTest.java b/apm-agent-plugins/apm-grails-plugin/src/test/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentationTest.java index 225ef4c222..90501be6f9 100644 --- a/apm-agent-plugins/apm-grails-plugin/src/test/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-grails-plugin/src/test/java/co/elastic/apm/agent/grails/GrailsTransactionNameInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.grails; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Scope; import grails.core.GrailsControllerClass; import grails.web.mapping.UrlMappingInfo; @@ -50,7 +50,7 @@ void testSetGrailsTransactionName() throws Exception { doReturn("Foo").when(controllerClass).getShortName(); final UrlMappingInfo mappingInfo = mock(UrlMappingInfo.class); doReturn("bar").when(mappingInfo).getActionName(); - final Transaction transaction = tracer.startRootTransaction(null).withName("override me"); + final TransactionImpl transaction = tracer.startRootTransaction(null).withName("override me"); try (Scope scope = transaction.activateInScope()) { handlerAdapter.handle(mock(HttpServletRequest.class), mock(HttpServletResponse.class), new GrailsControllerUrlMappingInfo(controllerClass, mappingInfo)); } catch (Exception ignore) { diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/pom.xml b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/pom.xml index 790e4eafab..f1fde89f83 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/pom.xml +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-grpc - 1.50.0 + 1.51.0 apm-grpc-plugin diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/GrpcHelper.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/GrpcHelper.java index 495a02eb2b..56ca09bb18 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/GrpcHelper.java +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/GrpcHelper.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; @@ -296,7 +296,7 @@ public void exitServerListenerMethod(@Nullable Throwable thrown, * @return client call span (activated) or {@literal null} if not within an exit span. */ @Nullable - public Span onClientCallCreationEntry(ElasticContext parent, + public Span onClientCallCreationEntry(TraceState parent, @Nullable MethodDescriptor method, @Nullable String authority) { @@ -333,7 +333,7 @@ public Span onClientCallCreationEntry(ElasticContext parent, * This is the 2nd method called during client call execution, the next is {@link #clientCallStartEnter(ClientCall, ClientCall.Listener, Metadata)}. * * @param clientCall client call - * @param spanFromEntry span created at {@link #onClientCallCreationEntry(ElasticContext, MethodDescriptor, String)} + * @param spanFromEntry span created at {@link #onClientCallCreationEntry(TraceState, MethodDescriptor, String)} */ public void onClientCallCreationExit(@Nullable ClientCall clientCall, @Nullable Span spanFromEntry) { if (clientCall != null) { diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcClientInstrumentationTest.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcClientInstrumentationTest.java index f971afeac9..b901a58a9d 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcClientInstrumentationTest.java +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcClientInstrumentationTest.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.grpc.testapp.GrpcApp; import co.elastic.apm.agent.grpc.testapp.GrpcAppProvider; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; @@ -58,7 +58,7 @@ void beforeEach() throws Exception { @AfterEach void afterEach() throws Exception { - Transaction transaction = tracer.currentTransaction(); + TransactionImpl transaction = tracer.currentTransaction(); if (transaction != null) { transaction.deactivate() @@ -77,16 +77,16 @@ public void simpleCall() { endRootTransaction(); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction).isNotNull(); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); checkSpan(span); assertThat(span.getOutcome()).isEqualTo(Outcome.SUCCESS); } - private void checkSpan(Span span) { + private void checkSpan(SpanImpl span) { assertThat(span.getType()).isEqualTo("external"); assertThat(span.getSubtype()).isEqualTo("grpc"); assertThat(span.getNameAsString()).isEqualTo("helloworld.Hello/SayHello"); @@ -136,7 +136,7 @@ public void cancelClientCall() throws Exception { assertThat(msg.cancel(true)).isTrue(); - Span span = reporter.getFirstSpan(200); + SpanImpl span = reporter.getFirstSpan(200); // we should have a span created and properly terminated, even if the server // thread is still waiting for proper termination. @@ -224,7 +224,7 @@ void clientCallAndListenerExceptionCheck(String method) { // even if there is an exception thrown, we should still have a span created. - Span span = getFirstSpan(); + SpanImpl span = getFirstSpan(); checkSpan(span); Outcome outcome = span.getOutcome(); @@ -239,7 +239,7 @@ void clientCallAndListenerExceptionCheck(String method) { } protected void endRootTransaction() { - Transaction transaction = tracer.currentTransaction(); + TransactionImpl transaction = tracer.currentTransaction(); assertThat(transaction).isNotNull(); transaction @@ -252,7 +252,7 @@ private boolean isVersion161() { return getClass().getPackageName().contains(".v1_6_1"); } - private static Span getFirstSpan() { + private static SpanImpl getFirstSpan() { return reporter.getFirstSpan(1000); } diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcContextHeadersTest.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcContextHeadersTest.java index 5199640189..ea852d2eee 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcContextHeadersTest.java +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcContextHeadersTest.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.grpc.testapp.GrpcApp; import co.elastic.apm.agent.grpc.testapp.GrpcAppProvider; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -61,7 +61,7 @@ void simpleClientContextPropagation() { // transaction 1 (root transaction) will do the gRPC call and create a span // transaction 2 will handle the gRPC call and create a transaction - Transaction transaction1 = createRootTransaction(); + TransactionImpl transaction1 = createRootTransaction(); try { assertThat(app.sayHello("oscar", 0)).isEqualTo("hello(oscar)"); @@ -76,20 +76,20 @@ void simpleClientContextPropagation() { .hasSize(2); }); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions).hasSize(2); assertThat(transactions).contains(transaction1); - Transaction transaction2 = transactions.stream() + TransactionImpl transaction2 = transactions.stream() .filter((t) -> !t.equals(transaction1)) .findFirst() .orElseThrow(() -> null); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(1); - Span span = spans.get(0); + SpanImpl span = spans.get(0); assertThat(transaction2.isChildOf(span)) .describedAs("server transaction parent %s should be client span %s", @@ -99,14 +99,14 @@ void simpleClientContextPropagation() { } - private static Transaction createRootTransaction() { + private static TransactionImpl createRootTransaction() { return tracer.startRootTransaction(AbstractGrpcClientInstrumentationTest.class.getClassLoader()) .withName("root") .withType("test") .activate(); } - private static void endRootTransaction(Transaction transaction) { + private static void endRootTransaction(TransactionImpl transaction) { transaction .withOutcome(Outcome.SUCCESS) .deactivate() diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcServerInstrumentationTest.java b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcServerInstrumentationTest.java index 084bb8675d..b1cf402511 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcServerInstrumentationTest.java +++ b/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/test/java/co/elastic/apm/agent/grpc/AbstractGrpcServerInstrumentationTest.java @@ -21,8 +21,8 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.grpc.testapp.GrpcApp; import co.elastic.apm.agent.grpc.testapp.GrpcAppProvider; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Transaction; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -69,7 +69,7 @@ void nestedCallShouldProduceTwoTransactions() { reporter.awaitTransactionCount(2); - for (Transaction transaction : reporter.getTransactions()) { + for (TransactionImpl transaction : reporter.getTransactions()) { checkUnaryTransactionSuccess(transaction); } } @@ -95,7 +95,7 @@ void asyncClientCallShouldWorkLikeRegularCall() throws Exception { String msg = app.sayHelloAsync("bob", 0).get(); assertThat(msg).isEqualTo("hello(bob)"); - Transaction transaction = getFirstTransaction(); + TransactionImpl transaction = getFirstTransaction(); checkUnaryTransactionSuccess(transaction); } @@ -103,7 +103,7 @@ private void simpleCallWithError(@Nullable String name, String expectedResult, O assertThat(app.sayHello(name, 0)) .isNull(); - Transaction transaction = getFirstTransaction(); + TransactionImpl transaction = getFirstTransaction(); checkUnaryTransaction(transaction, expectedResult, expectedOutcome); } @@ -187,11 +187,11 @@ void noNestedTransactionsForSingleCall() { reporter.awaitTransactionCount(1); } - private static void checkUnaryTransactionSuccess(Transaction transaction) { + private static void checkUnaryTransactionSuccess(TransactionImpl transaction) { checkUnaryTransaction(transaction, "OK", Outcome.SUCCESS); } - private static void checkUnaryTransaction(Transaction transaction, String expectedResult, Outcome expectedOutcome) { + private static void checkUnaryTransaction(TransactionImpl transaction, String expectedResult, Outcome expectedOutcome) { assertThat(transaction).isNotNull(); assertThat(transaction.getNameAsString()).isEqualTo("helloworld.Hello/SayHello"); assertThat(transaction.getType()).isEqualTo("request"); @@ -204,7 +204,7 @@ private static void checkNoTransaction() { getReporter().assertNoTransaction(100); } - private static Transaction getFirstTransaction() { + private static TransactionImpl getFirstTransaction() { return getReporter().getFirstTransaction(1000); } diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-test-1.6.1/pom.xml b/apm-agent-plugins/apm-grpc/apm-grpc-test-1.6.1/pom.xml index 9018dbc8e7..1655b678aa 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-test-1.6.1/pom.xml +++ b/apm-agent-plugins/apm-grpc/apm-grpc-test-1.6.1/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-grpc - 1.50.0 + 1.51.0 apm-grpc-test-1.6.1 diff --git a/apm-agent-plugins/apm-grpc/apm-grpc-test-latest/pom.xml b/apm-agent-plugins/apm-grpc/apm-grpc-test-latest/pom.xml index d6ee0f1b80..a5bb1f5e22 100644 --- a/apm-agent-plugins/apm-grpc/apm-grpc-test-latest/pom.xml +++ b/apm-agent-plugins/apm-grpc/apm-grpc-test-latest/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-grpc - 1.50.0 + 1.51.0 apm-grpc-test-latest diff --git a/apm-agent-plugins/apm-grpc/pom.xml b/apm-agent-plugins/apm-grpc/pom.xml index 67dd335530..6d38a3cc0e 100644 --- a/apm-agent-plugins/apm-grpc/pom.xml +++ b/apm-agent-plugins/apm-grpc/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-agent-plugins - 1.50.0 + 1.51.0 apm-grpc diff --git a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/pom.xml b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/pom.xml index 559d38ae0e..ef65db9947 100644 --- a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/pom.xml +++ b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-5_x/pom.xml @@ -5,7 +5,7 @@ apm-hibernate-search-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-hibernate-search-plugin-5_x diff --git a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/pom.xml b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/pom.xml index 673270d267..7bc19091d6 100644 --- a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/pom.xml +++ b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-6_x/pom.xml @@ -5,7 +5,7 @@ apm-hibernate-search-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-hibernate-search-plugin-6_x diff --git a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/pom.xml b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/pom.xml index 90b6bbf80c..1a47414528 100644 --- a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/pom.xml +++ b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/pom.xml @@ -5,7 +5,7 @@ apm-hibernate-search-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-hibernate-search-plugin-common diff --git a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchHelper.java b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchHelper.java index e92d3bcae4..f93ac3d294 100644 --- a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchHelper.java +++ b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/main/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchHelper.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.hibernatesearch; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.Tracer; @@ -32,7 +32,7 @@ private HibernateSearchHelper() { public static Span createAndActivateSpan(final Tracer tracer, final String methodName, final String query) { - ElasticContext active = tracer.currentContext(); + TraceState active = tracer.currentContext(); AbstractSpan activeSpan = active.getSpan(); // avoid creating the same span twice for example, when an instrumented API is wrapped if (activeSpan == null || activeSpan instanceof Span && HibernateSearchConstants.HIBERNATE_SEARCH_ORM_TYPE diff --git a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/test/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchAssertionHelper.java b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/test/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchAssertionHelper.java index 16e4a6af75..f9d81da6da 100644 --- a/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/test/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchAssertionHelper.java +++ b/apm-agent-plugins/apm-hibernate-search-plugin/apm-hibernate-search-plugin-common/src/test/java/co/elastic/apm/agent/hibernatesearch/HibernateSearchAssertionHelper.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.hibernatesearch; import co.elastic.apm.agent.MockReporter; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import static co.elastic.apm.agent.testutils.assertions.Assertions.assertThat; @@ -31,7 +31,7 @@ private HibernateSearchAssertionHelper() { public static void assertApmSpanInformation(final MockReporter reporter, final String expectedQuery, final String searchMethod) { assertThat(reporter.getSpans().size()).isEqualTo(1); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span) .hasType(HibernateSearchConstants.HIBERNATE_SEARCH_ORM_SPAN_TYPE) .hasSubType(HibernateSearchConstants.HIBERNATE_SEARCH_ORM_TYPE) diff --git a/apm-agent-plugins/apm-hibernate-search-plugin/pom.xml b/apm-agent-plugins/apm-hibernate-search-plugin/pom.xml index 435793ea7a..757f11b5f7 100644 --- a/apm-agent-plugins/apm-hibernate-search-plugin/pom.xml +++ b/apm-agent-plugins/apm-hibernate-search-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-hibernate-search-plugin diff --git a/apm-agent-plugins/apm-httpclient-core/pom.xml b/apm-agent-plugins/apm-httpclient-core/pom.xml index 96b8ee5235..eaf24bebbb 100644 --- a/apm-agent-plugins/apm-httpclient-core/pom.xml +++ b/apm-agent-plugins/apm-httpclient-core/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-httpclient-core diff --git a/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/HttpClientHelper.java b/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/HttpClientHelper.java index 36923f4845..61bb7e7e66 100644 --- a/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/HttpClientHelper.java +++ b/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/HttpClientHelper.java @@ -18,23 +18,33 @@ */ package co.elastic.apm.agent.httpclient; +import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.AbstractSpan; +import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Span; +import co.elastic.apm.agent.tracer.TraceState; +import co.elastic.apm.agent.tracer.configuration.WebConfiguration; +import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; import javax.annotation.Nullable; import java.net.URI; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class HttpClientHelper { + private static final Pattern CHARSET_EXTRACTOR = Pattern.compile(";\\s*charset\\s*=\\s*((\"[^\"]+)|([^;\\s]+))"); + private static final Logger logger = LoggerFactory.getLogger(HttpClientHelper.class); public static final String EXTERNAL_TYPE = "external"; public static final String HTTP_SUBTYPE = "http"; @Nullable - public static Span startHttpClientSpan(ElasticContext activeContext, String method, @Nullable URI uri, @Nullable CharSequence hostName) { + public static Span startHttpClientSpan(TraceState activeContext, String method, @Nullable URI uri, @Nullable CharSequence hostName) { String uriString = null; String scheme = null; int port = -1; @@ -50,10 +60,13 @@ public static Span startHttpClientSpan(ElasticContext activeContext, Strin } @Nullable - public static Span startHttpClientSpan(ElasticContext activeContext, String method, @Nullable String uri, + public static Span startHttpClientSpan(TraceState activeContext, String method, @Nullable String uri, @Nullable String scheme, @Nullable CharSequence hostName, int port) { Span span = activeContext.createExitSpan(); if (span != null) { + if (span.isSampled()) { + span.getContext().getHttp().getRequestBody().markEligibleForCapturing(); + } updateHttpSpanNameAndContext(span, method, uri, scheme, hostName, port); } if (logger.isTraceEnabled()) { @@ -62,6 +75,42 @@ public static Span startHttpClientSpan(ElasticContext activeContext, Strin return span; } + public static boolean startRequestBodyCapture(@Nullable AbstractSpan abstractSpan, R request, TextHeaderGetter headerGetter) { + if (!(abstractSpan instanceof Span)) { + return false; + } + Span span = (Span) abstractSpan; + if (!span.getContext().getHttp().getRequestBody().isEligibleForCapturing()) { + return false; + } + WebConfiguration webConfig = GlobalTracer.get().getConfig(WebConfiguration.class); + int byteCount = webConfig.getCaptureClientRequestBytes(); + if (byteCount == 0) { + return false; + } + List contentTypes = webConfig.getCaptureContentTypes(); + String contentTypeHeader = headerGetter.getFirstHeader("Content-Type", request); + if (contentTypeHeader == null) { + contentTypeHeader = ""; + } + if (WildcardMatcher.anyMatch(contentTypes, contentTypeHeader) == null) { + return false; + } + String charset = extractCharsetFromContentType(contentTypeHeader); + return span.getContext().getHttp().getRequestBody().startCapture(charset, byteCount); + } + + //Visible for testing + @Nullable + static String extractCharsetFromContentType(String contentTypeHeader) { + Matcher matcher = CHARSET_EXTRACTOR.matcher(contentTypeHeader); + if (matcher.find()) { + String potentiallyQuotedCharset = matcher.group(1); + return potentiallyQuotedCharset.replace("\"", ""); + } + return null; + } + public static void updateHttpSpanNameAndContext(Span span, String method, @Nullable String uri, String scheme, CharSequence hostName, int port) { span.withType(EXTERNAL_TYPE) .withSubtype(HTTP_SUBTYPE) diff --git a/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/RequestBodyRecordingInputStream.java b/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/RequestBodyRecordingInputStream.java new file mode 100644 index 0000000000..f8e228eaf8 --- /dev/null +++ b/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/RequestBodyRecordingInputStream.java @@ -0,0 +1,104 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.httpclient; + +import co.elastic.apm.agent.tracer.Span; +import co.elastic.apm.agent.tracer.metadata.BodyCapture; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.io.InputStream; + +public class RequestBodyRecordingInputStream extends InputStream { + + private final InputStream delegate; + + @Nullable + private Span clientSpan; + + public RequestBodyRecordingInputStream(InputStream delegate, Span clientSpan) { + this.delegate = delegate; + clientSpan.incrementReferences(); + this.clientSpan = clientSpan; + } + + + protected void appendToBody(byte b) { + if (clientSpan != null) { + BodyCapture requestBody = clientSpan.getContext().getHttp().getRequestBody(); + requestBody.append(b); + if (requestBody.isFull()) { + releaseSpan(); + } + } + } + + protected void appendToBody(byte[] b, int off, int len) { + if (clientSpan != null) { + BodyCapture requestBody = clientSpan.getContext().getHttp().getRequestBody(); + requestBody.append(b, off, len); + if (requestBody.isFull()) { + releaseSpan(); + } + } + } + + public void releaseSpan() { + if (clientSpan != null) { + clientSpan.decrementReferences(); + clientSpan = null; + } + } + + @Override + public int read() throws IOException { + int character = delegate.read(); + if (character == -1) { + releaseSpan(); + } else { + appendToBody((byte) character); + } + return character; + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + int readBytes = delegate.read(b, off, len); + if (readBytes == -1) { + releaseSpan(); + } else { + appendToBody(b, off, readBytes); + } + return readBytes; + } + + @Override + public int available() throws IOException { + return delegate.available(); + } + + @Override + public void close() throws IOException { + try { + releaseSpan(); + } finally { + delegate.close(); + } + } +} diff --git a/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/RequestBodyRecordingOutputStream.java b/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/RequestBodyRecordingOutputStream.java new file mode 100644 index 0000000000..aaf640c1d3 --- /dev/null +++ b/apm-agent-plugins/apm-httpclient-core/src/main/java/co/elastic/apm/agent/httpclient/RequestBodyRecordingOutputStream.java @@ -0,0 +1,108 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.httpclient; + +import co.elastic.apm.agent.tracer.Span; +import co.elastic.apm.agent.tracer.metadata.BodyCapture; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.io.OutputStream; + +public class RequestBodyRecordingOutputStream extends OutputStream { + + private final OutputStream delegate; + + @Nullable + private Span clientSpan; + + public RequestBodyRecordingOutputStream(OutputStream delegate, Span clientSpan) { + this.delegate = delegate; + clientSpan.incrementReferences(); + this.clientSpan = clientSpan; + } + + @Override + public void write(int b) throws IOException { + try { + appendToBody((byte) b); + } finally { + delegate.write(b); + } + } + + protected void appendToBody(byte b) { + if (clientSpan != null) { + BodyCapture body = clientSpan.getContext().getHttp().getRequestBody(); + body.append(b); + if (body.isFull()) { + releaseSpan(); + } + } + } + + @Override + public void write(byte[] b) throws IOException { + try { + appendToBody(b, 0, b.length); + } finally { + delegate.write(b); + } + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + try { + appendToBody(b, off, len); + } finally { + delegate.write(b, off, len); + } + } + + protected void appendToBody(byte[] b, int off, int len) { + if (clientSpan != null) { + BodyCapture body = clientSpan.getContext().getHttp().getRequestBody(); + body.append(b, off, len); + if (body.isFull()) { + releaseSpan(); + } + } + } + + public void releaseSpan() { + if (clientSpan != null) { + clientSpan.decrementReferences(); + clientSpan = null; + } + } + + @Override + public void close() throws IOException { + try { + releaseSpan(); + } finally { + delegate.close(); + } + } + + @Override + public void flush() throws IOException { + delegate.flush(); + } +} diff --git a/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/AbstractHttpClientInstrumentationTest.java b/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/AbstractHttpClientInstrumentationTest.java index 8bfcd27ecc..788757662f 100644 --- a/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/AbstractHttpClientInstrumentationTest.java +++ b/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/AbstractHttpClientInstrumentationTest.java @@ -19,19 +19,20 @@ package co.elastic.apm.agent.httpclient; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.TextHeaderMapAccessor; -import co.elastic.apm.agent.impl.context.Destination; -import co.elastic.apm.agent.impl.context.Http; -import co.elastic.apm.agent.tracer.util.ResultUtil; -import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.impl.context.BodyCaptureImpl; +import co.elastic.apm.agent.impl.context.DestinationImpl; +import co.elastic.apm.agent.impl.context.HttpImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Scope; +import co.elastic.apm.agent.tracer.TraceState; +import co.elastic.apm.agent.tracer.configuration.WebConfiguration; import co.elastic.apm.agent.tracer.dispatch.TextHeaderGetter; +import co.elastic.apm.agent.tracer.util.ResultUtil; import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.http.HttpHeader; @@ -46,6 +47,8 @@ import org.junit.Test; import javax.annotation.Nullable; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -53,8 +56,9 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; -import static co.elastic.apm.agent.impl.transaction.TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME; +import static co.elastic.apm.agent.impl.transaction.TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME; import static co.elastic.apm.agent.testutils.assertions.Assertions.assertThat; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.any; @@ -70,7 +74,7 @@ public abstract class AbstractHttpClientInstrumentationTest extends AbstractInst @Rule public WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.wireMockConfig().dynamicPort().dynamicHttpsPort(), false); - private ElasticContext emptyContext; + private TraceState emptyContext; @Before public final void setUpWiremock() { @@ -99,7 +103,7 @@ protected ResponseDefinitionBuilder dummyResponse() { @After public final void after() { - Transaction transaction = tracer.currentTransaction(); + TransactionImpl transaction = tracer.currentTransaction(); assertThat(transaction).isNotNull(); transaction.deactivate().end(); assertThat(reporter.getTransactions()).hasSize(1); @@ -115,9 +119,32 @@ public void testHttpCall() { expectSpan(path).verify(); } + @Test + public void testPostBodyCapture() throws Exception { + if (!isBodyCapturingSupported()) { + return; + } + doReturn(5).when(config.getConfig(WebConfiguration.class)).getCaptureClientRequestBytes(); + byte[] content = "Hello World!".getBytes(StandardCharsets.UTF_8); + String path = "/"; + performPost(getBaseUrl() + path, content, "text/plain; charset=utf-8"); + expectSpan(path) + .withRequestBodySatisfying(body -> { + ByteBuffer buffer = body.getBody(); + assertThat(buffer).isNotNull(); + int numBytes = buffer.position(); + buffer.position(0); + byte[] contentBytes = new byte[numBytes]; + buffer.get(contentBytes); + assertThat(contentBytes).isEqualTo("Hello".getBytes(StandardCharsets.UTF_8)); + assertThat(Objects.toString(body.getCharset())).isEqualTo("utf-8"); + }) + .verify(); + } + @Test public void testDisabledOutgoingHeaders() { - doReturn(true).when(config.getConfig(CoreConfiguration.class)).isOutgoingTraceContextHeadersInjectionDisabled(); + doReturn(true).when(config.getConfig(CoreConfigurationImpl.class)).isOutgoingTraceContextHeadersInjectionDisabled(); String path = "/"; performGetWithinTransaction(path); expectSpan(path).withoutTraceContextHeaders().verify(); @@ -126,7 +153,7 @@ public void testDisabledOutgoingHeaders() { @Test public void testContextPropagationFromExitParent() { String path = "/"; - Span exitSpan = Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(tracer.currentTransaction()).createExitSpan())); + SpanImpl exitSpan = Objects.requireNonNull(Objects.requireNonNull(Objects.requireNonNull(tracer.currentTransaction()).createExitSpan())); try { exitSpan.withType("custom").withSubtype("exit"); exitSpan.getContext().getDestination().withAddress("test-host").withPort(6000); @@ -142,7 +169,7 @@ public void testContextPropagationFromExitParent() { @Test public void testBaggagePropagatedWithoutTrace() { - ElasticContext baggageOnly = emptyContext.withUpdatedBaggage() + TraceState baggageOnly = emptyContext.withUpdatedBaggage() .put("foo", "bar") .buildContext(); try (Scope scope = baggageOnly.activateInScope()) { @@ -211,7 +238,7 @@ public void testHttpCallRedirect() { String path = "/redirect"; performGetWithinTransaction(path); - Span span = expectSpan(path).verify(); + SpanImpl span = expectSpan(path).verify(); verifyTraceContextHeaders(span, "/redirect"); verifyTraceContextHeaders(span, "/"); @@ -224,7 +251,7 @@ public void testHttpCallCircularRedirect() { String path = "/circular-redirect"; performGetWithinTransaction(path); - Span span = reporter.getFirstSpan(500); + SpanImpl span = reporter.getFirstSpan(500); assertThat(span).isNotNull(); assertThat(reporter.getSpans()).hasSize(1); @@ -248,6 +275,11 @@ protected boolean isRedirectFollowingSupported() { return true; } + // assumption + protected boolean isBodyCapturingSupported() { + return false; + } + // assumption protected boolean isErrorOnCircularRedirectSupported() { return isRedirectFollowingSupported(); @@ -281,6 +313,10 @@ public boolean isAsync() { protected abstract void performGet(String path) throws Exception; + protected void performPost(String path, byte[] content, String contentTypeHeader) throws Exception { + throw new UnsupportedOperationException(); + } + protected VerifyBuilder expectSpan(String path) { return new VerifyBuilder(path); } @@ -293,6 +329,8 @@ protected class VerifyBuilder { private boolean traceContextHeaders = true; private boolean requestExecuted = true; + private Consumer requestBodyVerification = null; + private VerifyBuilder(String path) { this.path = path; } @@ -324,17 +362,22 @@ public VerifyBuilder withoutRequestExecuted() { return this; } - public Span verify() { + public VerifyBuilder withRequestBodySatisfying(Consumer requestBodyVerification) { + this.requestBodyVerification = requestBodyVerification; + return this; + } + + public SpanImpl verify() { assertThat(reporter.getFirstSpan(500)).isNotNull(); assertThat(reporter.getSpans()).hasSize(1); - Span span = reporter.getSpans().get(0); + SpanImpl span = reporter.getSpans().get(0); int port = https ? wireMockRule.httpsPort() : wireMockRule.port(); String schema = https ? "https" : "http"; String baseUrl = String.format("%s://%s:%d", schema, host, port); - Http httpContext = span.getContext().getHttp(); + HttpImpl httpContext = span.getContext().getHttp(); assertThat(span) .hasName(String.format("%s %s", httpContext.getMethod(), host)) @@ -352,11 +395,16 @@ public Span verify() { assertThat(span).hasOutcome(Outcome.FAILURE); } + BodyCaptureImpl reqBody = span.getContext().getHttp().getRequestBody(); + if (requestBodyVerification != null) { + requestBodyVerification.accept(reqBody); + } + if (isAsync()) { assertThat(span).isAsync(); } - Destination destination = span.getContext().getDestination(); + DestinationImpl destination = span.getContext().getDestination(); int addressStartIndex = (host.startsWith("[")) ? 1 : 0; int addressEndIndex = (host.endsWith("]")) ? host.length() - 1 : host.length(); assertThat(destination.getAddress().toString()).isEqualTo(host.substring(addressStartIndex, addressEndIndex)); @@ -372,7 +420,7 @@ public Span verify() { verifyTraceContextHeaders(span, path); } else { findLoggedRequests(path).forEach(request -> - assertThat(TraceContext.containsTraceContextTextHeaders(request, HeaderAccessor.INSTANCE)).isFalse() + assertThat(TraceContextImpl.containsTraceContextTextHeaders(request, HeaderAccessor.INSTANCE)).isFalse() ); } } @@ -381,13 +429,13 @@ public Span verify() { } } - private void verifyTraceContextHeaders(Span span, String path) { + private void verifyTraceContextHeaders(SpanImpl span, String path) { Map headerMap = new HashMap<>(); span.propagateContext(headerMap, TextHeaderMapAccessor.INSTANCE, TextHeaderMapAccessor.INSTANCE); assertThat(headerMap).isNotEmpty(); final List loggedRequests = findLoggedRequests(path); loggedRequests.forEach(request -> { - assertThat(TraceContext.containsTraceContextTextHeaders(request, HeaderAccessor.INSTANCE)).isTrue(); + assertThat(TraceContextImpl.containsTraceContextTextHeaders(request, HeaderAccessor.INSTANCE)).isTrue(); AtomicInteger headerCount = new AtomicInteger(); HeaderAccessor.INSTANCE.forEach( W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, @@ -397,7 +445,7 @@ private void verifyTraceContextHeaders(Span span, String path) { ); assertThat(headerCount.get()).isEqualTo(1); headerMap.forEach((key, value) -> assertThat(request.getHeader(key)).isEqualTo(value)); - Transaction transaction = tracer.startChildTransaction(request, new HeaderAccessor(), AbstractHttpClientInstrumentationTest.class.getClassLoader()); + TransactionImpl transaction = tracer.startChildTransaction(request, new HeaderAccessor(), AbstractHttpClientInstrumentationTest.class.getClassLoader()); assertThat(transaction).isNotNull(); assertThat(transaction.getTraceContext().getTraceId()).isEqualTo(span.getTraceContext().getTraceId()); assertThat(transaction.getTraceContext().getParentId()).isEqualTo(span.getTraceContext().getId()); diff --git a/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/HttpClientHelperTest.java b/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/HttpClientHelperTest.java index 6b68b08ab7..9242d167ed 100644 --- a/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/HttpClientHelperTest.java +++ b/apm-agent-plugins/apm-httpclient-core/src/test/java/co/elastic/apm/agent/httpclient/HttpClientHelperTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.httpclient; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.context.Destination; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.context.DestinationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -47,9 +47,9 @@ void afterTest() { void testNonDefaultPort() throws URISyntaxException { createSpanWithUrl("http://user:pass@testing.local:1234/path?query"); assertThat(reporter.getSpans()).hasSize(1); - Span httpSpan = reporter.getFirstSpan(); + SpanImpl httpSpan = reporter.getFirstSpan(); assertThat(httpSpan.getContext().getHttp().getUrl().toString()).isEqualTo("http://testing.local:1234/path?query"); - Destination destination = httpSpan.getContext().getDestination(); + DestinationImpl destination = httpSpan.getContext().getDestination(); assertThat(httpSpan.getContext().getServiceTarget()) .hasType("http") .hasName("testing.local:1234") @@ -63,9 +63,9 @@ void testNonDefaultPort() throws URISyntaxException { void testDefaultExplicitPort() throws URISyntaxException { createSpanWithUrl("https://www.elastic.co:443/products/apm"); assertThat(reporter.getSpans()).hasSize(1); - Span httpSpan = reporter.getFirstSpan(); + SpanImpl httpSpan = reporter.getFirstSpan(); assertThat(httpSpan.getContext().getHttp().getUrl().toString()).isEqualTo("https://www.elastic.co:443/products/apm"); - Destination destination = httpSpan.getContext().getDestination(); + DestinationImpl destination = httpSpan.getContext().getDestination(); assertThat(httpSpan.getContext().getServiceTarget()) .hasType("http") .hasName("www.elastic.co:443") @@ -78,13 +78,13 @@ void testDefaultExplicitPort() throws URISyntaxException { void testDefaultImplicitPort() throws URISyntaxException { createSpanWithUrl("https://www.elastic.co/products/apm"); assertThat(reporter.getSpans()).hasSize(1); - Span httpSpan = reporter.getFirstSpan(); + SpanImpl httpSpan = reporter.getFirstSpan(); assertThat(httpSpan.getContext().getHttp().getUrl().toString()).isEqualTo("https://www.elastic.co/products/apm"); assertThat(httpSpan.getContext().getServiceTarget()) .hasType("http") .hasName("www.elastic.co:443") .hasNameOnlyDestinationResource(); - Destination destination = httpSpan.getContext().getDestination(); + DestinationImpl destination = httpSpan.getContext().getDestination(); assertThat(destination.getAddress().toString()).isEqualTo("www.elastic.co"); assertThat(destination.getPort()).isEqualTo(443); } @@ -93,13 +93,13 @@ void testDefaultImplicitPort() throws URISyntaxException { void testDefaultImplicitPortWithIpv4() throws URISyntaxException { createSpanWithUrl("https://151.101.114.217/index.html"); assertThat(reporter.getSpans()).hasSize(1); - Span httpSpan = reporter.getFirstSpan(); + SpanImpl httpSpan = reporter.getFirstSpan(); assertThat(httpSpan.getContext().getHttp().getUrl().toString()).isEqualTo("https://151.101.114.217/index.html"); assertThat(httpSpan.getContext().getServiceTarget()) .hasType("http") .hasName("151.101.114.217:443") .hasNameOnlyDestinationResource(); - Destination destination = httpSpan.getContext().getDestination(); + DestinationImpl destination = httpSpan.getContext().getDestination(); assertThat(destination.getAddress().toString()).isEqualTo("151.101.114.217"); assertThat(destination.getPort()).isEqualTo(443); } @@ -108,9 +108,9 @@ void testDefaultImplicitPortWithIpv4() throws URISyntaxException { void testDefaultImplicitPortWithIpv6() throws URISyntaxException { createSpanWithUrl("http://[2001:db8:a0b:12f0::1]/index.html"); assertThat(reporter.getSpans()).hasSize(1); - Span httpSpan = reporter.getFirstSpan(); + SpanImpl httpSpan = reporter.getFirstSpan(); assertThat(httpSpan.getContext().getHttp().getUrl().toString()).isEqualTo("http://[2001:db8:a0b:12f0::1]/index.html"); - Destination destination = httpSpan.getContext().getDestination(); + DestinationImpl destination = httpSpan.getContext().getDestination(); assertThat(destination.getAddress().toString()).isEqualTo("2001:db8:a0b:12f0::1"); assertThat(destination.getPort()).isEqualTo(80); assertThat(httpSpan.getContext().getServiceTarget()) @@ -123,4 +123,17 @@ private void createSpanWithUrl(String s) throws URISyntaxException { HttpClientHelper.startHttpClientSpan(tracer.getActive(), "GET", new URI(s), null) .end(); } + + @Test + void testContentTypeCharsetExtraction() { + assertThat(HttpClientHelper.extractCharsetFromContentType("multipart/form-data; boundary=---------------------------974767299852498929531610575")) + .isNull(); + assertThat(HttpClientHelper.extractCharsetFromContentType("Content-Type: text/html; charset=utf-8")) + .isEqualTo("utf-8"); + assertThat(HttpClientHelper.extractCharsetFromContentType("Content-Type: text/html; charset = foobar;baz")) + .isEqualTo("foobar"); + assertThat(HttpClientHelper.extractCharsetFromContentType("Content-Type: application/json; charset = \"foo bar\";baz")) + .isEqualTo("foo bar"); + + } } diff --git a/apm-agent-plugins/apm-httpserver-core/pom.xml b/apm-agent-plugins/apm-httpserver-core/pom.xml index 906a5c879b..163510ffa3 100644 --- a/apm-agent-plugins/apm-httpserver-core/pom.xml +++ b/apm-agent-plugins/apm-httpserver-core/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-httpserver-core diff --git a/apm-agent-plugins/apm-jakarta-websocket-plugin/pom.xml b/apm-agent-plugins/apm-jakarta-websocket-plugin/pom.xml index fe9af6c323..fc0f37632e 100644 --- a/apm-agent-plugins/apm-jakarta-websocket-plugin/pom.xml +++ b/apm-agent-plugins/apm-jakarta-websocket-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-jakarta-websocket-plugin diff --git a/apm-agent-plugins/apm-jakarta-websocket-plugin/src/test/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentationTest.java b/apm-agent-plugins/apm-jakarta-websocket-plugin/src/test/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentationTest.java index d8f5df8dc8..2d8b68eb7d 100644 --- a/apm-agent-plugins/apm-jakarta-websocket-plugin/src/test/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentationTest.java +++ b/apm-agent-plugins/apm-jakarta-websocket-plugin/src/test/java/co/elastic/apm/agent/websocket/BaseServerEndpointInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.websocket; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.websocket.endpoint.WebSocketEndpoint; import org.junit.jupiter.api.Test; @@ -35,7 +35,7 @@ protected BaseServerEndpointInstrumentationTest(WebSocketEndpoint serverEndpoint @Test void testOnOpenWithActiveTransaction() { - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try { serverEndpoint.onOpen(); } finally { @@ -54,7 +54,7 @@ void testOnOpenWithoutActiveTransaction() { @Test void testOnMessage() { - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try { serverEndpoint.onMessage(""); } finally { @@ -66,7 +66,7 @@ void testOnMessage() { @Test void testOnError() { - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try { serverEndpoint.onError(); } finally { @@ -78,7 +78,7 @@ void testOnError() { @Test void testOnClose() { - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try { serverEndpoint.onClose(); } finally { @@ -95,7 +95,7 @@ void testOnClose() { protected abstract String getFrameworkVersion(); private void assertReportedTransactionNameAndFramework(String methodName) { - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getNameAsString()).isEqualTo(getWebSocketServerEndpointClassName() + '#' + methodName); assertThat(transaction.getFrameworkName()).isEqualTo(getFrameworkName()); diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/pom.xml b/apm-agent-plugins/apm-java-concurrent-plugin/pom.xml index bf763e0358..69f19dcb5d 100644 --- a/apm-agent-plugins/apm-java-concurrent-plugin/pom.xml +++ b/apm-agent-plugins/apm-java-concurrent-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-java-concurrent-plugin diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/JavaConcurrent.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/JavaConcurrent.java index 3f06f75079..555ff1b425 100644 --- a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/JavaConcurrent.java +++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/JavaConcurrent.java @@ -23,7 +23,7 @@ import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.sdk.state.GlobalState; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; @@ -43,7 +43,7 @@ @GlobalState public class JavaConcurrent { - private static final ReferenceCountedMap> contextMap = GlobalTracer.get().newReferenceCountedMap(); + private static final ReferenceCountedMap> contextMap = GlobalTracer.get().newReferenceCountedMap(); private static final List> RUNNABLE_CALLABLE_FJTASK_INSTRUMENTATION = Collections. >singletonList(RunnableCallableForkJoinTaskInstrumentation.class); @@ -83,12 +83,12 @@ private static boolean shouldAvoidContextPropagation(@Nullable Object executable * is already the active one on the current thread. */ @Nullable - public static ElasticContext restoreContext(Object o, Tracer tracer) { + public static TraceState restoreContext(Object o, Tracer tracer) { // When an Executor executes directly on the current thread we need to enable this thread for context propagation again needsContext.set(Boolean.TRUE); // we cannot remove yet, as this decrements the reference count, which may cause already ended spans to be recycled ahead of time - ElasticContext context = contextMap.get(o); + TraceState context = contextMap.get(o); if (context == null) { return null; } @@ -113,7 +113,7 @@ public static Runnable withContext(@Nullable Runnable runnable, Tracer tracer) { return runnable; } needsContext.set(Boolean.FALSE); - ElasticContext active = tracer.currentContext(); + TraceState active = tracer.currentContext(); if (active.isEmpty()) { return runnable; } @@ -124,7 +124,7 @@ public static Runnable withContext(@Nullable Runnable runnable, Tracer tracer) { return runnable; } - private static void captureContext(Object task, ElasticContext active) { + private static void captureContext(Object task, TraceState active) { DynamicTransformer.ensureInstrumented(task.getClass(), RUNNABLE_CALLABLE_FJTASK_INSTRUMENTATION); contextMap.put(task, active); // Do no discard branches leading to async operations so not to break span references @@ -142,7 +142,7 @@ public static Callable withContext(@Nullable Callable callable, Tracer return callable; } needsContext.set(Boolean.FALSE); - ElasticContext active = tracer.currentContext(); + TraceState active = tracer.currentContext(); if (active.isEmpty()) { return callable; } @@ -159,7 +159,7 @@ public static ForkJoinTask withContext(@Nullable ForkJoinTask task, Tr return task; } needsContext.set(Boolean.FALSE); - ElasticContext active = tracer.currentContext(); + TraceState active = tracer.currentContext(); if (active.isEmpty()) { return task; } diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/RunnableCallableForkJoinTaskInstrumentation.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/RunnableCallableForkJoinTaskInstrumentation.java index 5ef881945c..ab2fc9f9f2 100644 --- a/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/RunnableCallableForkJoinTaskInstrumentation.java +++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/main/java/co/elastic/apm/agent/concurrent/RunnableCallableForkJoinTaskInstrumentation.java @@ -20,10 +20,9 @@ import co.elastic.apm.agent.sdk.DynamicTransformer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; -import co.elastic.apm.agent.tracer.AbstractSpan; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Tracer; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -81,7 +80,7 @@ public static Object onEnter(@Advice.This Object thiz) { @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class, inline = false) public static void onExit(@Nullable @Advice.Enter Object context) { if (context != null) { - ((ElasticContext) context).deactivate(); + ((TraceState) context).deactivate(); } } } diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/AsyncTraceMethodInstrumentationTest.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/AsyncTraceMethodInstrumentationTest.java index 3e13c855c0..74c17fc801 100644 --- a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/AsyncTraceMethodInstrumentationTest.java +++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/AsyncTraceMethodInstrumentationTest.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.tracer.configuration.TimeDuration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.matcher.MethodMatcher; @@ -44,14 +44,14 @@ class AsyncTraceMethodInstrumentationTest { private MockReporter reporter; private ElasticApmTracer tracer; - private CoreConfiguration coreConfiguration; + private CoreConfigurationImpl coreConfiguration; @BeforeEach void setUp(TestInfo testInfo) { MockTracer.MockInstrumentationSetup mockInstrumentationSetup = MockTracer.createMockInstrumentationSetup(); reporter = mockInstrumentationSetup.getReporter(); ConfigurationRegistry config = mockInstrumentationSetup.getConfig(); - coreConfiguration = config.getConfig(CoreConfiguration.class); + coreConfiguration = config.getConfig(CoreConfigurationImpl.class); MethodMatcher testTraceMethodMatcher = MethodMatcher.of("private co.elastic.apm.agent.concurrent.AsyncTraceMethodInstrumentationTest$TestAsyncTraceMethodsClass#*"); doReturn(Arrays.asList(testTraceMethodMatcher)).when(coreConfiguration).getTraceMethods(); @@ -66,7 +66,7 @@ void setUp(TestInfo testInfo) { } tracer = mockInstrumentationSetup.getTracer(); - assertThat(tracer.getConfig(CoreConfiguration.class).getTraceMethods()).containsExactly(testTraceMethodMatcher); + assertThat(tracer.getConfig(CoreConfigurationImpl.class).getTraceMethods()).containsExactly(testTraceMethodMatcher); ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install()); } diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExcludedExecutorClassTest.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExcludedExecutorClassTest.java index 278458f86e..d213b5b732 100644 --- a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExcludedExecutorClassTest.java +++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExcludedExecutorClassTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.concurrent; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -32,7 +32,7 @@ public class ExcludedExecutorClassTest extends AbstractInstrumentationTest { private ExecutorService executor; - private Transaction transaction; + private TransactionImpl transaction; @Before public void setUp() { diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorInstrumentationTest.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorInstrumentationTest.java index cbc36d65d7..a6395c5428 100644 --- a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorInstrumentationTest.java +++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorInstrumentationTest.java @@ -20,9 +20,9 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.impl.baggage.BaggageContext; -import co.elastic.apm.agent.impl.transaction.ElasticContext; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -61,7 +61,7 @@ public void tearDown() { @Test public void testExecutorExecute_Transaction() { - Transaction transaction = tracer.startRootTransaction(null).withName("Transaction").activate(); + TransactionImpl transaction = tracer.startRootTransaction(null).withName("Transaction").activate(); executor.execute(() -> createAsyncSpan(transaction)); try { // wait for the async operation to end @@ -76,13 +76,13 @@ public void testExecutorExecute_Transaction() { @Test public void testBaggagePropagationWithTransaction() throws InterruptedException { - Transaction transaction = tracer.startRootTransaction(null).withName("Transaction").activate(); + TransactionImpl transaction = tracer.startRootTransaction(null).withName("Transaction").activate(); BaggageContext transactionWithBaggage = tracer.currentContext().withUpdatedBaggage() .put("foo", "bar") .buildContext() .activate(); - AtomicReference> propagatedContext = new AtomicReference<>(); + AtomicReference> propagatedContext = new AtomicReference<>(); CountDownLatch doneLatch = new CountDownLatch(1); executor.execute(() -> { propagatedContext.set(tracer.currentContext()); @@ -105,7 +105,7 @@ public void testBaggagePropagationWithoutTransaction() throws InterruptedExcepti .buildContext() .activate(); - AtomicReference> propagatedContext = new AtomicReference<>(); + AtomicReference> propagatedContext = new AtomicReference<>(); CountDownLatch doneLatch = new CountDownLatch(1); executor.execute(() -> { propagatedContext.set(tracer.currentContext()); @@ -122,8 +122,8 @@ public void testBaggagePropagationWithoutTransaction() throws InterruptedExcepti @Test public void testExecutorExecute_Span() { - Transaction transaction = tracer.startRootTransaction(null).withName("Transaction").activate(); - Span nonAsyncSpan = transaction.createSpan().withName("NonAsync").activate(); + TransactionImpl transaction = tracer.startRootTransaction(null).withName("Transaction").activate(); + SpanImpl nonAsyncSpan = transaction.createSpan().withName("NonAsync").activate(); executor.execute(() -> createAsyncSpan(transaction)); try { // wait for the async operation to end @@ -139,7 +139,7 @@ public void testExecutorExecute_Span() { } - private void createAsyncSpan(Transaction expectedCurrent) { + private void createAsyncSpan(TransactionImpl expectedCurrent) { assertThat(tracer.currentTransaction()).isEqualTo(expectedCurrent); tracer.getActive().createSpan().withName("Async").end(); } diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorServiceDoubleWrappingTest.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorServiceDoubleWrappingTest.java index eaac85fa45..d72d75513e 100644 --- a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorServiceDoubleWrappingTest.java +++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorServiceDoubleWrappingTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.concurrent; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -36,7 +36,7 @@ public class ExecutorServiceDoubleWrappingTest extends AbstractInstrumentationTe private static final Object TEST_OBJECT = new Object(); private final ExecutorService executor = Executors.newSingleThreadExecutor(); - private Transaction transaction; + private TransactionImpl transaction; @Before public void setUp() { @@ -66,7 +66,7 @@ public void testWrappingTransactionSubmitRunnableTwice() throws InterruptedExcep public void testWrappingTransactionSubmitRunnableWithResultTwice() throws InterruptedException, ExecutionException { Future future = executor.submit(this::createAsyncSpan, TEST_OBJECT); assertThat(future.get()).isEqualTo(TEST_OBJECT); - Span span = reporter.getFirstSpan(500); + SpanImpl span = reporter.getFirstSpan(500); assertThat(span.getNameAsString()).isEqualTo("Async"); assertThat(span.getTraceContext().getParentId()).isEqualTo(transaction.getTraceContext().getId()); } @@ -78,7 +78,7 @@ public void testWrappingTransactionSubmitCallableTwice() throws InterruptedExcep return TEST_OBJECT; }); assertThat(future.get()).isEqualTo(TEST_OBJECT); - Span span = reporter.getFirstSpan(500); + SpanImpl span = reporter.getFirstSpan(500); assertThat(span.getNameAsString()).isEqualTo("Async"); assertThat(span.getTraceContext().getParentId()).isEqualTo(transaction.getTraceContext().getId()); } diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorServiceInstrumentationTest.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorServiceInstrumentationTest.java index 95bb769d2c..0407eca710 100644 --- a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorServiceInstrumentationTest.java +++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ExecutorServiceInstrumentationTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.concurrent; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -51,7 +51,7 @@ public class ExecutorServiceInstrumentationTest extends AbstractInstrumentationT private final ExecutorService executor; private CurrentThreadExecutor currentThreadExecutor; - private Transaction transaction; + private TransactionImpl transaction; public ExecutorServiceInstrumentationTest(Supplier supplier) { executor = supplier.get(); @@ -141,9 +141,9 @@ public void testExecutorSubmitCallableMethodReference() throws Exception { @Test public void testInvokeAll() throws Exception { - final List> futures = executor.invokeAll(Arrays.>asList(this::createAsyncSpan, () -> createAsyncSpan(), new Callable() { + final List> futures = executor.invokeAll(Arrays.>asList(this::createAsyncSpan, () -> createAsyncSpan(), new Callable() { @Override - public Span call() throws Exception { + public SpanImpl call() throws Exception { return createAsyncSpan(); } })); @@ -159,16 +159,16 @@ public void testNestedExecutions() throws Exception { @Test public void testInvokeAllTimed() throws Exception { - final List> futures = executor.invokeAll(Arrays.asList( - new Callable() { + final List> futures = executor.invokeAll(Arrays.asList( + new Callable() { @Override - public Span call() throws Exception { + public SpanImpl call() throws Exception { return createAsyncSpan(); } }, - new Callable() { + new Callable() { @Override - public Span call() throws Exception { + public SpanImpl call() throws Exception { return createAsyncSpan(); } }), 1, TimeUnit.SECONDS); @@ -178,9 +178,9 @@ public Span call() throws Exception { @Test public void testInvokeAny() throws Exception { - executor.invokeAny(Collections.singletonList(new Callable() { + executor.invokeAny(Collections.singletonList(new Callable() { @Override - public Span call() { + public SpanImpl call() { return createAsyncSpan(); } })); @@ -189,9 +189,9 @@ public Span call() { @Test public void testInvokeAnyTimed() throws Exception { - executor.invokeAny(Collections.>singletonList(new Callable() { + executor.invokeAny(Collections.>singletonList(new Callable() { @Override - public Span call() { + public SpanImpl call() { return createAsyncSpan(); } }), 1, TimeUnit.SECONDS); @@ -213,10 +213,10 @@ static Consumer of(ThrowingConsumer throwingConsumer) { void accept(T t) throws Exception; } - private Span createAsyncSpan() { + private SpanImpl createAsyncSpan() { assertThat(tracer.getActive()).isNotNull(); assertThat(tracer.getActive().getTraceContext().getId()).isEqualTo(transaction.getTraceContext().getId()); - final Span span = tracer.getActive().createSpan().withName("Async"); + final SpanImpl span = tracer.getActive().createSpan().withName("Async"); span.end(); return span; } diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ForkJoinPoolTest.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ForkJoinPoolTest.java index cc644b6603..11b2553579 100644 --- a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ForkJoinPoolTest.java +++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ForkJoinPoolTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.concurrent; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; +import co.elastic.apm.agent.tracer.TraceState; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,8 +37,8 @@ public class ForkJoinPoolTest extends AbstractInstrumentationTest { private ForkJoinPool pool; - private Transaction transaction; - private ElasticContext txWithBaggage; + private TransactionImpl transaction; + private TraceState txWithBaggage; @BeforeEach void setUp() { @@ -58,7 +58,7 @@ void tearDown() { @Test void testExecute() throws Exception { - final ForkJoinTask> task = newTask(() -> tracer.currentContext()); + final ForkJoinTask> task = newTask(() -> tracer.currentContext()); pool.execute(task); assertThat(task.get()).isSameAs(txWithBaggage); } @@ -90,7 +90,7 @@ void testCompletableFuture() throws Exception { void testParallelStream() { assertThat(Stream.of("foo", "bar", "baz") .parallel() - .>map(s -> tracer.currentContext()) + .>map(s -> tracer.currentContext()) .distinct()) .containsExactly(txWithBaggage); } diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ScheduledExecutorServiceTest.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ScheduledExecutorServiceTest.java index 5e61ef8e1a..73c6bdeeae 100644 --- a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ScheduledExecutorServiceTest.java +++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ScheduledExecutorServiceTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.concurrent; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,7 +36,7 @@ public class ScheduledExecutorServiceTest extends AbstractInstrumentationTest { private ScheduledThreadPoolExecutor scheduler; - private Transaction transaction; + private TransactionImpl transaction; @BeforeEach void setUp() { @@ -53,14 +53,14 @@ void tearDown() { @Test void testScheduleCallable() throws Exception { - final ScheduledFuture> future = scheduler.schedule(() -> tracer.getActive(), 0, TimeUnit.SECONDS); + final ScheduledFuture> future = scheduler.schedule(() -> tracer.getActive(), 0, TimeUnit.SECONDS); assertThat(future.get()).isEqualTo(transaction); assertThat(tracer.getActive()).isEqualTo(transaction); } @Test void testScheduleRunnable() throws Exception { - AtomicReference> ref = new AtomicReference<>(); + AtomicReference> ref = new AtomicReference<>(); scheduler.schedule(() -> ref.set(tracer.getActive()), 0, TimeUnit.SECONDS).get(); assertThat(ref.get()).isEqualTo(transaction); assertThat(tracer.getActive()).isEqualTo(transaction); @@ -68,14 +68,14 @@ void testScheduleRunnable() throws Exception { @Test void testScheduleCallable_delayAndEndTransaction() throws Exception { - final ScheduledFuture> scheduledFuture = scheduler.schedule(() -> tracer.getActive(), 50, TimeUnit.MILLISECONDS); + final ScheduledFuture> scheduledFuture = scheduler.schedule(() -> tracer.getActive(), 50, TimeUnit.MILLISECONDS); verifyEndedTransactionIsStillReferenced(scheduledFuture); assertThat(scheduledFuture.get()).isEqualTo(transaction); } @Test void testScheduleRunnable_delayAndEndTransaction() throws Exception { - AtomicReference> ref = new AtomicReference<>(); + AtomicReference> ref = new AtomicReference<>(); ScheduledFuture scheduledTaskFuture = scheduler.schedule(() -> ref.set(tracer.getActive()), 50, TimeUnit.MILLISECONDS); verifyEndedTransactionIsStillReferenced(scheduledTaskFuture); assertThat(ref.get()).isEqualTo(transaction); diff --git a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ScopeManagementTest.java b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ScopeManagementTest.java index ac78d46be2..fd15bf408e 100644 --- a/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ScopeManagementTest.java +++ b/apm-agent-plugins/apm-java-concurrent-plugin/src/test/java/co/elastic/apm/agent/concurrent/ScopeManagementTest.java @@ -21,8 +21,8 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.TracerInternalApiUtils; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.Test; import java.util.concurrent.Callable; @@ -43,8 +43,8 @@ void runTestWithAssertionsDisabled(Runnable test) { @Test void testWrongDeactivationOrder() { runTestWithAssertionsDisabled(() -> { - final Transaction transaction = tracer.startRootTransaction(null).activate(); - final Span span = transaction.createSpan().activate(); + final TransactionImpl transaction = tracer.startRootTransaction(null).activate(); + final SpanImpl span = transaction.createSpan().activate(); transaction.deactivate().end(); span.deactivate().end(); @@ -68,7 +68,7 @@ void testActivateTwice() { void testRedundantActivation() { disableRecyclingValidation(); runTestWithAssertionsDisabled(() -> { - final Transaction transaction = tracer.startRootTransaction(null).activate(); + final TransactionImpl transaction = tracer.startRootTransaction(null).activate(); transaction.createSpan().activate().end(); transaction.deactivate(); assertThat(tracer.getActive()).isEqualTo(transaction); @@ -80,8 +80,8 @@ void testRedundantActivation() { @Test void testSpanAndContextCallableActivation() { runTestWithAssertionsDisabled(() -> { - final Transaction transaction = tracer.startRootTransaction(null).activate(); - Callable callable = () -> tracer.currentTransaction(); + final TransactionImpl transaction = tracer.startRootTransaction(null).activate(); + Callable callable = () -> tracer.currentTransaction(); try { assertThat(callable.call()).isSameAs(transaction); } catch (Exception e) { @@ -95,7 +95,7 @@ void testSpanAndContextCallableActivation() { @Test void testContextAndSpanRunnableActivationInDifferentThread() throws Exception { - final Transaction transaction = tracer.startRootTransaction(null).activate(); + final TransactionImpl transaction = tracer.startRootTransaction(null).activate(); Executors.newSingleThreadExecutor().submit(() -> { assertThat(tracer.getActive()).isSameAs(transaction); assertThat(tracer.currentTransaction()).isSameAs(transaction); @@ -107,8 +107,8 @@ void testContextAndSpanRunnableActivationInDifferentThread() throws Exception { @Test void testContextAndSpanCallableActivationInDifferentThread() throws Exception { - final Transaction transaction = tracer.startRootTransaction(null).activate(); - Future transactionFuture = Executors.newSingleThreadExecutor().submit(() -> { + final TransactionImpl transaction = tracer.startRootTransaction(null).activate(); + Future transactionFuture = Executors.newSingleThreadExecutor().submit(() -> { assertThat(tracer.getActive()).isSameAs(transaction); return tracer.currentTransaction(); }); @@ -120,7 +120,7 @@ void testContextAndSpanCallableActivationInDifferentThread() throws Exception { @Test void testSpanAndContextRunnableActivationInDifferentThread() throws Exception { - final Transaction transaction = tracer.startRootTransaction(null).activate(); + final TransactionImpl transaction = tracer.startRootTransaction(null).activate(); Runnable runnable = () -> { assertThat(tracer.currentTransaction()).isSameAs(transaction); assertThat(tracer.getActive()).isSameAs(transaction); @@ -133,7 +133,7 @@ void testSpanAndContextRunnableActivationInDifferentThread() throws Exception { @Test void testSpanAndContextCallableActivationInDifferentThread() throws Exception { - final Transaction transaction = tracer.startRootTransaction(null).activate(); + final TransactionImpl transaction = tracer.startRootTransaction(null).activate(); assertThat(Executors.newSingleThreadExecutor().submit(() -> { assertThat(tracer.currentTransaction()).isSameAs(transaction); return tracer.currentTransaction(); diff --git a/apm-agent-plugins/apm-java-ldap-plugin/pom.xml b/apm-agent-plugins/apm-java-ldap-plugin/pom.xml index a144963f8c..70de83e3c4 100644 --- a/apm-agent-plugins/apm-java-ldap-plugin/pom.xml +++ b/apm-agent-plugins/apm-java-ldap-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-java-ldap-plugin diff --git a/apm-agent-plugins/apm-java-ldap-plugin/src/test/java/co/elastic/apm/agent/java_ldap/LdapClientAdviceTest.java b/apm-agent-plugins/apm-java-ldap-plugin/src/test/java/co/elastic/apm/agent/java_ldap/LdapClientAdviceTest.java index 262ccd0f29..ca47db7939 100644 --- a/apm-agent-plugins/apm-java-ldap-plugin/src/test/java/co/elastic/apm/agent/java_ldap/LdapClientAdviceTest.java +++ b/apm-agent-plugins/apm-java-ldap-plugin/src/test/java/co/elastic/apm/agent/java_ldap/LdapClientAdviceTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.java_ldap; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.test.TestPort; import co.elastic.apm.agent.tracer.Outcome; import com.unboundid.ldap.listener.InMemoryDirectoryServer; @@ -63,7 +63,7 @@ static void stopServer() { void testSuccessfulAuthentication() throws Exception { Hashtable environment = getEnvironment(); - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try { new InitialDirContext(environment).close(); } catch (Exception ignored) { @@ -71,7 +71,7 @@ void testSuccessfulAuthentication() throws Exception { transaction.deactivate().end(); } - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans.size()).isEqualTo(1); assertSpan(spans.get(0), "authenticate", Outcome.SUCCESS); @@ -82,7 +82,7 @@ void testUnsuccessfulAuthentication() { Hashtable environment = getEnvironment(); environment.put(Context.SECURITY_CREDENTIALS, "wrong password"); - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try { new InitialDirContext(environment).close(); } catch (Exception ignored) { @@ -91,7 +91,7 @@ void testUnsuccessfulAuthentication() { transaction.deactivate().end(); } - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans.size()).isEqualTo(1); assertSpan(spans.get(0), "authenticate", Outcome.FAILURE); @@ -101,7 +101,7 @@ void testUnsuccessfulAuthentication() { void testSearch() { Hashtable environment = getEnvironment(); - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try { InitialDirContext context = new InitialDirContext(environment); context.search("dc=example,dc=com", "(&(objectClass=person)(uid=tobiasstadler))", null); @@ -111,7 +111,7 @@ void testSearch() { transaction.deactivate().end(); } - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans.size()).isEqualTo(2); assertSpan(spans.get(0), "authenticate", Outcome.SUCCESS); @@ -130,7 +130,7 @@ private static Hashtable getEnvironment() { return environment; } - static void assertSpan(Span span, String method, Outcome outcome) { + static void assertSpan(SpanImpl span, String method, Outcome outcome) { assertThat(span.getNameAsString()).isEqualTo("LDAP " + method); assertThat(span.getType()).isEqualTo("external"); assertThat(span.getSubtype()).isEqualTo("ldap"); diff --git a/apm-agent-plugins/apm-javalin-plugin/pom.xml b/apm-agent-plugins/apm-javalin-plugin/pom.xml index 16b4e238df..555be4c392 100644 --- a/apm-agent-plugins/apm-javalin-plugin/pom.xml +++ b/apm-agent-plugins/apm-javalin-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-javalin-plugin diff --git a/apm-agent-plugins/apm-javalin-plugin/src/test/java/co/elastic/apm/agent/javalin/JavalinInstrumentationTest.java b/apm-agent-plugins/apm-javalin-plugin/src/test/java/co/elastic/apm/agent/javalin/JavalinInstrumentationTest.java index 8f28f8cdef..746ee2f630 100644 --- a/apm-agent-plugins/apm-javalin-plugin/src/test/java/co/elastic/apm/agent/javalin/JavalinInstrumentationTest.java +++ b/apm-agent-plugins/apm-javalin-plugin/src/test/java/co/elastic/apm/agent/javalin/JavalinInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.javalin; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import io.javalin.Javalin; import io.javalin.http.Context; import io.javalin.http.HandlerType; @@ -101,9 +101,9 @@ public void testBefore() throws Exception { final HttpResponse mainUrlResponse = client.send(request, HttpResponse.BodyHandlers.ofString()); assertThat(mainUrlResponse.statusCode()).isEqualTo(404); assertThat(reporter.getFirstTransaction().getNameAsString()).isEqualTo("GET /before"); - final List spans = reporter.getSpans(); + final List spans = reporter.getSpans(); assertThat(spans).hasSize(2); - final List names = spans.stream().map(Span::getNameAsString).collect(Collectors.toList()); + final List names = spans.stream().map(SpanImpl::getNameAsString).collect(Collectors.toList()); assertThat(names).containsExactly("BEFORE /before", "GET /before"); } @@ -119,9 +119,9 @@ public void testAfter() throws Exception { assertThat(mainUrlResponse.headers().firstValue("foo").get()).isEqualTo("bar"); assertThat(reporter.getFirstTransaction().getNameAsString()).isEqualTo("GET /after"); assertThat(reporter.getFirstTransaction().getSpanCount().getTotal().get()).isEqualTo(3); - final List spans = reporter.getSpans(); + final List spans = reporter.getSpans(); assertThat(spans).hasSize(3); - final List names = spans.stream().map(Span::getNameAsString).collect(Collectors.toList()); + final List names = spans.stream().map(SpanImpl::getNameAsString).collect(Collectors.toList()); assertThat(names).containsExactly("GET /after", "AFTER /after", "AFTER /after"); } @@ -157,7 +157,7 @@ public void testFuturesGetInstrumented() throws Exception { final HttpResponse mainUrlResponse = client.send(request, HttpResponse.BodyHandlers.ofString()); assertThat(mainUrlResponse.statusCode()).isEqualTo(404); assertThat(reporter.getFirstTransaction(500).getNameAsString()).isEqualTo("GET " + endpoint); - final Span span = reporter.getFirstSpan(500); + final SpanImpl span = reporter.getFirstSpan(500); assertThat(span.getNameAsString()).isEqualTo("GET " + endpoint); } @@ -175,9 +175,9 @@ public void testRenderSpan() throws Exception { assertThat(reporter.getFirstTransaction(500).getNameAsString()).isEqualTo("GET " + endpoint); assertThat(reporter.getSpans()).hasSize(2); - Span getSpan = reporter.getSpanByName("GET /render-span"); + SpanImpl getSpan = reporter.getSpanByName("GET /render-span"); assertThat(getSpan).isNotNull(); - Span renderSpan = reporter.getSpanByName("render my-template.abc"); + SpanImpl renderSpan = reporter.getSpanByName("render my-template.abc"); assertThat(renderSpan).isNotNull(); assertThat(renderSpan.getType()).isEqualTo("app"); assertThat(renderSpan.getSubtype()).isEqualTo("internal"); diff --git a/apm-agent-plugins/apm-jaxrs-plugin-jakartaee-test/pom.xml b/apm-agent-plugins/apm-jaxrs-plugin-jakartaee-test/pom.xml index 1dbc95fc84..684ec3a081 100644 --- a/apm-agent-plugins/apm-jaxrs-plugin-jakartaee-test/pom.xml +++ b/apm-agent-plugins/apm-jaxrs-plugin-jakartaee-test/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-jaxrs-plugin-jakartaee-test/src/test/java/co/elastic/apm/agent/jaxrs/JakartaeeJaxRsTransactionNameInstrumentationTest.java b/apm-agent-plugins/apm-jaxrs-plugin-jakartaee-test/src/test/java/co/elastic/apm/agent/jaxrs/JakartaeeJaxRsTransactionNameInstrumentationTest.java index d74ad9118c..35c0ccff68 100644 --- a/apm-agent-plugins/apm-jaxrs-plugin-jakartaee-test/src/test/java/co/elastic/apm/agent/jaxrs/JakartaeeJaxRsTransactionNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-jaxrs-plugin-jakartaee-test/src/test/java/co/elastic/apm/agent/jaxrs/JakartaeeJaxRsTransactionNameInstrumentationTest.java @@ -22,7 +22,7 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; @@ -140,7 +140,7 @@ public void testJaxRsFrameworkNameAndVersion() throws IOException { * @param path the path to make the get request against */ private void doRequest(String path) { - final Transaction request = tracer.startRootTransaction(null) + final TransactionImpl request = tracer.startRootTransaction(null) .withType("request") .activate(); try { diff --git a/apm-agent-plugins/apm-jaxrs-plugin/pom.xml b/apm-agent-plugins/apm-jaxrs-plugin/pom.xml index ff76e2ad6c..d520542507 100644 --- a/apm-agent-plugins/apm-jaxrs-plugin/pom.xml +++ b/apm-agent-plugins/apm-jaxrs-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-jaxrs-plugin diff --git a/apm-agent-plugins/apm-jaxrs-plugin/src/test/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentationTest.java b/apm-agent-plugins/apm-jaxrs-plugin/src/test/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentationTest.java index 5eda6683e8..1473d4734a 100644 --- a/apm-agent-plugins/apm-jaxrs-plugin/src/test/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-jaxrs-plugin/src/test/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentationTest.java @@ -22,7 +22,7 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; @@ -137,7 +137,7 @@ public void testJaxRsFrameworkNameAndVersion() throws IOException { * @param path the path to make the get request against */ private void doRequest(String path) { - final Transaction request = tracer.startRootTransaction(null) + final TransactionImpl request = tracer.startRootTransaction(null) .withType("request") .activate(); try { diff --git a/apm-agent-plugins/apm-jaxrs-plugin/src/test/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentationTestHelper.java b/apm-agent-plugins/apm-jaxrs-plugin/src/test/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentationTestHelper.java index 5a947e307e..a27d6d7ca5 100644 --- a/apm-agent-plugins/apm-jaxrs-plugin/src/test/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentationTestHelper.java +++ b/apm-agent-plugins/apm-jaxrs-plugin/src/test/java/co/elastic/apm/agent/jaxrs/JaxRsTransactionNameInstrumentationTestHelper.java @@ -20,10 +20,10 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.objectpool.TestObjectPoolFactory; import net.bytebuddy.agent.ByteBuddyAgent; import org.stagemonitor.configuration.ConfigurationRegistry; @@ -58,7 +58,7 @@ public void testJaxRsTransactionNameWithoutJaxrsAnnotationInheritance() { doRequestConsumer.accept("test"); doRequestConsumer.accept("testInterface"); doRequestConsumer.accept("testAbstract"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(3); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("ResourceWithPath#testMethod"); assertThat(actualTransactions.get(1).getNameAsString()).isEqualTo("unnamed"); @@ -73,7 +73,7 @@ public void testJaxRsTransactionNameWithJaxrsAnnotationInheritance() { doRequestConsumer.accept("testInterface"); doRequestConsumer.accept("testAbstract"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(3); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("ResourceWithPath#testMethod"); assertThat(actualTransactions.get(1).getNameAsString()).isEqualTo("ResourceWithPathOnInterface#testMethod"); @@ -85,7 +85,7 @@ public void testJaxRsTransactionNameMethodDelegation() { doRequestConsumer.accept("methodDelegation/methodA"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(1); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("MethodDelegationResource#methodA"); } @@ -97,19 +97,19 @@ public void testProxyClassInstrumentationExclusion() { doRequestConsumer.accept("testViewProxy"); doRequestConsumer.accept("testProxyProxy"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(2); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("unnamed"); assertThat(actualTransactions.get(1).getNameAsString()).isEqualTo("unnamed"); } public void testJaxRsTransactionNameNonSampledTransactions() throws IOException { - config.getConfig(CoreConfiguration.class).getSampleRate().update(0.0, SpyConfiguration.CONFIG_SOURCE_NAME); + config.getConfig(CoreConfigurationImpl.class).getSampleRate().update(0.0, SpyConfiguration.CONFIG_SOURCE_NAME); ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install()); doRequestConsumer.accept("test"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(1); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("ResourceWithPath#testMethod"); } @@ -124,7 +124,7 @@ public void testJaxRsTransactionNameFromPathAnnotationInheritanceEnabled() { doRequestConsumer.accept("testAbstract"); doRequestConsumer.accept("testInterface"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(3); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("GET /test"); assertThat(actualTransactions.get(1).getNameAsString()).isEqualTo("GET /testAbstract"); @@ -141,7 +141,7 @@ public void testJaxRsTransactionNameFromPathAnnotationInheritanceDisabled() { doRequestConsumer.accept("testInterface"); doRequestConsumer.accept("testAbstract"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(3); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("GET /test"); assertThat(actualTransactions.get(1).getNameAsString()).isEqualTo("unnamed"); @@ -157,7 +157,7 @@ public void testJaxRsTransactionNameFromPathAnnotationInheritanceEnabledOnMethod doRequestConsumer.accept("testWithPathMethod"); doRequestConsumer.accept("testWithPathMethod/15"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(2); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("GET /testWithPathMethod"); assertThat(actualTransactions.get(1).getNameAsString()).isEqualTo("GET /testWithPathMethod/{id}"); @@ -172,7 +172,7 @@ public void testJaxRsTransactionNameFromPathAnnotationInheritanceEnabledOnMethod doRequestConsumer.accept("testWithPathMethodSlash"); doRequestConsumer.accept("testWithPathMethodSlash/15"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(2); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("GET /testWithPathMethodSlash"); assertThat(actualTransactions.get(1).getNameAsString()).isEqualTo("GET /testWithPathMethodSlash/{id}"); @@ -186,7 +186,7 @@ public void testJaxRsTransactionNameFromPathAnnotationInheritanceEnabledOnMethod doRequestConsumer.accept("/foo/bar"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(1); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("GET /foo/bar"); } @@ -199,7 +199,7 @@ public void testJaxRsTransactionNameFromPathAnnotationInheritanceEnabledOnEmptyP doRequestConsumer.accept(""); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(1); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("GET /"); } @@ -212,7 +212,7 @@ public void testJaxRsTransactionNameFromPathAnnotationInheritanceEnabledOnResour doRequestConsumer.accept("/testInterface/test"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(1); assertThat(actualTransactions.get(0).getNameAsString()).isEqualTo("GET /testInterface/test"); } @@ -224,19 +224,19 @@ public void testJaxRsFrameworkNameAndVersion(String expectedVersion) throws IOEx doRequestConsumer.accept("test"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(1); assertThat(reporter.getFirstTransaction().getFrameworkName()).isEqualTo("JAX-RS"); assertThat(reporter.getFirstTransaction().getFrameworkVersion()).isEqualTo(expectedVersion); } public void testJaxRsFrameworkNameAndVersionWithNonSampledTransaction(String expectedVersion) throws IOException { - config.getConfig(CoreConfiguration.class).getSampleRate().update(0.0, SpyConfiguration.CONFIG_SOURCE_NAME); + config.getConfig(CoreConfigurationImpl.class).getSampleRate().update(0.0, SpyConfiguration.CONFIG_SOURCE_NAME); ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install()); doRequestConsumer.accept("test"); - List actualTransactions = reporter.getTransactions(); + List actualTransactions = reporter.getTransactions(); assertThat(actualTransactions).hasSize(1); assertThat(reporter.getFirstTransaction().getFrameworkName()).isEqualTo("JAX-RS"); assertThat(reporter.getFirstTransaction().getFrameworkVersion()).isEqualTo(expectedVersion); diff --git a/apm-agent-plugins/apm-jaxws-plugin-jakartaee-test/pom.xml b/apm-agent-plugins/apm-jaxws-plugin-jakartaee-test/pom.xml index 8deff6f05e..da66ac50f6 100644 --- a/apm-agent-plugins/apm-jaxws-plugin-jakartaee-test/pom.xml +++ b/apm-agent-plugins/apm-jaxws-plugin-jakartaee-test/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-jaxws-plugin/pom.xml b/apm-agent-plugins/apm-jaxws-plugin/pom.xml index 95de0d6747..36d0d5a2ba 100644 --- a/apm-agent-plugins/apm-jaxws-plugin/pom.xml +++ b/apm-agent-plugins/apm-jaxws-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-jaxws-plugin diff --git a/apm-agent-plugins/apm-jaxws-plugin/src/test/java/co/elastic/apm/agent/jaxws/AbstractJaxWsInstrumentationTest.java b/apm-agent-plugins/apm-jaxws-plugin/src/test/java/co/elastic/apm/agent/jaxws/AbstractJaxWsInstrumentationTest.java index 55f5e6b06e..726327e0ab 100644 --- a/apm-agent-plugins/apm-jaxws-plugin/src/test/java/co/elastic/apm/agent/jaxws/AbstractJaxWsInstrumentationTest.java +++ b/apm-agent-plugins/apm-jaxws-plugin/src/test/java/co/elastic/apm/agent/jaxws/AbstractJaxWsInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.jaxws; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Scope; import org.junit.jupiter.api.Test; @@ -31,7 +31,7 @@ public abstract class AbstractJaxWsInstrumentationTest extends AbstractInstrumen @Test void testTransactionName() { - final Transaction transaction = tracer.startRootTransaction(getClass().getClassLoader()); + final TransactionImpl transaction = tracer.startRootTransaction(getClass().getClassLoader()); try (Scope scope = transaction.activateInScope()) { helloWorldService.sayHello(); } finally { diff --git a/apm-agent-plugins/apm-jdbc-plugin/pom.xml b/apm-agent-plugins/apm-jdbc-plugin/pom.xml index fd7bfd7466..1e7a3bddc6 100644 --- a/apm-agent-plugins/apm-jdbc-plugin/pom.xml +++ b/apm-agent-plugins/apm-jdbc-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-jdbc-plugin diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcHelper.java b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcHelper.java index ca8f379e40..cc93cb87c0 100644 --- a/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcHelper.java +++ b/apm-agent-plugins/apm-jdbc-plugin/src/main/java/co/elastic/apm/agent/jdbc/helper/JdbcHelper.java @@ -23,7 +23,7 @@ import co.elastic.apm.agent.tracer.AbstractSpan; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Span; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.jdbc.JdbcFilter; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -90,7 +90,7 @@ public String retrieveSqlForStatement(Object statement) { @Nullable - public Span createJdbcSpan(@Nullable String sql, Object statement, ElasticContext activeContext, boolean preparedStatement) { + public Span createJdbcSpan(@Nullable String sql, Object statement, TraceState activeContext, boolean preparedStatement) { if (!(statement instanceof Statement) || sql == null || isAlreadyMonitored(activeContext.getSpan())) { return null; } diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/test/java/co/elastic/apm/agent/jdbc/AbstractJdbcInstrumentationTest.java b/apm-agent-plugins/apm-jdbc-plugin/src/test/java/co/elastic/apm/agent/jdbc/AbstractJdbcInstrumentationTest.java index 71dbd2e4f8..8a924884cb 100644 --- a/apm-agent-plugins/apm-jdbc-plugin/src/test/java/co/elastic/apm/agent/jdbc/AbstractJdbcInstrumentationTest.java +++ b/apm-agent-plugins/apm-jdbc-plugin/src/test/java/co/elastic/apm/agent/jdbc/AbstractJdbcInstrumentationTest.java @@ -20,12 +20,12 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.configuration.SpanConfiguration; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.sdk.internal.db.signature.SignatureParser; -import co.elastic.apm.agent.impl.context.Db; -import co.elastic.apm.agent.impl.context.Destination; +import co.elastic.apm.agent.impl.context.DbImpl; +import co.elastic.apm.agent.impl.context.DestinationImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.jdbc.helper.JdbcGlobalState; import org.junit.After; import org.junit.Before; @@ -68,7 +68,7 @@ public abstract class AbstractJdbcInstrumentationTest extends AbstractInstrument private PreparedStatement preparedStatement; @Nullable private PreparedStatement updatePreparedStatement; - private final Transaction transaction; + private final TransactionImpl transaction; private final SignatureParser signatureParser; AbstractJdbcInstrumentationTest(Connection connection, String expectedDbVendor, String expectedDbName) throws Exception { @@ -183,7 +183,7 @@ private void testStatement() throws SQLException { assertThat(resultSet.getInt("foo")).isEqualTo(1); assertThat(resultSet.getString("BAR")).isEqualTo("APM"); - Span span = assertSpanRecorded(sql, false, -1); + SpanImpl span = assertSpanRecorded(sql, false, -1); assertThat(span.getOutcome()).isEqualTo(Outcome.SUCCESS); } @@ -323,7 +323,7 @@ private void testUpdate(StatementExecutor statementConsumer) throws SQLE reporter.reset(); // unique key violation assertThatThrownBy(() -> statementConsumer.withStatement(statement, insert)).isInstanceOf(SQLException.class); - Span span = assertSpanRecorded(insert, false, -1); + SpanImpl span = assertSpanRecorded(insert, false, -1); assertThat(span.getOutcome()).isEqualTo(Outcome.FAILURE); } @@ -349,7 +349,7 @@ private void testPreparedStatementUpdate(PreparedStatementExecutor state int mappedStatements = JdbcGlobalState.statementSqlMap.approximateSize(); statement.close(); assertThat(JdbcGlobalState.statementSqlMap.approximateSize()).isLessThan(mappedStatements); - Span span = assertSpanRecorded(insert, false, -1); + SpanImpl span = assertSpanRecorded(insert, false, -1); assertThat(span.getOutcome()).isEqualTo(Outcome.FAILURE); } @@ -422,15 +422,15 @@ private void assertQuerySucceededAndSpanRecorded(ResultSet resultSet, String raw assertSpanRecorded(rawSql, preparedStatement, -1); } - private Span assertSpanRecorded(String rawSql, boolean preparedStatement, long expectedAffectedRows) throws SQLException { + private SpanImpl assertSpanRecorded(String rawSql, boolean preparedStatement, long expectedAffectedRows) throws SQLException { return assertSpanRecorded(rawSql, preparedStatement, expectedAffectedRows, expectedDbName); } - private Span assertSpanRecorded(String rawSql, boolean preparedStatement, long expectedAffectedRows, @Nullable String expectedDbInstance) throws SQLException { + private SpanImpl assertSpanRecorded(String rawSql, boolean preparedStatement, long expectedAffectedRows, @Nullable String expectedDbInstance) throws SQLException { assertThat(reporter.getSpans()) .describedAs("one span is expected") .hasSize(1); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); StringBuilder processedSql = new StringBuilder(); signatureParser.querySignature(rawSql, processedSql, preparedStatement); assertThat(span.getNameAsString()).isEqualTo(processedSql.toString()); @@ -438,7 +438,7 @@ private Span assertSpanRecorded(String rawSql, boolean preparedStatement, long e assertThat(span.getSubtype()).isEqualTo(expectedDbVendor); assertThat(span.getAction()).isEqualTo(DB_SPAN_ACTION); - Db db = span.getContext().getDb(); + DbImpl db = span.getContext().getDb(); assertThat(db).hasStatement(rawSql); DatabaseMetaData metaData = connection.getMetaData(); @@ -449,7 +449,7 @@ private Span assertSpanRecorded(String rawSql, boolean preparedStatement, long e .describedAs("unexpected affected rows count for statement %s", rawSql) .isEqualTo(expectedAffectedRows); - Destination destination = span.getContext().getDestination(); + DestinationImpl destination = span.getContext().getDestination(); assertThat(destination).hasLocalAddress(); if (expectedDbVendor.equals("h2")) { assertThat(destination).hasNoPort(); @@ -485,7 +485,7 @@ private void assertSpanRecordedWithoutConnection(String rawSql, boolean prepared assertThat(reporter.getSpans()) .describedAs("one span is expected") .hasSize(1); - Span jdbcSpan = reporter.getFirstSpan(); + SpanImpl jdbcSpan = reporter.getFirstSpan(); StringBuilder processedSql = new StringBuilder(); signatureParser.querySignature(rawSql, processedSql, preparedStatement); assertThat(jdbcSpan).hasName(processedSql.toString()) @@ -493,7 +493,7 @@ private void assertSpanRecordedWithoutConnection(String rawSql, boolean prepared .hasSubType("unknown") .hasAction(DB_SPAN_ACTION); - Db db = jdbcSpan.getContext().getDb(); + DbImpl db = jdbcSpan.getContext().getDb(); assertThat(db).hasStatement(rawSql); assertThat(db.getInstance()).isNull(); assertThat(db.getUser()).isNull(); diff --git a/apm-agent-plugins/apm-jdbc-plugin/src/test/java/co/elastic/apm/agent/jdbc/helper/ConnectionMetaDataTest.java b/apm-agent-plugins/apm-jdbc-plugin/src/test/java/co/elastic/apm/agent/jdbc/helper/ConnectionMetaDataTest.java index 5c77ad732d..000fe01d3b 100644 --- a/apm-agent-plugins/apm-jdbc-plugin/src/test/java/co/elastic/apm/agent/jdbc/helper/ConnectionMetaDataTest.java +++ b/apm-agent-plugins/apm-jdbc-plugin/src/test/java/co/elastic/apm/agent/jdbc/helper/ConnectionMetaDataTest.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -376,7 +376,7 @@ private void testUrl(String url, String expectedVendor, @Nullable String expecte // to make sure that at least the known ones always fit try { - Transaction transaction = tracer.startRootTransaction(this.getClass().getClassLoader()); + TransactionImpl transaction = tracer.startRootTransaction(this.getClass().getClassLoader()); assertThat(transaction).isNotNull(); transaction.createSpan() .withType("db") diff --git a/apm-agent-plugins/apm-jdk-httpclient-plugin/pom.xml b/apm-agent-plugins/apm-jdk-httpclient-plugin/pom.xml index 1f15367012..bd7a2a381e 100644 --- a/apm-agent-plugins/apm-jdk-httpclient-plugin/pom.xml +++ b/apm-agent-plugins/apm-jdk-httpclient-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-jdk-httpclient-plugin diff --git a/apm-agent-plugins/apm-jdk-httpserver-plugin/pom.xml b/apm-agent-plugins/apm-jdk-httpserver-plugin/pom.xml index 60c2773b81..13fc68cde5 100644 --- a/apm-agent-plugins/apm-jdk-httpserver-plugin/pom.xml +++ b/apm-agent-plugins/apm-jdk-httpserver-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-jdk-httpserver-plugin diff --git a/apm-agent-plugins/apm-jdk-httpserver-plugin/src/test/java/co/elastic/apm/agent/httpserver/HttpHandlerTest.java b/apm-agent-plugins/apm-jdk-httpserver-plugin/src/test/java/co/elastic/apm/agent/httpserver/HttpHandlerTest.java index eae5e67fed..8618e46f27 100644 --- a/apm-agent-plugins/apm-jdk-httpserver-plugin/src/test/java/co/elastic/apm/agent/httpserver/HttpHandlerTest.java +++ b/apm-agent-plugins/apm-jdk-httpserver-plugin/src/test/java/co/elastic/apm/agent/httpserver/HttpHandlerTest.java @@ -19,15 +19,15 @@ package co.elastic.apm.agent.httpserver; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.context.Socket; -import co.elastic.apm.agent.impl.context.Url; +import co.elastic.apm.agent.impl.context.RequestImpl; +import co.elastic.apm.agent.impl.context.ResponseImpl; +import co.elastic.apm.agent.impl.context.SocketImpl; +import co.elastic.apm.agent.impl.context.UrlImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; import co.elastic.apm.agent.tracer.util.ResultUtil; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; @@ -105,19 +105,19 @@ void testRootTransaction(int expectedStatus) throws IOException { assertThat(httpResponse.code()).isEqualTo(expectedStatus); assertThat(httpResponse.body().string()).isEmpty(); - Transaction transaction = reporter.getFirstTransaction(500); + TransactionImpl transaction = reporter.getFirstTransaction(500); assertThat(transaction.getTraceContext().getParentId().toString()).isEqualTo("0000000000000000"); assertThat(transaction.getType()).isEqualTo(co.elastic.apm.agent.tracer.Transaction.TYPE_REQUEST); assertThat(transaction.getNameAsString()).isEqualTo("GET /status_%d", expectedStatus); assertThat(transaction.getResult()).isEqualTo(ResultUtil.getResultByHttpStatus(expectedStatus)); assertThat(transaction.getOutcome()).isEqualTo(ResultUtil.getOutcomeByHttpServerStatus(expectedStatus)); - Request request = transaction.getContext().getRequest(); + RequestImpl request = transaction.getContext().getRequest(); - Socket socket = request.getSocket(); + SocketImpl socket = request.getSocket(); assertThat(socket.getRemoteAddress()).isEqualTo("127.0.0.1"); - Url url = request.getUrl(); + UrlImpl url = request.getUrl(); assertThat(url.getProtocol()).isEqualTo("http"); assertThat(url.getHostname()).isEqualTo("localhost"); assertThat(url.getPort()).isEqualTo(httpServer.getAddress().getPort()); @@ -130,7 +130,7 @@ void testRootTransaction(int expectedStatus) throws IOException { assertThat(request.getHeaders().get("Foo")).isEqualTo("abc"); - Response response = transaction.getContext().getResponse(); + ResponseImpl response = transaction.getContext().getResponse(); assertThat(response.getStatusCode()).isEqualTo(expectedStatus); assertThat(response.getHeaders().get("Bar")).isEqualTo("xyz"); @@ -149,7 +149,7 @@ void testChildTransaction() throws IOException { assertThat(httpResponse.code()).isEqualTo(200); assertThat(httpResponse.body().string()).isEmpty(); - TraceContext traceContext = reporter.getFirstTransaction(500).getTraceContext(); + TraceContextImpl traceContext = reporter.getFirstTransaction(500).getTraceContext(); assertThat(traceContext.getTraceId().toString()).isEqualTo("e00fef7cc6023c8e2c02d003cf50a266"); assertThat(traceContext.getParentId().toString()).isEqualTo("a048a11f61713b66"); diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/pom.xml b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/pom.xml index 9a726ec633..b87eb8bed6 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/pom.xml +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/pom.xml @@ -3,7 +3,7 @@ apm-jms-plugin co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsInstrumentationIT.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsInstrumentationIT.java index 8e57ce385b..e9d4282150 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsInstrumentationIT.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsInstrumentationIT.java @@ -21,15 +21,15 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.TracerInternalApiUtils; import co.elastic.apm.agent.impl.context.Headers; import co.elastic.apm.agent.impl.sampling.ConstantSampler; import co.elastic.apm.agent.impl.sampling.Sampler; -import co.elastic.apm.agent.impl.transaction.Id; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.IdImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; import jakarta.jms.Destination; @@ -70,7 +70,7 @@ @RunWith(Parameterized.class) public class JmsInstrumentationIT extends AbstractInstrumentationTest { - private static final String JMS_TRACE_PARENT_PROPERTY = TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME.replace('-', '_'); + private static final String JMS_TRACE_PARENT_PROPERTY = TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME.replace('-', '_'); // Keeping a static reference for resource cleaning private final static Set staticBrokerFacade = new HashSet<>(); @@ -78,7 +78,7 @@ public class JmsInstrumentationIT extends AbstractInstrumentationTest { private static final BlockingQueue resultQ = new ArrayBlockingQueue<>(5); private final BrokerFacade brokerFacade; - private final CoreConfiguration coreConfiguration; + private final CoreConfigurationImpl coreConfiguration; private final ThreadLocal receiveNoWaitFlow = new ThreadLocal<>(); private final ThreadLocal expectNoTraces = new ThreadLocal<>(); @@ -89,7 +89,7 @@ public JmsInstrumentationIT(BrokerFacade brokerFacade, Class receiveMethod, Queue queue, boolean sleepBetweenCycles, boolean disableTimestamp) throws Exception { final CancellableThread thread = new CancellableThread(() -> { - Transaction transaction = null; + TransactionImpl transaction = null; Message message = null; try { transaction = tracer.startRootTransaction(null); @@ -338,23 +338,23 @@ private void verifyQueueSendReceiveOnTracedThread(Queue queue, boolean disableTi assertThat(incomingMessage).isNotNull(); verifyMessage(message, incomingMessage); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); int numSpans = spans.size(); if (!receiveNoWaitFlow.get()) { assertThat(numSpans).isGreaterThanOrEqualTo(3); } final String sendToTestQueueSpanName = "JMS SEND to queue " + queue.getQueueName(); - List sendSpans = spans.stream().filter(span -> span.getNameAsString().equals(sendToTestQueueSpanName)).collect(Collectors.toList()); + List sendSpans = spans.stream().filter(span -> span.getNameAsString().equals(sendToTestQueueSpanName)).collect(Collectors.toList()); assertThat(sendSpans).hasSize(1); - Span sendSpan = sendSpans.get(0); + SpanImpl sendSpan = sendSpans.get(0); final String receiveFromTestQueueSpanName = "JMS RECEIVE from queue " + queue.getQueueName(); - List receiveSpans = spans.stream().filter(span -> span.getNameAsString().equals(receiveFromTestQueueSpanName)).collect(Collectors.toList()); + List receiveSpans = spans.stream().filter(span -> span.getNameAsString().equals(receiveFromTestQueueSpanName)).collect(Collectors.toList()); assertThat(receiveSpans).hasSize(1); - Span receiveSpan = receiveSpans.get(0); + SpanImpl receiveSpan = receiveSpans.get(0); final String sendToTestNoopQueueSpanName = "JMS SEND to queue NOOP"; - List sendToNoopSpans = spans.stream().filter(span -> span.getNameAsString().equals(sendToTestNoopQueueSpanName)).collect(Collectors.toList()); - Span sendToNoopSpan = null; + List sendToNoopSpans = spans.stream().filter(span -> span.getNameAsString().equals(sendToTestNoopQueueSpanName)).collect(Collectors.toList()); + SpanImpl sendToNoopSpan = null; if (!receiveNoWaitFlow.get()) { assertThat(sendToNoopSpans).hasSize(1); sendToNoopSpan = sendToNoopSpans.get(0); @@ -365,7 +365,7 @@ private void verifyQueueSendReceiveOnTracedThread(Queue queue, boolean disableTi assertThat(spans.stream().filter(span -> span.getNameAsString().equals(receiveWithNoMessageSpanName)).count()).isGreaterThanOrEqualTo(numSpans - 3); //noinspection ConstantConditions - Id currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); + IdImpl currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); assertThat(sendSpan.getTraceContext().getTraceId()).isEqualTo(currentTraceId); assertThat(sendSpan.getContext().getMessage().getQueueName()).isEqualTo(queue.getQueueName()); @@ -374,10 +374,10 @@ private void verifyQueueSendReceiveOnTracedThread(Queue queue, boolean disableTi .hasName(queue.getQueueName()) .hasDestinationResource("jms/" + queue.getQueueName()); - Id receiveTraceId = receiveSpan.getTraceContext().getTraceId(); - List receiveTransactions = reporter.getTransactions().stream().filter(transaction -> transaction.getTraceContext().getTraceId().equals(receiveTraceId)).collect(Collectors.toList()); + IdImpl receiveTraceId = receiveSpan.getTraceContext().getTraceId(); + List receiveTransactions = reporter.getTransactions().stream().filter(transaction -> transaction.getTraceContext().getTraceId().equals(receiveTraceId)).collect(Collectors.toList()); assertThat(receiveTransactions).hasSize(1); - Transaction receiveTransaction = receiveTransactions.get(0); + TransactionImpl receiveTransaction = receiveTransactions.get(0); assertThat(receiveSpan.getTraceContext().getParentId()).isEqualTo(receiveTransaction.getTraceContext().getId()); assertThat(receiveSpan.getContext().getMessage().getQueueName()).isEqualTo(queue.getQueueName()); // Body and headers should not be captured for receive spans @@ -389,7 +389,7 @@ private void verifyQueueSendReceiveOnTracedThread(Queue queue, boolean disableTi } else { assertThat(receiveSpan.getContext().getMessage().getAge()).isGreaterThanOrEqualTo(0); } - List spanLinks = receiveSpan.getSpanLinks(); + List spanLinks = receiveSpan.getSpanLinks(); assertThat(spanLinks).hasSize(1); assertThat(spanLinks.get(0).getTraceId()).isEqualTo(sendSpan.getTraceContext().getTraceId()); assertThat(spanLinks.get(0).getParentId()).isEqualTo(sendSpan.getTraceContext().getId()); @@ -416,7 +416,7 @@ private void verifyQueueSendReceiveOnNonTracedThread(Queue queue) assertThat(incomingMessage).isNotNull(); verifyMessage(message, incomingMessage); if (tracer.isRunning()) { - Transaction transaction = tracer.currentTransaction(); + TransactionImpl transaction = tracer.currentTransaction(); assertThat(transaction).isNotNull(); if (transaction.isSampled()) { verifySendReceiveOnNonTracedThread(queue.getQueueName(), outgoingMessage); @@ -427,9 +427,9 @@ private void verifyQueueSendReceiveOnNonTracedThread(Queue queue) private void verifySendListenOnNonTracedThread(String destinationName, TextMessage message, int expectedReadTransactions) throws JMSException { reporter.awaitTransactionCount(expectedReadTransactions); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(1); - Span sendSpan = spans.get(0); + SpanImpl sendSpan = spans.get(0); String spanName = sendSpan.getNameAsString(); assertThat(spanName).startsWith("JMS SEND to "); assertThat(spanName).endsWith(destinationName); @@ -442,12 +442,12 @@ private void verifySendListenOnNonTracedThread(String destinationName, TextMessa .hasDestinationResource("jms/" + destinationName); //noinspection ConstantConditions - Id currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); + IdImpl currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); assertThat(sendSpan.getTraceContext().getTraceId()).isEqualTo(currentTraceId); - List receiveTransactions = reporter.getTransactions(); + List receiveTransactions = reporter.getTransactions(); assertThat(receiveTransactions).hasSize(expectedReadTransactions); - for (Transaction receiveTransaction : receiveTransactions) { + for (TransactionImpl receiveTransaction : receiveTransactions) { assertThat(receiveTransaction.getNameAsString()).startsWith("JMS RECEIVE from "); assertThat(receiveTransaction.getNameAsString()).endsWith(destinationName); assertThat(receiveTransaction.getFrameworkName()).isEqualTo("JMS"); @@ -463,7 +463,7 @@ private void verifySendListenOnNonTracedThread(String destinationName, TextMessa } } - private void verifyMessageHeaders(Message message, Transaction receiveTransaction) throws JMSException { + private void verifyMessageHeaders(Message message, TransactionImpl receiveTransaction) throws JMSException { Map headersMap = new HashMap<>(); for (Headers.Header header : receiveTransaction.getContext().getMessage().getHeaders()) { headersMap.put(header.getKey(), header.getValue()); @@ -484,8 +484,8 @@ private void verifyMessageHeaders(Message message, Transaction receiveTransactio private void verifySendReceiveOnNonTracedThread(String destinationName, TextMessage message) throws JMSException { MessagingConfiguration.JmsStrategy strategy = config.getConfig(MessagingConfiguration.class).getMessagePollingTransactionStrategy(); - List spans = reporter.getSpans(); - List receiveTransactions = reporter.getTransactions(); + List spans = reporter.getSpans(); + List receiveTransactions = reporter.getTransactions(); if (expectNoTraces.get()) { assertThat(spans).isEmpty(); @@ -500,7 +500,7 @@ private void verifySendReceiveOnNonTracedThread(String destinationName, TextMess assertThat(spans).hasSize(2); } - Span sendInitialMessageSpan = spans.get(0); + SpanImpl sendInitialMessageSpan = spans.get(0); String spanName = sendInitialMessageSpan.getNameAsString(); assertThat(spanName).startsWith("JMS SEND to "); assertThat(spanName).endsWith(destinationName); @@ -514,7 +514,7 @@ private void verifySendReceiveOnNonTracedThread(String destinationName, TextMess .hasDestinationResource("jms/"+destinationName); //noinspection ConstantConditions - Id currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); + IdImpl currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); assertThat(sendInitialMessageSpan.getTraceContext().getTraceId()).isEqualTo(currentTraceId); if (!isActive) { @@ -526,8 +526,8 @@ private void verifySendReceiveOnNonTracedThread(String destinationName, TextMess assertThat(receiveTransactions).hasSize(1); } - Id transactionId = null; - for (Transaction receiveTransaction : receiveTransactions) { + IdImpl transactionId = null; + for (TransactionImpl receiveTransaction : receiveTransactions) { assertThat(receiveTransaction.getNameAsString()).startsWith("JMS RECEIVE from "); assertThat(receiveTransaction.getNameAsString()).endsWith(destinationName); if (receiveTransaction.getSpanLinks().isEmpty()) { @@ -547,7 +547,7 @@ private void verifySendReceiveOnNonTracedThread(String destinationName, TextMess } if (strategy != POLLING && !receiveNoWaitFlow.get()) { - Span sendNoopSpan = spans.get(1); + SpanImpl sendNoopSpan = spans.get(1); assertThat(sendNoopSpan.getNameAsString()).isEqualTo("JMS SEND to queue NOOP"); assertThat(sendNoopSpan.getTraceContext().getTraceId()).isEqualTo(currentTraceId); // If both polling and handling transactions are captured, handling transaction would come second diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsMessageListenerTest.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsMessageListenerTest.java index fcebcfda02..25645574f4 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsMessageListenerTest.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsMessageListenerTest.java @@ -21,9 +21,8 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import testapp.TestMessageConsumer; import testapp.TestMessageListener; import testapp.TestMsgHandler; @@ -71,7 +70,7 @@ private void startAgent(){ @Test public void testJmsMessageListenerPackage_defaultConfig() throws Exception { // default configuration - doReturn(Collections.emptyList()).when(config.getConfig(StacktraceConfiguration.class)).getApplicationPackages(); + doReturn(Collections.emptyList()).when(config.getConfig(StacktraceConfigurationImpl.class)).getApplicationPackages(); startAgent(); @@ -83,7 +82,7 @@ public void testJmsMessageListenerPackage_defaultConfig() throws Exception { @Test public void testJmsMessageListenerPackage_customValue() throws Exception { - doReturn(Collections.emptyList()).when(config.getConfig(StacktraceConfiguration.class)).getApplicationPackages(); + doReturn(Collections.emptyList()).when(config.getConfig(StacktraceConfigurationImpl.class)).getApplicationPackages(); doReturn(Arrays.asList("testapp")).when(config.getConfig(MessagingConfiguration.class)).getJmsListenerPackages(); startAgent(); @@ -96,7 +95,7 @@ public void testJmsMessageListenerPackage_customValue() throws Exception { @Test public void testJmsMessageListenerPackage_applicationPackages() throws Exception { - doReturn(Arrays.asList("testapp")).when(config.getConfig(StacktraceConfiguration.class)).getApplicationPackages(); + doReturn(Arrays.asList("testapp")).when(config.getConfig(StacktraceConfigurationImpl.class)).getApplicationPackages(); startAgent(); @@ -121,7 +120,7 @@ private void testJmsMessageListenerPackage(boolean expectIncluded, JmsMessageLis Message message = mock(Message.class); - AtomicReference transaction = new AtomicReference<>(); + AtomicReference transaction = new AtomicReference<>(); switch (variant){ case MATCHING_NAME_CONVENTION: @@ -137,7 +136,7 @@ private void testJmsMessageListenerPackage(boolean expectIncluded, JmsMessageLis case LAMBDA: // lambda is instrumented through wrapping on the message consumer MessageListener listener = msg -> { - transaction.set(GlobalTracer.get().require(Tracer.class).currentTransaction()); + transaction.set(GlobalTracer.get().require(ElasticApmTracer.class).currentTransaction()); }; TestMessageConsumer consumer = new TestMessageConsumer(); // listener should be wrapped on setter entry @@ -167,15 +166,15 @@ private void testJmsMessageListenerPackage(boolean expectIncluded, JmsMessageLis // will be instrumented by default as it's an inner class private static class InnerClassMsgHandler implements MessageListener { - private final AtomicReference transaction; + private final AtomicReference transaction; - public InnerClassMsgHandler(AtomicReference transaction) { + public InnerClassMsgHandler(AtomicReference transaction) { this.transaction = transaction; } @Override public void onMessage(Message message) { - transaction.set(GlobalTracer.get().require(Tracer.class).currentTransaction()); + transaction.set(GlobalTracer.get().require(ElasticApmTracer.class).currentTransaction()); } } diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsMessagePropertyAccessorTest.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsMessagePropertyAccessorTest.java index ffaf4cc65a..dd2ce6f909 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsMessagePropertyAccessorTest.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/co/elastic/apm/agent/jms/jakarta/JmsMessagePropertyAccessorTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.jms.jakarta; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageNotWriteableException; @@ -55,11 +55,11 @@ void setHeader() throws JMSException { doReturn(null).when(msg).getStringProperty(any(String.class)); - JmsMessagePropertyAccessor.instance().setHeader(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "header-value", msg); + JmsMessagePropertyAccessor.instance().setHeader(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "header-value", msg); verify(msg).setStringProperty(headerName.capture(), headerValue.capture()); - assertThat(headerName.getValue()).isEqualTo(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME.replace("-", "_")); + assertThat(headerName.getValue()).isEqualTo(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME.replace("-", "_")); assertThat(headerValue.getValue()).isEqualTo("header-value"); } diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/testapp/TestMessageListener.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/testapp/TestMessageListener.java index fe992bdba3..34795b42c2 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/testapp/TestMessageListener.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/testapp/TestMessageListener.java @@ -18,8 +18,8 @@ */ package testapp; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.GlobalTracer; import jakarta.jms.Message; @@ -28,14 +28,14 @@ public class TestMessageListener implements MessageListener { - private final AtomicReference transaction; + private final AtomicReference transaction; - public TestMessageListener(AtomicReference transaction) { + public TestMessageListener(AtomicReference transaction) { this.transaction = transaction; } @Override public void onMessage(Message message) { - transaction.set(GlobalTracer.get().require(Tracer.class).currentTransaction()); + transaction.set(GlobalTracer.get().require(ElasticApmTracer.class).currentTransaction()); } } diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/testapp/TestMsgHandler.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/testapp/TestMsgHandler.java index 4b9ce0c794..6ab2420feb 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/testapp/TestMsgHandler.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-jakarta/src/test/java/testapp/TestMsgHandler.java @@ -19,8 +19,8 @@ package testapp; -import co.elastic.apm.agent.impl.Tracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.GlobalTracer; import jakarta.jms.Message; @@ -30,14 +30,14 @@ // won't be instrumented by default as it does not fit naming conventions that we rely on by default public class TestMsgHandler implements MessageListener { - private final AtomicReference transaction; + private final AtomicReference transaction; - public TestMsgHandler(AtomicReference transaction) { + public TestMsgHandler(AtomicReference transaction) { this.transaction = transaction; } @Override public void onMessage(Message message) { - transaction.set(GlobalTracer.get().require(Tracer.class).currentTransaction()); + transaction.set(GlobalTracer.get().require(ElasticApmTracer.class).currentTransaction()); } } diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/pom.xml b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/pom.xml index abc79d7863..ab9b2b298c 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/pom.xml +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/pom.xml @@ -3,7 +3,7 @@ apm-jms-plugin co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsInstrumentationIT.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsInstrumentationIT.java index b7d4d4df51..4bf65629a9 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsInstrumentationIT.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsInstrumentationIT.java @@ -21,15 +21,15 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.TracerInternalApiUtils; import co.elastic.apm.agent.impl.context.Headers; import co.elastic.apm.agent.impl.sampling.ConstantSampler; import co.elastic.apm.agent.impl.sampling.Sampler; -import co.elastic.apm.agent.impl.transaction.Id; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.IdImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; import org.junit.After; @@ -70,7 +70,7 @@ @RunWith(Parameterized.class) public class JmsInstrumentationIT extends AbstractInstrumentationTest { - private static final String JMS_TRACE_PARENT_PROPERTY = TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME.replace('-', '_'); + private static final String JMS_TRACE_PARENT_PROPERTY = TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME.replace('-', '_'); // Keeping a static reference for resource cleaning private final static Set staticBrokerFacade = new HashSet<>(); @@ -78,7 +78,7 @@ public class JmsInstrumentationIT extends AbstractInstrumentationTest { private static final BlockingQueue resultQ = new ArrayBlockingQueue<>(5); private final BrokerFacade brokerFacade; - private final CoreConfiguration coreConfiguration; + private final CoreConfigurationImpl coreConfiguration; private final ThreadLocal receiveNoWaitFlow = new ThreadLocal<>(); private final ThreadLocal expectNoTraces = new ThreadLocal<>(); @@ -89,7 +89,7 @@ public JmsInstrumentationIT(BrokerFacade brokerFacade, Class receiveMethod, Queue queue, boolean sleepBetweenCycles, boolean disableTimestamp) throws Exception { final CancellableThread thread = new CancellableThread(() -> { - Transaction transaction = null; + TransactionImpl transaction = null; Message message = null; try { transaction = tracer.startRootTransaction(null); @@ -338,23 +338,23 @@ private void verifyQueueSendReceiveOnTracedThread(Queue queue, boolean disableTi assertThat(incomingMessage).isNotNull(); verifyMessage(message, incomingMessage); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); int numSpans = spans.size(); if (!receiveNoWaitFlow.get()) { assertThat(numSpans).isGreaterThanOrEqualTo(3); } final String sendToTestQueueSpanName = "JMS SEND to queue " + queue.getQueueName(); - List sendSpans = spans.stream().filter(span -> span.getNameAsString().equals(sendToTestQueueSpanName)).collect(Collectors.toList()); + List sendSpans = spans.stream().filter(span -> span.getNameAsString().equals(sendToTestQueueSpanName)).collect(Collectors.toList()); assertThat(sendSpans).hasSize(1); - Span sendSpan = sendSpans.get(0); + SpanImpl sendSpan = sendSpans.get(0); final String receiveFromTestQueueSpanName = "JMS RECEIVE from queue " + queue.getQueueName(); - List receiveSpans = spans.stream().filter(span -> span.getNameAsString().equals(receiveFromTestQueueSpanName)).collect(Collectors.toList()); + List receiveSpans = spans.stream().filter(span -> span.getNameAsString().equals(receiveFromTestQueueSpanName)).collect(Collectors.toList()); assertThat(receiveSpans).hasSize(1); - Span receiveSpan = receiveSpans.get(0); + SpanImpl receiveSpan = receiveSpans.get(0); final String sendToTestNoopQueueSpanName = "JMS SEND to queue NOOP"; - List sendToNoopSpans = spans.stream().filter(span -> span.getNameAsString().equals(sendToTestNoopQueueSpanName)).collect(Collectors.toList()); - Span sendToNoopSpan = null; + List sendToNoopSpans = spans.stream().filter(span -> span.getNameAsString().equals(sendToTestNoopQueueSpanName)).collect(Collectors.toList()); + SpanImpl sendToNoopSpan = null; if (!receiveNoWaitFlow.get()) { assertThat(sendToNoopSpans).hasSize(1); sendToNoopSpan = sendToNoopSpans.get(0); @@ -365,7 +365,7 @@ private void verifyQueueSendReceiveOnTracedThread(Queue queue, boolean disableTi assertThat(spans.stream().filter(span -> span.getNameAsString().equals(receiveWithNoMessageSpanName)).count()).isGreaterThanOrEqualTo(numSpans - 3); //noinspection ConstantConditions - Id currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); + IdImpl currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); assertThat(sendSpan.getTraceContext().getTraceId()).isEqualTo(currentTraceId); assertThat(sendSpan.getContext().getMessage().getQueueName()).isEqualTo(queue.getQueueName()); @@ -374,10 +374,10 @@ private void verifyQueueSendReceiveOnTracedThread(Queue queue, boolean disableTi .hasName(queue.getQueueName()) .hasDestinationResource("jms/" + queue.getQueueName()); - Id receiveTraceId = receiveSpan.getTraceContext().getTraceId(); - List receiveTransactions = reporter.getTransactions().stream().filter(transaction -> transaction.getTraceContext().getTraceId().equals(receiveTraceId)).collect(Collectors.toList()); + IdImpl receiveTraceId = receiveSpan.getTraceContext().getTraceId(); + List receiveTransactions = reporter.getTransactions().stream().filter(transaction -> transaction.getTraceContext().getTraceId().equals(receiveTraceId)).collect(Collectors.toList()); assertThat(receiveTransactions).hasSize(1); - Transaction receiveTransaction = receiveTransactions.get(0); + TransactionImpl receiveTransaction = receiveTransactions.get(0); assertThat(receiveSpan.getTraceContext().getParentId()).isEqualTo(receiveTransaction.getTraceContext().getId()); assertThat(receiveSpan.getContext().getMessage().getQueueName()).isEqualTo(queue.getQueueName()); // Body and headers should not be captured for receive spans @@ -389,7 +389,7 @@ private void verifyQueueSendReceiveOnTracedThread(Queue queue, boolean disableTi } else { assertThat(receiveSpan.getContext().getMessage().getAge()).isGreaterThanOrEqualTo(0); } - List spanLinks = receiveSpan.getSpanLinks(); + List spanLinks = receiveSpan.getSpanLinks(); assertThat(spanLinks).hasSize(1); assertThat(spanLinks.get(0).getTraceId()).isEqualTo(sendSpan.getTraceContext().getTraceId()); assertThat(spanLinks.get(0).getParentId()).isEqualTo(sendSpan.getTraceContext().getId()); @@ -416,7 +416,7 @@ private void verifyQueueSendReceiveOnNonTracedThread(Queue queue) assertThat(incomingMessage).isNotNull(); verifyMessage(message, incomingMessage); if (tracer.isRunning()) { - Transaction transaction = tracer.currentTransaction(); + TransactionImpl transaction = tracer.currentTransaction(); assertThat(transaction).isNotNull(); if (transaction.isSampled()) { verifySendReceiveOnNonTracedThread(queue.getQueueName(), outgoingMessage); @@ -427,9 +427,9 @@ private void verifyQueueSendReceiveOnNonTracedThread(Queue queue) private void verifySendListenOnNonTracedThread(String destinationName, TextMessage message, int expectedReadTransactions) throws JMSException { reporter.awaitTransactionCount(expectedReadTransactions); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(1); - Span sendSpan = spans.get(0); + SpanImpl sendSpan = spans.get(0); String spanName = sendSpan.getNameAsString(); assertThat(spanName).startsWith("JMS SEND to "); assertThat(spanName).endsWith(destinationName); @@ -442,12 +442,12 @@ private void verifySendListenOnNonTracedThread(String destinationName, TextMessa .hasDestinationResource("jms/" + destinationName); //noinspection ConstantConditions - Id currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); + IdImpl currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); assertThat(sendSpan.getTraceContext().getTraceId()).isEqualTo(currentTraceId); - List receiveTransactions = reporter.getTransactions(); + List receiveTransactions = reporter.getTransactions(); assertThat(receiveTransactions).hasSize(expectedReadTransactions); - for (Transaction receiveTransaction : receiveTransactions) { + for (TransactionImpl receiveTransaction : receiveTransactions) { assertThat(receiveTransaction.getNameAsString()).startsWith("JMS RECEIVE from "); assertThat(receiveTransaction.getNameAsString()).endsWith(destinationName); assertThat(receiveTransaction.getFrameworkName()).isEqualTo("JMS"); @@ -463,7 +463,7 @@ private void verifySendListenOnNonTracedThread(String destinationName, TextMessa } } - private void verifyMessageHeaders(Message message, Transaction receiveTransaction) throws JMSException { + private void verifyMessageHeaders(Message message, TransactionImpl receiveTransaction) throws JMSException { Map headersMap = new HashMap<>(); for (Headers.Header header : receiveTransaction.getContext().getMessage().getHeaders()) { headersMap.put(header.getKey(), header.getValue()); @@ -484,8 +484,8 @@ private void verifyMessageHeaders(Message message, Transaction receiveTransactio private void verifySendReceiveOnNonTracedThread(String destinationName, TextMessage message) throws JMSException { MessagingConfiguration.JmsStrategy strategy = config.getConfig(MessagingConfiguration.class).getMessagePollingTransactionStrategy(); - List spans = reporter.getSpans(); - List receiveTransactions = reporter.getTransactions(); + List spans = reporter.getSpans(); + List receiveTransactions = reporter.getTransactions(); if (expectNoTraces.get()) { assertThat(spans).isEmpty(); @@ -500,7 +500,7 @@ private void verifySendReceiveOnNonTracedThread(String destinationName, TextMess assertThat(spans).hasSize(2); } - Span sendInitialMessageSpan = spans.get(0); + SpanImpl sendInitialMessageSpan = spans.get(0); String spanName = sendInitialMessageSpan.getNameAsString(); assertThat(spanName).startsWith("JMS SEND to "); assertThat(spanName).endsWith(destinationName); @@ -514,7 +514,7 @@ private void verifySendReceiveOnNonTracedThread(String destinationName, TextMess .hasDestinationResource("jms/"+destinationName); //noinspection ConstantConditions - Id currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); + IdImpl currentTraceId = tracer.currentTransaction().getTraceContext().getTraceId(); assertThat(sendInitialMessageSpan.getTraceContext().getTraceId()).isEqualTo(currentTraceId); if (!isActive) { @@ -526,8 +526,8 @@ private void verifySendReceiveOnNonTracedThread(String destinationName, TextMess assertThat(receiveTransactions).hasSize(1); } - Id transactionId = null; - for (Transaction receiveTransaction : receiveTransactions) { + IdImpl transactionId = null; + for (TransactionImpl receiveTransaction : receiveTransactions) { assertThat(receiveTransaction.getNameAsString()).startsWith("JMS RECEIVE from "); assertThat(receiveTransaction.getNameAsString()).endsWith(destinationName); if (receiveTransaction.getSpanLinks().isEmpty()) { @@ -547,7 +547,7 @@ private void verifySendReceiveOnNonTracedThread(String destinationName, TextMess } if (strategy != POLLING && !receiveNoWaitFlow.get()) { - Span sendNoopSpan = spans.get(1); + SpanImpl sendNoopSpan = spans.get(1); assertThat(sendNoopSpan.getNameAsString()).isEqualTo("JMS SEND to queue NOOP"); assertThat(sendNoopSpan.getTraceContext().getTraceId()).isEqualTo(currentTraceId); // If both polling and handling transactions are captured, handling transaction would come second diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsMessageListenerTest.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsMessageListenerTest.java index 659373db7b..d6c27a89f7 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsMessageListenerTest.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsMessageListenerTest.java @@ -20,12 +20,11 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.Tracer; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Transaction; import testapp.TestMessageConsumer; import testapp.TestMessageListener; import testapp.TestMsgHandler; @@ -73,7 +72,7 @@ private void startAgent(){ @Test public void testJmsMessageListenerPackage_defaultConfig() throws Exception { // default configuration - doReturn(Collections.emptyList()).when(config.getConfig(StacktraceConfiguration.class)).getApplicationPackages(); + doReturn(Collections.emptyList()).when(config.getConfig(StacktraceConfigurationImpl.class)).getApplicationPackages(); startAgent(); @@ -85,7 +84,7 @@ public void testJmsMessageListenerPackage_defaultConfig() throws Exception { @Test public void testJmsMessageListenerPackage_customValue() throws Exception { - doReturn(Collections.emptyList()).when(config.getConfig(StacktraceConfiguration.class)).getApplicationPackages(); + doReturn(Collections.emptyList()).when(config.getConfig(StacktraceConfigurationImpl.class)).getApplicationPackages(); doReturn(Arrays.asList("testapp")).when(config.getConfig(MessagingConfiguration.class)).getJmsListenerPackages(); startAgent(); @@ -98,7 +97,7 @@ public void testJmsMessageListenerPackage_customValue() throws Exception { @Test public void testJmsMessageListenerPackage_applicationPackages() throws Exception { - doReturn(Arrays.asList("testapp")).when(config.getConfig(StacktraceConfiguration.class)).getApplicationPackages(); + doReturn(Arrays.asList("testapp")).when(config.getConfig(StacktraceConfigurationImpl.class)).getApplicationPackages(); startAgent(); @@ -123,7 +122,7 @@ private void testJmsMessageListenerPackage(boolean expectIncluded, JmsMessageLis Message message = mock(Message.class); - AtomicReference transaction = new AtomicReference<>(); + AtomicReference transaction = new AtomicReference<>(); switch (variant){ case MATCHING_NAME_CONVENTION: @@ -139,7 +138,7 @@ private void testJmsMessageListenerPackage(boolean expectIncluded, JmsMessageLis case LAMBDA: // lambda is instrumented through wrapping on the message consumer MessageListener listener = msg -> { - transaction.set(GlobalTracer.get().require(Tracer.class).currentTransaction()); + transaction.set(GlobalTracer.get().require(ElasticApmTracer.class).currentTransaction()); }; TestMessageConsumer consumer = new TestMessageConsumer(); // listener should be wrapped on setter entry @@ -169,15 +168,15 @@ private void testJmsMessageListenerPackage(boolean expectIncluded, JmsMessageLis // will be instrumented by default as it's an inner class private static class InnerClassMsgHandler implements MessageListener { - private final AtomicReference transaction; + private final AtomicReference transaction; - public InnerClassMsgHandler(AtomicReference transaction) { + public InnerClassMsgHandler(AtomicReference transaction) { this.transaction = transaction; } @Override public void onMessage(Message message) { - transaction.set(GlobalTracer.get().require(Tracer.class).currentTransaction()); + transaction.set(GlobalTracer.get().require(ElasticApmTracer.class).currentTransaction()); } } diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsMessagePropertyAccessorTest.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsMessagePropertyAccessorTest.java index bdf37d9663..5a6e49cbc7 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsMessagePropertyAccessorTest.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/co/elastic/apm/agent/jms/javax/JmsMessagePropertyAccessorTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.jms.javax; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -56,11 +56,11 @@ void setHeader() throws JMSException { doReturn(null).when(msg).getStringProperty(any(String.class)); - JmsMessagePropertyAccessor.instance().setHeader(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "header-value", msg); + JmsMessagePropertyAccessor.instance().setHeader(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME, "header-value", msg); verify(msg).setStringProperty(headerName.capture(), headerValue.capture()); - assertThat(headerName.getValue()).isEqualTo(TraceContext.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME.replace("-", "_")); + assertThat(headerName.getValue()).isEqualTo(TraceContextImpl.ELASTIC_TRACE_PARENT_TEXTUAL_HEADER_NAME.replace("-", "_")); assertThat(headerValue.getValue()).isEqualTo("header-value"); } diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/testapp/TestMessageListener.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/testapp/TestMessageListener.java index ab8425168a..ef5641c0a8 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/testapp/TestMessageListener.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/testapp/TestMessageListener.java @@ -18,9 +18,9 @@ */ package testapp; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import javax.jms.Message; import javax.jms.MessageListener; @@ -28,14 +28,14 @@ public class TestMessageListener implements MessageListener { - private final AtomicReference transaction; + private final AtomicReference transaction; - public TestMessageListener(AtomicReference transaction) { + public TestMessageListener(AtomicReference transaction) { this.transaction = transaction; } @Override public void onMessage(Message message) { - transaction.set(GlobalTracer.get().require(Tracer.class).currentTransaction()); + transaction.set(GlobalTracer.get().require(ElasticApmTracer.class).currentTransaction()); } } diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/testapp/TestMsgHandler.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/testapp/TestMsgHandler.java index 40e6186c45..a488190dc2 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/testapp/TestMsgHandler.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-javax/src/test/java/testapp/TestMsgHandler.java @@ -19,9 +19,9 @@ package testapp; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Transaction; import javax.jms.Message; import javax.jms.MessageListener; @@ -30,14 +30,14 @@ // won't be instrumented by default as it does not fit naming conventions that we rely on by default public class TestMsgHandler implements MessageListener { - private final AtomicReference transaction; + private final AtomicReference transaction; - public TestMsgHandler(AtomicReference transaction) { + public TestMsgHandler(AtomicReference transaction) { this.transaction = transaction; } @Override public void onMessage(Message message) { - transaction.set(GlobalTracer.get().require(Tracer.class).currentTransaction()); + transaction.set(GlobalTracer.get().require(ElasticApmTracer.class).currentTransaction()); } } diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/pom.xml b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/pom.xml index 0e622d9d62..ea785a8871 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/pom.xml +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/pom.xml @@ -5,7 +5,7 @@ apm-jms-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-jms-plugin-base diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java index f8929757ee..7fd3fb2feb 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-plugin-base/src/main/java/co/elastic/apm/agent/jms/JmsInstrumentationHelper.java @@ -22,7 +22,7 @@ import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.Transaction; @@ -219,7 +219,7 @@ public Object baseBeforeReceive(Class clazz, String methodName) { AbstractSpan createdSpan = null; boolean createPollingTransaction = false; boolean createPollingSpan = false; - final ElasticContext activeContext = tracer.currentContext(); + final TraceState activeContext = tracer.currentContext(); final AbstractSpan parentSpan = activeContext.getSpan(); if (parentSpan == null) { createPollingTransaction = true; diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/pom.xml b/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/pom.xml index 0d04d02c98..f45ee0fa4d 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/pom.xml +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/pom.xml @@ -5,7 +5,7 @@ apm-jms-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-jms-spring-plugin diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/src/test/java/co/elastic/apm/agent/jms/javax/spring/SpringJmsTest.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/src/test/java/co/elastic/apm/agent/jms/javax/spring/SpringJmsTest.java index dc4d176117..f710dc4fd9 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/src/test/java/co/elastic/apm/agent/jms/javax/spring/SpringJmsTest.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/src/test/java/co/elastic/apm/agent/jms/javax/spring/SpringJmsTest.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.jms.javax.spring; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Id; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.IdImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.command.ActiveMQMapMessage; import org.junit.AfterClass; @@ -71,7 +71,7 @@ public static void teardown() throws JMSException { public void testSendListenSpringQueue() throws JMSException, InterruptedException { try (Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) { - Transaction transaction = startTestRootTransaction("JMS-Spring-Test Transaction"); + TransactionImpl transaction = startTestRootTransaction("JMS-Spring-Test Transaction"); final String key1 = "key1"; final String key2 = "key2"; @@ -96,23 +96,23 @@ public void testSendListenSpringQueue() throws JMSException, InterruptedExceptio assertThat(result.get(key1).toString()).isEqualTo(value1); assertThat(result.get(key2).toString()).isEqualTo(value2); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions).hasSize(2); - Transaction baseTransaction = transactions.get(1); - Id traceId = baseTransaction.getTraceContext().getTraceId(); + TransactionImpl baseTransaction = transactions.get(1); + IdImpl traceId = baseTransaction.getTraceContext().getTraceId(); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(1); - Span sendSpan = spans.get(0); + SpanImpl sendSpan = spans.get(0); assertThat(sendSpan.getNameAsString()).isEqualTo("JMS SEND to queue " + SPRING_TEST_QUEUE); assertThat(sendSpan.getTraceContext().getTraceId()).isEqualTo(traceId); - Transaction receiveTransaction = transactions.get(0); + TransactionImpl receiveTransaction = transactions.get(0); verifyReceiveTransaction(traceId, sendSpan, receiveTransaction); } } - private void verifyReceiveTransaction(Id traceId, Span sendSpan, Transaction receiveTransaction) { + private void verifyReceiveTransaction(IdImpl traceId, SpanImpl sendSpan, TransactionImpl receiveTransaction) { assertThat(receiveTransaction.getNameAsString()).isEqualTo("JMS RECEIVE from queue " + SPRING_TEST_QUEUE); assertThat(receiveTransaction.getTraceContext().getTraceId()).isEqualTo(traceId); assertThat(receiveTransaction.getTraceContext().getParentId()).isEqualTo(sendSpan.getTraceContext().getId()); diff --git a/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/src/test/java/co/elastic/apm/agent/jms/javax/spring/SpringMapMessageListener.java b/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/src/test/java/co/elastic/apm/agent/jms/javax/spring/SpringMapMessageListener.java index 3f1e00aaa2..d599485918 100644 --- a/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/src/test/java/co/elastic/apm/agent/jms/javax/spring/SpringMapMessageListener.java +++ b/apm-agent-plugins/apm-jms-plugin/apm-jms-spring-plugin/src/test/java/co/elastic/apm/agent/jms/javax/spring/SpringMapMessageListener.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.jms.javax.spring; import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Transaction; import org.apache.activemq.command.ActiveMQMapMessage; import org.springframework.jms.listener.SessionAwareMessageListener; import org.springframework.stereotype.Service; @@ -46,7 +46,7 @@ public void onMessage(MapMessage mapMessage, Session session) throws JMSExceptio } System.out.println("Received map message: "); map.forEach((key, value) -> System.out.println(" " + key + " --> " + value)); - Transaction transaction = GlobalTracer.get().require(ElasticApmTracer.class).currentTransaction(); + TransactionImpl transaction = GlobalTracer.get().require(ElasticApmTracer.class).currentTransaction(); assertThat(transaction.isFinished()).isFalse(); SpringJmsTest.resultQueue.offer(map); } diff --git a/apm-agent-plugins/apm-jms-plugin/pom.xml b/apm-agent-plugins/apm-jms-plugin/pom.xml index 5b07b44250..4ca39439d7 100644 --- a/apm-agent-plugins/apm-jms-plugin/pom.xml +++ b/apm-agent-plugins/apm-jms-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-jms-plugin diff --git a/apm-agent-plugins/apm-jmx-plugin/pom.xml b/apm-agent-plugins/apm-jmx-plugin/pom.xml index 81b2140a16..20b22ae2d2 100644 --- a/apm-agent-plugins/apm-jmx-plugin/pom.xml +++ b/apm-agent-plugins/apm-jmx-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-jmx-plugin diff --git a/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetricTracker.java b/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetricTracker.java index 5c3733a639..6518f4f03e 100644 --- a/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetricTracker.java +++ b/apm-agent-plugins/apm-jmx-plugin/src/main/java/co/elastic/apm/agent/jmx/JmxMetricTracker.java @@ -46,6 +46,8 @@ import javax.management.ObjectInstance; import javax.management.ObjectName; import javax.management.RuntimeMBeanException; +import javax.management.MBeanException; +import javax.management.ReflectionException; import javax.management.openmbean.CompositeData; import javax.management.relation.MBeanServerNotificationFilter; import java.lang.management.ManagementFactory; @@ -367,31 +369,39 @@ private void addJmxMetricRegistration(final JmxMetric jmxMetric, List registrations, + MBeanServer server, + JmxMetric.Attribute attribute, + ObjectName objectName, + String attributeName, + @Nullable String metricPrepend) throws MBeanException, InstanceNotFoundException, ReflectionException { + + try { + Object value = server.getAttribute(objectName, attributeName); + addJmxMetricRegistration(jmxMetric, registrations, objectName, value, attribute, attributeName, metricPrepend); + } catch (AttributeNotFoundException e) { + logger.warn("Can't create metric '{}' because attribute '{}' could not be found", jmxMetric, attributeName); + } catch (RuntimeMBeanException e) { + if (e.getCause() instanceof UnsupportedOperationException) { + // silently ignore this attribute, won't retry as it's not a transient runtime exception + } else { + throw e; + } + } + } + private static boolean isWildcard(JmxMetric.Attribute attribute) { return "*".equals(attribute.getJmxAttributeName()); } @@ -486,7 +496,7 @@ public double get() { value = ((Number) ((CompositeData) server.getAttribute(objectName, jmxAttribute)).get(compositeDataKey)).doubleValue(); } return value; - } catch (InstanceNotFoundException | AttributeNotFoundException e) { + } catch (InstanceNotFoundException | AttributeNotFoundException | RuntimeMBeanException e) { if (unsubscribeOnError) { unregister(tracer); } diff --git a/apm-agent-plugins/apm-jsf-plugin/pom.xml b/apm-agent-plugins/apm-jsf-plugin/pom.xml index 49b7116c83..1148fe925a 100644 --- a/apm-agent-plugins/apm-jsf-plugin/pom.xml +++ b/apm-agent-plugins/apm-jsf-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-jsf-plugin diff --git a/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleExecuteInstrumentation.java b/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleExecuteInstrumentation.java index 46c43b3956..2481b123da 100644 --- a/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleExecuteInstrumentation.java +++ b/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleExecuteInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.jsf; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.Transaction; import net.bytebuddy.description.method.MethodDescription; @@ -46,7 +46,7 @@ static class BaseExecuteAdvice { @Nullable protected static Object createAndActivateSpan(boolean withExternalContext, @Nullable String requestServletPath, @Nullable String requestPathInfo) { - final ElasticContext activeContext = tracer.currentContext(); + final TraceState activeContext = tracer.currentContext(); if (activeContext.getSpan() instanceof Span) { Span parentSpan = (Span) activeContext.getSpan(); if (SPAN_SUBTYPE.equals(parentSpan.getSubtype()) && SPAN_ACTION.equals(parentSpan.getAction())) { diff --git a/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleRenderInstrumentation.java b/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleRenderInstrumentation.java index e098c4f499..e26ab550a9 100644 --- a/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleRenderInstrumentation.java +++ b/apm-agent-plugins/apm-jsf-plugin/src/main/java/co/elastic/apm/agent/jsf/AbstractJsfLifecycleRenderInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.jsf; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Span; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; @@ -64,7 +64,7 @@ public static class AdviceClass { @Nullable @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static Object createRenderSpan() { - final ElasticContext activeContext = tracer.currentContext(); + final TraceState activeContext = tracer.currentContext(); final AbstractSpan parentSpan = activeContext.getSpan(); if (parentSpan instanceof Span) { Span parSpan = (Span) parentSpan; diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/pom.xml b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/pom.xml index d218acb25c..b9fdc06b5e 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/pom.xml +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/pom.xml @@ -3,7 +3,7 @@ apm-kafka-plugin co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java index 385526a154..be030128f6 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/main/java/co/elastic/apm/agent/kafka/KafkaConsumerInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.kafka; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.Transaction; @@ -63,7 +63,7 @@ public static class KafkaPollEntryAdvice { @SuppressWarnings("unused") @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void pollStart() { - final ElasticContext activeContext = tracer.currentContext(); + final TraceState activeContext = tracer.currentContext(); final AbstractSpan activeSpan = activeContext.getSpan(); if (activeSpan == null) { return; diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyClientIT.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyClientIT.java index b11581c11d..716fcd27b6 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyClientIT.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-base-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyClientIT.java @@ -19,13 +19,13 @@ package co.elastic.apm.agent.kafka; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.context.Destination; -import co.elastic.apm.agent.impl.context.Message; -import co.elastic.apm.agent.impl.context.SpanContext; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.DestinationImpl; +import co.elastic.apm.agent.impl.context.MessageImpl; +import co.elastic.apm.agent.impl.context.SpanContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.testutils.TestContainersUtils; import org.apache.kafka.clients.consumer.ConsumerConfig; @@ -85,13 +85,13 @@ public class KafkaLegacyClientIT extends AbstractInstrumentationTest { private static KafkaConsumer replyConsumer; private static KafkaProducer producer; - private final CoreConfiguration coreConfiguration; + private final CoreConfigurationImpl coreConfiguration; private final MessagingConfiguration messagingConfiguration; private TestScenario testScenario; public KafkaLegacyClientIT() { - this.coreConfiguration = config.getConfig(CoreConfiguration.class); + this.coreConfiguration = config.getConfig(CoreConfigurationImpl.class); this.messagingConfiguration = config.getConfig(MessagingConfiguration.class); } @@ -140,7 +140,7 @@ public void startTransaction() { @After public void endTransaction() { - Transaction currentTransaction = tracer.currentTransaction(); + TransactionImpl currentTransaction = tracer.currentTransaction(); if (currentTransaction != null) { currentTransaction.deactivate().end(); } @@ -205,7 +205,7 @@ public void testSendTwoRecords_PartiallyIterate() { @Test public void testBodyCaptureEnabled() { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); testScenario = TestScenario.BODY_CAPTURE_ENABLED; consumerThread.setIterationMode(RecordIterationMode.ITERABLE_FOR); sendTwoRecordsAndConsumeReplies(); @@ -247,10 +247,10 @@ public void testIgnoreTopic() { sendTwoRecordsAndConsumeReplies(); // we expect only one span for polling the reply topic - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(1); verifyPollSpanContents(spans.get(0)); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions).isEmpty(); } @@ -274,22 +274,22 @@ private void sendTwoRecordsAndConsumeReplies() { } private void verifyTracing() { - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); // we expect two send spans to request topic and one poll span from reply topic assertThat(spans).hasSize(3); - Span sendRequestSpan0 = spans.get(0); + SpanImpl sendRequestSpan0 = spans.get(0); verifySendSpanContents(sendRequestSpan0); - Span sendRequestSpan1 = spans.get(1); + SpanImpl sendRequestSpan1 = spans.get(1); verifySendSpanContents(sendRequestSpan1); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions).isEmpty(); - Span pollSpan = spans.get(2); + SpanImpl pollSpan = spans.get(2); verifyPollSpanContents(pollSpan); } - private void verifyPollSpanContents(Span pollSpan) { + private void verifyPollSpanContents(SpanImpl pollSpan) { assertThat(pollSpan.getType()).isEqualTo("messaging"); assertThat(pollSpan.getSubtype()).isEqualTo("kafka"); assertThat(pollSpan.getAction()).isEqualTo("poll"); @@ -300,15 +300,15 @@ private void verifyPollSpanContents(Span pollSpan) { .hasNoName(); } - private void verifySendSpanContents(Span sendSpan) { + private void verifySendSpanContents(SpanImpl sendSpan) { assertThat(sendSpan.getType()).isEqualTo("messaging"); assertThat(sendSpan.getSubtype()).isEqualTo("kafka"); assertThat(sendSpan.getAction()).isEqualTo("send"); assertThat(sendSpan.getNameAsString()).isEqualTo("KafkaProducer#send to " + REQUEST_TOPIC); - SpanContext context = sendSpan.getContext(); - Message message = context.getMessage(); + SpanContextImpl context = sendSpan.getContext(); + MessageImpl message = context.getMessage(); assertThat(message.getQueueName()).isEqualTo(REQUEST_TOPIC); - Destination destination = context.getDestination(); + DestinationImpl destination = context.getDestination(); if (testScenario != TestScenario.TOPIC_ADDRESS_COLLECTION_DISABLED) { assertThat(destination.getPort()).isEqualTo(kafkaPort); assertThat(destination.getAddress().toString()).isEqualTo(kafka.getContainerIpAddress()); diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/pom.xml b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/pom.xml index 32acb0fda9..b968cfd1d7 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/pom.xml +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/pom.xml @@ -4,7 +4,7 @@ apm-kafka-plugin co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHeadersHelper.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHeadersHelper.java index 14cc72b372..1f107281ab 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHeadersHelper.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/main/java/co/elastic/apm/agent/kafka/helper/KafkaInstrumentationHeadersHelper.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.dispatch.HeaderUtils; @@ -116,7 +116,7 @@ public void addSpanLinks(@Nullable ConsumerRecords records, AbstractSpan toPropagate, ProducerRecord producerRecord) { + public void setOutgoingTraceContextHeaders(TraceState toPropagate, ProducerRecord producerRecord) { toPropagate.propagateContext(producerRecord, KafkaRecordHeaderAccessor.instance(), null); } diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT.java index 48508ca34c..c8bd0a16d9 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT.java @@ -20,19 +20,19 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.TracerInternalApiUtils; import co.elastic.apm.agent.impl.baggage.BaggageContext; -import co.elastic.apm.agent.impl.context.Destination; +import co.elastic.apm.agent.impl.context.DestinationImpl; import co.elastic.apm.agent.impl.context.Headers; -import co.elastic.apm.agent.impl.context.Message; -import co.elastic.apm.agent.impl.context.SpanContext; -import co.elastic.apm.agent.impl.context.TransactionContext; +import co.elastic.apm.agent.impl.context.MessageImpl; +import co.elastic.apm.agent.impl.context.SpanContextImpl; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; import co.elastic.apm.agent.impl.sampling.ConstantSampler; import co.elastic.apm.agent.impl.sampling.Sampler; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.testutils.TestContainersUtils; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; @@ -102,13 +102,13 @@ public class KafkaIT extends AbstractInstrumentationTest { private static KafkaConsumer replyConsumer; private static KafkaProducer producer; - private final CoreConfiguration coreConfiguration; + private final CoreConfigurationImpl coreConfiguration; private final MessagingConfiguration messagingConfiguration; private TestScenario testScenario; public KafkaIT() { - this.coreConfiguration = config.getConfig(CoreConfiguration.class); + this.coreConfiguration = config.getConfig(CoreConfigurationImpl.class); this.messagingConfiguration = config.getConfig(MessagingConfiguration.class); } @@ -153,7 +153,7 @@ public void startTransaction() { } private void startAndActivateTransaction(@Nullable Sampler sampler) { - Transaction transaction; + TransactionImpl transaction; if (sampler == null) { transaction = tracer.startRootTransaction(null); } else { @@ -170,7 +170,7 @@ private void startAndActivateTransaction(@Nullable Sampler sampler) { @After public void endTransaction() { - Transaction currentTransaction = tracer.currentTransaction(); + TransactionImpl currentTransaction = tracer.currentTransaction(); if (currentTransaction != null) { currentTransaction.deactivate().end(); } @@ -235,7 +235,7 @@ public void testSendTwoRecords_PartiallyIterate() { @Test public void testBodyCaptureEnabled() { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); testScenario = TestScenario.BODY_CAPTURE_ENABLED; consumerThread.setIterationMode(RecordIterationMode.ITERABLE_FOR); sendTwoRecordsAndConsumeReplies(); @@ -264,11 +264,11 @@ public void testBatchProcessing() { testScenario = TestScenario.BATCH_PROCESSING; consumerThread.setIterationMode(RecordIterationMode.ITERATE_WITHIN_TRANSACTION); sendTwoRecordsAndConsumeReplies(); - List sendSpans = + List sendSpans = reporter.getSpans().stream().filter(span -> span.getNameAsString().contains("send to " + REQUEST_TOPIC)).collect(Collectors.toList()); assertThat(sendSpans).hasSize(2); - Transaction batchProcessingTransaction = reporter.getFirstTransaction(); - verifySpanLinks(batchProcessingTransaction.getSpanLinks(), sendSpans.toArray(new Span[2])); + TransactionImpl batchProcessingTransaction = reporter.getFirstTransaction(); + verifySpanLinks(batchProcessingTransaction.getSpanLinks(), sendSpans.toArray(new SpanImpl[2])); } @Test @@ -289,10 +289,10 @@ public void testIgnoreTopic() { sendTwoRecordsAndConsumeReplies(); // we expect only one span for polling the reply topic - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans.size()).isGreaterThanOrEqualTo(1); verifyPollSpanContents(spans); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions).isEmpty(); } @@ -314,13 +314,13 @@ public void testTransactionCreationWithoutContext() { // We expect two transactions from records read from the request topic, each creating a send span as well. // In addition, we expect two transactions from the main test thread, iterating over reply messages. - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(2); - Span sendSpan1 = spans.get(0); + SpanImpl sendSpan1 = spans.get(0); verifySendSpanContents(sendSpan1, REPLY_TOPIC); - Span sendSpan2 = spans.get(1); + SpanImpl sendSpan2 = spans.get(1); verifySendSpanContents(sendSpan2, REPLY_TOPIC); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions).hasSize(4); verifyKafkaTransactionContents(transactions.get(0), null, null, REQUEST_TOPIC); verifyKafkaTransactionContents(transactions.get(1), null, null, REQUEST_TOPIC); @@ -397,29 +397,29 @@ private List> awaitReplyRecords(long timeoutMs, i } private void verifyTracing() { - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); // we expect two send spans to request topic, two send spans to reply topic and at least one poll span from reply topic assertThat(spans.size()).isGreaterThanOrEqualTo(5); - Span sendRequestSpan0 = spans.get(0); + SpanImpl sendRequestSpan0 = spans.get(0); verifySendSpanContents(sendRequestSpan0, REQUEST_TOPIC); - Span sendRequestSpan1 = spans.get(1); + SpanImpl sendRequestSpan1 = spans.get(1); verifySendSpanContents(sendRequestSpan1, REQUEST_TOPIC); - Span sendReplySpan0 = spans.get(2); + SpanImpl sendReplySpan0 = spans.get(2); verifySendSpanContents(sendReplySpan0, REPLY_TOPIC); - Span sendReplySpan1 = spans.get(3); + SpanImpl sendReplySpan1 = spans.get(3); verifySendSpanContents(sendReplySpan1, REPLY_TOPIC); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions).hasSize(2); verifyKafkaTransactionContents(transactions.get(0), sendRequestSpan0, FIRST_MESSAGE_VALUE, REQUEST_TOPIC); verifyKafkaTransactionContents(transactions.get(1), sendRequestSpan1, SECOND_MESSAGE_VALUE, REQUEST_TOPIC); - List pollSpans = spans.stream().filter(span -> !span.getSpanLinks().isEmpty()).collect(Collectors.toList()); + List pollSpans = spans.stream().filter(span -> !span.getSpanLinks().isEmpty()).collect(Collectors.toList()); verifyPollSpanContents(pollSpans, sendReplySpan0, sendReplySpan1); } - private void verifyPollSpanContents(List pollSpans, Span... sendSpans) { - List spanLinks = new ArrayList<>(); + private void verifyPollSpanContents(List pollSpans, SpanImpl... sendSpans) { + List spanLinks = new ArrayList<>(); // collecting Reply-Topic polling spans that returned with records pollSpans.forEach(pollSpan -> { assertThat(pollSpan.getType()).isEqualTo("messaging"); @@ -434,22 +434,22 @@ private void verifyPollSpanContents(List pollSpans, Span... sendSpans) { verifySpanLinks(spanLinks, sendSpans); } - private void verifySpanLinks(List spanLinks, Span... sendSpans) { + private void verifySpanLinks(List spanLinks, SpanImpl... sendSpans) { assertThat(spanLinks).hasSize(sendSpans.length); Arrays.stream(sendSpans).forEach( sendSpan -> assertThat(spanLinks.stream()).anyMatch(link -> link.getParentId().equals(sendSpan.getTraceContext().getId())) ); } - private void verifySendSpanContents(Span sendSpan, String topicName) { + private void verifySendSpanContents(SpanImpl sendSpan, String topicName) { assertThat(sendSpan.getType()).isEqualTo("messaging"); assertThat(sendSpan.getSubtype()).isEqualTo("kafka"); assertThat(sendSpan.getAction()).isEqualTo("send"); assertThat(sendSpan.getNameAsString()).isEqualTo("KafkaProducer#send to " + topicName); - SpanContext context = sendSpan.getContext(); - Message message = context.getMessage(); + SpanContextImpl context = sendSpan.getContext(); + MessageImpl message = context.getMessage(); assertThat(message.getQueueName()).isEqualTo(topicName); - Destination destination = context.getDestination(); + DestinationImpl destination = context.getDestination(); if (testScenario != TestScenario.TOPIC_ADDRESS_COLLECTION_DISABLED) { assertThat(destination.getPort()).isEqualTo(kafkaPort); assertThat(destination.getAddress().toString()).isEqualTo(kafka.getContainerIpAddress()); @@ -464,19 +464,19 @@ private void verifySendSpanContents(Span sendSpan, String topicName) { .hasDestinationResource("kafka/" + topicName); } - private void verifyKafkaTransactionContents(Transaction transaction, @Nullable Span parentSpan, + private void verifyKafkaTransactionContents(TransactionImpl transaction, @Nullable SpanImpl parentSpan, @Nullable String messageValue, String topic) { assertThat(transaction.getType()).isEqualTo("messaging"); assertThat(transaction.getNameAsString()).isEqualTo("Kafka record from " + topic); assertThat(transaction.getFrameworkName()).isEqualTo("Kafka"); - TraceContext traceContext = transaction.getTraceContext(); + TraceContextImpl traceContext = transaction.getTraceContext(); if (parentSpan != null) { assertThat(traceContext.getTraceId()).isEqualTo(parentSpan.getTraceContext().getTraceId()); assertThat(traceContext.getParentId()).isEqualTo(parentSpan.getTraceContext().getId()); } - TransactionContext transactionContext = transaction.getContext(); - Message message = transactionContext.getMessage(); + TransactionContextImpl transactionContext = transaction.getContext(); + MessageImpl message = transactionContext.getMessage(); assertThat(message.getAge()).isGreaterThanOrEqualTo(0); assertThat(message.getQueueName()).isEqualTo(topic); if (testScenario == TestScenario.BODY_CAPTURE_ENABLED && messageValue != null) { @@ -578,7 +578,7 @@ record = iterator.next(); producer.send(new ProducerRecord<>(REPLY_TOPIC, REPLY_KEY, record.value())); } } else if (iterationMode == RecordIterationMode.ITERATE_WITHIN_TRANSACTION) { - Transaction transaction = Objects.requireNonNull(tracer.startRootTransaction(null)) + TransactionImpl transaction = Objects.requireNonNull(tracer.startRootTransaction(null)) .withName("Batch-processing Transaction") .activate(); if (records.isEmpty()) { diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT_RealReporter.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT_RealReporter.java index 27029e47df..54c8b66757 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT_RealReporter.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaIT_RealReporter.java @@ -20,14 +20,14 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.report.Reporter; import co.elastic.apm.agent.testutils.TestContainersUtils; @@ -93,7 +93,7 @@ public class KafkaIT_RealReporter { private static KafkaConsumer replyConsumer; private static KafkaProducer producer; - private static CoreConfiguration coreConfiguration; + private static CoreConfigurationImpl coreConfiguration; private static MessagingConfiguration messagingConfiguration; private static TestScenario testScenario; @@ -126,7 +126,7 @@ public static void setup() { ); config = SpyConfiguration.createSpyConfig(); - StacktraceConfiguration stacktraceConfiguration = config.getConfig(StacktraceConfiguration.class); + StacktraceConfigurationImpl stacktraceConfiguration = config.getConfig(StacktraceConfigurationImpl.class); doReturn(30).when(stacktraceConfiguration).getStackTraceLimit(); tracer = new ElasticApmTracerBuilder() .configurationRegistry(config) @@ -135,7 +135,7 @@ public static void setup() { ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install()); testScenario = TestScenario.NORMAL; - coreConfiguration = config.getConfig(CoreConfiguration.class); + coreConfiguration = config.getConfig(CoreConfigurationImpl.class); messagingConfiguration = config.getConfig(MessagingConfiguration.class); } @@ -150,7 +150,7 @@ public static void tearDown() { @Before public void startTransaction() { - Transaction transaction; + TransactionImpl transaction; transaction = tracer.startRootTransaction(null); if (transaction != null) { transaction.activate() @@ -163,7 +163,7 @@ public void startTransaction() { @After public void endAndReportTransaction() { - Transaction currentTransaction = tracer.currentTransaction(); + TransactionImpl currentTransaction = tracer.currentTransaction(); if (currentTransaction != null) { currentTransaction.deactivate().end(); } @@ -222,7 +222,7 @@ public void testSendTwoRecords_PartiallyIterate() { @Test public void testBodyCaptureEnabled() { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); testScenario = TestScenario.BODY_CAPTURE_ENABLED; consumerThread.setIterationMode(RecordIterationMode.ITERABLE_FOR); sendTwoRecordsAndConsumeReplies(); @@ -391,7 +391,7 @@ record = iterator.next(); producer.send(new ProducerRecord<>(REPLY_TOPIC, REPLY_KEY, record.value())); } } else if (iterationMode == RecordIterationMode.ITERATE_WITHIN_TRANSACTION) { - Transaction transaction = Objects.requireNonNull(tracer.startRootTransaction(null)) + TransactionImpl transaction = Objects.requireNonNull(tracer.startRootTransaction(null)) .withName("Batch-processing Transaction") .activate(); if (records.isEmpty()) { diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyBrokerIT.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyBrokerIT.java index 309719dda4..f621d4c907 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyBrokerIT.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-headers-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaLegacyBrokerIT.java @@ -19,14 +19,14 @@ package co.elastic.apm.agent.kafka; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.context.Message; -import co.elastic.apm.agent.impl.context.SpanContext; -import co.elastic.apm.agent.impl.context.TransactionContext; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.MessageImpl; +import co.elastic.apm.agent.impl.context.SpanContextImpl; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.testutils.TestContainersUtils; import org.apache.kafka.clients.consumer.ConsumerConfig; @@ -87,13 +87,13 @@ public class KafkaLegacyBrokerIT extends AbstractInstrumentationTest { private static KafkaConsumer replyConsumer; private static KafkaProducer producer; - private final CoreConfiguration coreConfiguration; + private final CoreConfigurationImpl coreConfiguration; private final MessagingConfiguration messagingConfiguration; private TestScenario testScenario; public KafkaLegacyBrokerIT() { - this.coreConfiguration = config.getConfig(CoreConfiguration.class); + this.coreConfiguration = config.getConfig(CoreConfigurationImpl.class); this.messagingConfiguration = config.getConfig(MessagingConfiguration.class); } @@ -140,7 +140,7 @@ public void startTransaction() { @After public void endTransaction() { - Transaction currentTransaction = tracer.currentTransaction(); + TransactionImpl currentTransaction = tracer.currentTransaction(); if (currentTransaction != null) { currentTransaction.deactivate().end(); } @@ -205,7 +205,7 @@ public void testSendTwoRecords_PartiallyIterate() { @Test public void testBodyCaptureEnabled() { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); testScenario = TestScenario.BODY_CAPTURE_ENABLED; consumerThread.setIterationMode(RecordIterationMode.ITERABLE_FOR); sendTwoRecordsAndConsumeReplies(); @@ -230,10 +230,10 @@ public void testIgnoreTopic() { sendTwoRecordsAndConsumeReplies(); // we expect only one span for polling the reply topic - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(1); verifyPollSpanContents(spans.get(0)); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions).isEmpty(); } @@ -250,13 +250,13 @@ public void testTransactionCreationWithoutContext() { // We expect two transactions from records read from the request topic, each creating a send span as well. // In addition we expect two transactions from the main test thread, iterating over reply messages. - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(2); - Span sendSpan1 = spans.get(0); + SpanImpl sendSpan1 = spans.get(0); verifySendSpanContents(sendSpan1, REPLY_TOPIC); - Span sendSpan2 = spans.get(1); + SpanImpl sendSpan2 = spans.get(1); verifySendSpanContents(sendSpan2, REPLY_TOPIC); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions).hasSize(4); verifyKafkaTransactionContents(transactions.get(0), null, null, REQUEST_TOPIC); verifyKafkaTransactionContents(transactions.get(1), null, null, REQUEST_TOPIC); @@ -287,28 +287,28 @@ private void sendTwoRecordsAndConsumeReplies() { } private void verifyTracing() { - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); // we expect two send spans to request topic, two send spans to reply topic and one poll span from reply topic assertThat(spans).hasSize(5); - Span sendRequestSpan0 = spans.get(0); + SpanImpl sendRequestSpan0 = spans.get(0); verifySendSpanContents(sendRequestSpan0, REQUEST_TOPIC); - Span sendRequestSpan1 = spans.get(1); + SpanImpl sendRequestSpan1 = spans.get(1); verifySendSpanContents(sendRequestSpan1, REQUEST_TOPIC); - Span sendReplySpan0 = spans.get(2); + SpanImpl sendReplySpan0 = spans.get(2); verifySendSpanContents(sendReplySpan0, REPLY_TOPIC); - Span sendReplySpan1 = spans.get(3); + SpanImpl sendReplySpan1 = spans.get(3); verifySendSpanContents(sendReplySpan1, REPLY_TOPIC); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions).hasSize(2); verifyKafkaTransactionContents(transactions.get(0), sendRequestSpan0, FIRST_MESSAGE_VALUE, REQUEST_TOPIC); verifyKafkaTransactionContents(transactions.get(1), sendRequestSpan1, SECOND_MESSAGE_VALUE, REQUEST_TOPIC); - Span pollSpan = spans.get(4); + SpanImpl pollSpan = spans.get(4); verifyPollSpanContents(pollSpan); } - private void verifyPollSpanContents(Span pollSpan) { + private void verifyPollSpanContents(SpanImpl pollSpan) { assertThat(pollSpan.getType()).isEqualTo("messaging"); assertThat(pollSpan.getSubtype()).isEqualTo("kafka"); assertThat(pollSpan.getAction()).isEqualTo("poll"); @@ -320,13 +320,13 @@ private void verifyPollSpanContents(Span pollSpan) { .hasDestinationResource("kafka"); } - private void verifySendSpanContents(Span sendSpan, String topicName) { + private void verifySendSpanContents(SpanImpl sendSpan, String topicName) { assertThat(sendSpan.getType()).isEqualTo("messaging"); assertThat(sendSpan.getSubtype()).isEqualTo("kafka"); assertThat(sendSpan.getAction()).isEqualTo("send"); assertThat(sendSpan.getNameAsString()).isEqualTo("KafkaProducer#send to " + topicName); - SpanContext context = sendSpan.getContext(); - Message message = context.getMessage(); + SpanContextImpl context = sendSpan.getContext(); + MessageImpl message = context.getMessage(); assertThat(message.getQueueName()).isEqualTo(topicName); assertThat(context.getServiceTarget()) @@ -335,17 +335,17 @@ private void verifySendSpanContents(Span sendSpan, String topicName) { .hasDestinationResource("kafka/" + topicName); } - private void verifyKafkaTransactionContents(Transaction transaction, @Nullable Span parentSpan, + private void verifyKafkaTransactionContents(TransactionImpl transaction, @Nullable SpanImpl parentSpan, @Nullable String messageValue, String topic) { assertThat(transaction.getType()).isEqualTo("messaging"); assertThat(transaction.getNameAsString()).isEqualTo("Kafka record from " + topic); - TraceContext traceContext = transaction.getTraceContext(); + TraceContextImpl traceContext = transaction.getTraceContext(); if (parentSpan != null) { assertThat(traceContext.getTraceId()).isNotEqualTo(parentSpan.getTraceContext().getTraceId()); assertThat(traceContext.getParentId()).isNotEqualTo(parentSpan.getTraceContext().getId()); } - TransactionContext transactionContext = transaction.getContext(); - Message message = transactionContext.getMessage(); + TransactionContextImpl transactionContext = transaction.getContext(); + MessageImpl message = transactionContext.getMessage(); assertThat(message.getAge()).isGreaterThanOrEqualTo(0); assertThat(message.getQueueName()).isEqualTo(topic); if (testScenario == TestScenario.BODY_CAPTURE_ENABLED && messageValue != null) { diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/pom.xml b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/pom.xml index ff03892222..de89a04e68 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/pom.xml +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/pom.xml @@ -4,7 +4,7 @@ apm-kafka-plugin co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaSpringIT.java b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaSpringIT.java index 7cabf3bd58..f5a78516d7 100644 --- a/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaSpringIT.java +++ b/apm-agent-plugins/apm-kafka-plugin/apm-kafka-spring-plugin/src/test/java/co/elastic/apm/agent/kafka/KafkaSpringIT.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.kafka; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.testutils.TestContainersUtils; import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.clients.producer.ProducerConfig; @@ -85,23 +85,23 @@ public static void tearDown() { @Test public void testBatchReceive() { - Transaction transaction1 = startTestRootTransaction("Send 1"); + TransactionImpl transaction1 = startTestRootTransaction("Send 1"); kafkaTemplate.send(BATCH_TOPIC, "data-1"); transaction1.deactivate().end(); - Transaction transaction2 = startTestRootTransaction("Send 2"); + TransactionImpl transaction2 = startTestRootTransaction("Send 2"); kafkaTemplate.send(BATCH_TOPIC, "data-2"); transaction2.deactivate().end(); reporter.awaitTransactionCount(3, 10000); reporter.awaitSpanCount(3); //two kafka exit spans + the batchListener span - List senderSpans = reporter.getSpans().stream() - .filter(AbstractSpan::isExit) + List senderSpans = reporter.getSpans().stream() + .filter(AbstractSpanImpl::isExit) .collect(Collectors.toList()); assertThat(senderSpans).hasSize(2); - Transaction batchReceive = reporter.getTransactions().stream() + TransactionImpl batchReceive = reporter.getTransactions().stream() .filter(transaction -> transaction.getNameAsString().equals("Spring Kafka Message Batch Processing")) .findFirst().orElse(null); @@ -111,7 +111,7 @@ public void testBatchReceive() { .hasSpanLink(senderSpans.get(0)) .hasSpanLink(senderSpans.get(1)); - Span listenerSpan = reporter.getSpanByName("batchListener"); + SpanImpl listenerSpan = reporter.getSpanByName("batchListener"); assertThat(listenerSpan) .isNotNull() .hasParent(batchReceive); @@ -121,20 +121,20 @@ public void testBatchReceive() { // it just verifies that non-batch listeners are caught by the standard kafka instrumentation @Test public void testNonBatchSingleReceive() { - Transaction transaction1 = startTestRootTransaction("Send 1"); + TransactionImpl transaction1 = startTestRootTransaction("Send 1"); kafkaTemplate.send(SINGLE_TOPIC, "data-1"); transaction1.deactivate().end(); reporter.awaitTransactionCount(2, 10000); reporter.awaitSpanCount(2); //one kafka exit spans + the singleListener span - Span senderSpan = reporter.getSpans().stream() - .filter(AbstractSpan::isExit) + SpanImpl senderSpan = reporter.getSpans().stream() + .filter(AbstractSpanImpl::isExit) .findFirst().orElse(null); assertThat(senderSpan).isNotNull(); - Transaction singleReceive = reporter.getTransactions().stream() + TransactionImpl singleReceive = reporter.getTransactions().stream() .filter(transaction -> "messaging".equals(transaction.getType())) .findFirst().orElse(null); @@ -142,7 +142,7 @@ public void testNonBatchSingleReceive() { .isNotNull() .hasParent(senderSpan); - Span listenerSpan = reporter.getSpanByName("singleListener"); + SpanImpl listenerSpan = reporter.getSpanByName("singleListener"); assertThat(listenerSpan) .isNotNull() .hasParent(singleReceive); diff --git a/apm-agent-plugins/apm-kafka-plugin/pom.xml b/apm-agent-plugins/apm-kafka-plugin/pom.xml index dec07b0e32..5a97ca94bd 100644 --- a/apm-agent-plugins/apm-kafka-plugin/pom.xml +++ b/apm-agent-plugins/apm-kafka-plugin/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/pom.xml index 7da7970da7..b42612dc96 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/pom.xml @@ -5,7 +5,7 @@ apm-logging-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-jboss-logging-plugin diff --git a/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/src/test/java/co/elastic/apm/agent/jbosslogging/correlation/JBossLogManagerCorrelationInstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/src/test/java/co/elastic/apm/agent/jbosslogging/correlation/JBossLogManagerCorrelationInstrumentationTest.java index 081905a8de..9de71a7a0e 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/src/test/java/co/elastic/apm/agent/jbosslogging/correlation/JBossLogManagerCorrelationInstrumentationTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/src/test/java/co/elastic/apm/agent/jbosslogging/correlation/JBossLogManagerCorrelationInstrumentationTest.java @@ -20,9 +20,9 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.impl.TextHeaderMapAccessor; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.loginstr.correlation.AbstractLogCorrelationHelper; import org.jboss.logmanager.ExtHandler; import org.jboss.logmanager.ExtLogRecord; @@ -38,7 +38,7 @@ import java.util.Map; import java.util.Objects; -import static co.elastic.apm.agent.impl.transaction.TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME; +import static co.elastic.apm.agent.impl.transaction.TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME; import static org.assertj.core.api.Assertions.assertThat; public class JBossLogManagerCorrelationInstrumentationTest extends AbstractInstrumentationTest { @@ -48,7 +48,7 @@ public class JBossLogManagerCorrelationInstrumentationTest extends AbstractInstr private static final LoggingCorrelationVerifier loggingCorrelationVerifier = new LoggingCorrelationVerifier(); private static Logger logger; - private Transaction transaction; + private TransactionImpl transaction; @BeforeAll static void initializeLogger() { @@ -115,14 +115,14 @@ protected void doPublish(ExtLogRecord record) { String traceParent = record.getMessage(); assertThat(traceParent).isNotNull(); Map textHeaderMap = Map.of(W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, traceParent); - TraceContext childTraceContext = TraceContext.with64BitId(tracer); + TraceContextImpl childTraceContext = TraceContextImpl.with64BitId(tracer); childTraceContext.asChildOf(textHeaderMap, TextHeaderMapAccessor.INSTANCE); System.out.println("childTraceContext = " + childTraceContext); assertThat(childTraceContext.getTraceId().toString()).isEqualTo(traceId.toString()); assertThat(childTraceContext.getParentId().toString()).isEqualTo(transactionId.toString()); if (shouldContainErrorId) { assertThat(errorId).isNotNull(); - ErrorCapture activeError = ErrorCapture.getActive(); + ErrorCaptureImpl activeError = ErrorCaptureImpl.getActive(); assertThat(activeError).isNotNull(); assertThat(activeError.getTraceContext().getId().toString()).isEqualTo(errorId.toString()); } else { diff --git a/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/src/test/java/co/elastic/apm/agent/jbosslogging/correlation/JBossLoggingCorrelationInstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/src/test/java/co/elastic/apm/agent/jbosslogging/correlation/JBossLoggingCorrelationInstrumentationTest.java index af869e005f..60062911d7 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/src/test/java/co/elastic/apm/agent/jbosslogging/correlation/JBossLoggingCorrelationInstrumentationTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-jboss-logging-plugin/src/test/java/co/elastic/apm/agent/jbosslogging/correlation/JBossLoggingCorrelationInstrumentationTest.java @@ -20,9 +20,9 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.impl.TextHeaderMapAccessor; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.loginstr.correlation.AbstractLogCorrelationHelper; import org.jboss.logging.Logger; import org.jboss.logging.MDC; @@ -37,7 +37,7 @@ import java.util.logging.Handler; import java.util.logging.LogRecord; -import static co.elastic.apm.agent.impl.transaction.TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME; +import static co.elastic.apm.agent.impl.transaction.TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME; import static org.assertj.core.api.Assertions.assertThat; public class JBossLoggingCorrelationInstrumentationTest extends AbstractInstrumentationTest { @@ -47,7 +47,7 @@ public class JBossLoggingCorrelationInstrumentationTest extends AbstractInstrume private static final LoggingCorrelationVerifier loggingCorrelationVerifier = new LoggingCorrelationVerifier(); private static Logger logger; - private Transaction transaction; + private TransactionImpl transaction; @BeforeAll static void initializeLogger() { @@ -119,14 +119,14 @@ public void publish(LogRecord record) { String traceParent = record.getMessage(); assertThat(traceParent).isNotNull(); Map textHeaderMap = Map.of(W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, traceParent); - TraceContext childTraceContext = TraceContext.with64BitId(tracer); + TraceContextImpl childTraceContext = TraceContextImpl.with64BitId(tracer); childTraceContext.asChildOf(textHeaderMap, TextHeaderMapAccessor.INSTANCE); System.out.println("childTraceContext = " + childTraceContext); assertThat(childTraceContext.getTraceId().toString()).isEqualTo(traceId.toString()); assertThat(childTraceContext.getParentId().toString()).isEqualTo(transactionId.toString()); if (shouldContainErrorId) { assertThat(errorId).isNotNull(); - ErrorCapture activeError = ErrorCapture.getActive(); + ErrorCaptureImpl activeError = ErrorCaptureImpl.getActive(); assertThat(activeError).isNotNull(); assertThat(activeError.getTraceContext().getId().toString()).isEqualTo(errorId.toString()); } else { diff --git a/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/pom.xml index 1392013f6d..db37c7ad82 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-jul-plugin/pom.xml @@ -5,7 +5,7 @@ apm-logging-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-jul-plugin diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/pom.xml index 80273cbcb6..c16057dc69 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j1-plugin/pom.xml @@ -5,7 +5,7 @@ apm-logging-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-log4j1-plugin diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml index fca47ca9c4..e783ce77ae 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/pom.xml @@ -5,7 +5,7 @@ apm-logging-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-log4j2-plugin diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java index 4d5ab75fa7..e8cfe0480a 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTest.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.loginstr.LoggingInstrumentationTest; import co.elastic.apm.agent.loginstr.LoggerFacade; -import co.elastic.apm.agent.logging.LoggingConfiguration; +import co.elastic.apm.agent.logging.LoggingConfigurationImpl; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Marker; @@ -36,8 +36,6 @@ import java.net.URI; import java.net.URISyntaxException; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.List; import java.util.Objects; @@ -57,7 +55,7 @@ static void resetConfigFactory() { @AfterAll static void reInitLogging() { - LoggingConfiguration.init(List.of(), ""); + LoggingConfigurationImpl.init(List.of(), ""); } private static final Marker TEST_MARKER = MarkerManager.getMarker("TEST"); diff --git a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java index d6a5fc3278..302f0132f5 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-log4j2-plugin/src/test/java/co/elastic/apm/agent/log4j2/Log4j2InstrumentationTestVersions.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.log4j2; import co.elastic.apm.agent.testutils.JUnit4TestClassWithDependencyRunner; -import co.elastic.apm.agent.logging.LoggingConfiguration; +import co.elastic.apm.agent.logging.LoggingConfigurationImpl; import org.apache.logging.log4j.core.config.ConfigurationFactory; import org.junit.After; import org.junit.AfterClass; @@ -47,7 +47,7 @@ public static void resetConfigFactory() { @AfterClass public static void reInitLogging() { - LoggingConfiguration.init(List.of(), ""); + LoggingConfigurationImpl.init(List.of(), ""); } @Before diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/pom.xml index 3897841872..f7bbb07d4f 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-impl/pom.xml @@ -5,7 +5,7 @@ apm-logback-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-logback-plugin-impl diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-legacy-tests/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-legacy-tests/pom.xml index 426dea6531..4fd0893477 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-legacy-tests/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/apm-logback-plugin-legacy-tests/pom.xml @@ -5,7 +5,7 @@ apm-logback-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-logback-plugin-legacy-tests diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/pom.xml index 75cbe6eb81..c1bb26be24 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-logback-plugin/pom.xml @@ -5,7 +5,7 @@ apm-logging-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-logback-plugin diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/pom.xml index 9b53276ce6..aa15887e3d 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/pom.xml @@ -5,7 +5,7 @@ apm-logging-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-logging-plugin-common diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java index 623c854314..041df393c4 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/main/java/co/elastic/apm/agent/loginstr/reformatting/AbstractEcsReformattingHelper.java @@ -28,11 +28,8 @@ import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import co.elastic.apm.agent.tracer.Tracer; -import co.elastic.apm.agent.tracer.configuration.CoreConfiguration; import co.elastic.apm.agent.tracer.configuration.LoggingConfiguration; -import co.elastic.apm.agent.tracer.configuration.ServerlessConfiguration; import co.elastic.apm.agent.tracer.service.Service; -import co.elastic.apm.agent.tracer.service.ServiceAwareTracer; import javax.annotation.Nullable; import java.util.List; diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/LoggingInstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/LoggingInstrumentationTest.java index 422fcc9b2e..b7b5a5d110 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/LoggingInstrumentationTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/LoggingInstrumentationTest.java @@ -19,12 +19,12 @@ package co.elastic.apm.agent.loginstr; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.LogEcsReformatting; -import co.elastic.apm.agent.logging.LoggingConfiguration; +import co.elastic.apm.agent.logging.LoggingConfigurationImpl; import co.elastic.apm.agent.logging.TestUtils; import co.elastic.apm.agent.loginstr.correlation.AbstractLogCorrelationHelper; import co.elastic.apm.agent.loginstr.reformatting.Utils; @@ -75,10 +75,10 @@ public abstract class LoggingInstrumentationTest extends AbstractInstrumentation private final SimpleDateFormat timestampFormat; private final SimpleDateFormat utcTimestampFormat; - private LoggingConfiguration loggingConfig; + private LoggingConfigurationImpl loggingConfig; private String serviceName; - private Transaction transaction; - private Span childSpan; + private TransactionImpl transaction; + private SpanImpl childSpan; public LoggingInstrumentationTest() { logger = createLoggerFacade(); @@ -91,11 +91,11 @@ public LoggingInstrumentationTest() { @Before @BeforeEach public void setup() throws Exception { - doReturn(SERVICE_VERSION).when(config.getConfig(CoreConfiguration.class)).getServiceVersion(); - doReturn(ENVIRONMENT).when(config.getConfig(CoreConfiguration.class)).getEnvironment(); - doReturn(SERVICE_NODE_NAME).when(config.getConfig(CoreConfiguration.class)).getServiceNodeName(); + doReturn(SERVICE_VERSION).when(config.getConfig(CoreConfigurationImpl.class)).getServiceVersion(); + doReturn(ENVIRONMENT).when(config.getConfig(CoreConfigurationImpl.class)).getEnvironment(); + doReturn(SERVICE_NODE_NAME).when(config.getConfig(CoreConfigurationImpl.class)).getServiceNodeName(); - loggingConfig = config.getConfig(LoggingConfiguration.class); + loggingConfig = config.getConfig(LoggingConfigurationImpl.class); doReturn(ADDITIONAL_FIELDS).when(loggingConfig).getLogEcsReformattingAdditionalFields(); logger.open(); @@ -354,7 +354,7 @@ private void verifyErrorCaptureAndCorrelation(boolean isErrorLine, JsonNode ecsL final JsonNode errorJsonNode = ecsLogLineTree.get(AbstractLogCorrelationHelper.ERROR_ID_MDC_KEY); if (isErrorLine) { assertThat(errorJsonNode).describedAs("missing error ID").isNotNull(); - List errors = reporter.getErrors().stream() + List errors = reporter.getErrors().stream() .filter(error -> errorJsonNode.textValue().equals(error.getTraceContext().getId().toString())) .collect(Collectors.toList()); assertThat(errors).hasSize(1); diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/correlation/CorrelationIdMapAdapterTest.java b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/correlation/CorrelationIdMapAdapterTest.java index 6b7e3037fe..0e225ca6ea 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/correlation/CorrelationIdMapAdapterTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/correlation/CorrelationIdMapAdapterTest.java @@ -21,8 +21,8 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Scope; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -53,7 +53,7 @@ void testNoContext() { @Test void testTransactionContext() { - Transaction transaction = tracer.startRootTransaction(null); + TransactionImpl transaction = tracer.startRootTransaction(null); try (Scope scope = transaction.activateInScope()) { assertThat(CorrelationIdMapAdapter.get()).containsOnlyKeys("trace.id", "transaction.id"); } finally { @@ -64,8 +64,8 @@ void testTransactionContext() { @Test void testSpanContext() { - Transaction transaction = tracer.startRootTransaction(null); - Span span = transaction.createSpan(); + TransactionImpl transaction = tracer.startRootTransaction(null); + SpanImpl span = transaction.createSpan(); try (Scope scope = span.activateInScope()) { assertThat(CorrelationIdMapAdapter.get()).containsOnlyKeys("trace.id", "transaction.id"); } finally { diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/error/AbstractErrorLoggingInstrumentationTest.java b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/error/AbstractErrorLoggingInstrumentationTest.java index bfe0fbce37..fb21844018 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/error/AbstractErrorLoggingInstrumentationTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/error/AbstractErrorLoggingInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.loginstr.error; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -28,7 +28,7 @@ public abstract class AbstractErrorLoggingInstrumentationTest extends AbstractInstrumentationTest { - private Transaction transaction; + private TransactionImpl transaction; @BeforeEach void startTransaction() { diff --git a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/reformatting/UtilsTest.java b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/reformatting/UtilsTest.java index 8cf473a39c..75431e1f35 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/reformatting/UtilsTest.java +++ b/apm-agent-plugins/apm-logging-plugin/apm-logging-plugin-common/src/test/java/co/elastic/apm/agent/loginstr/reformatting/UtilsTest.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.tracer.configuration.LogEcsReformatting; -import co.elastic.apm.agent.logging.LoggingConfiguration; +import co.elastic.apm.agent.logging.LoggingConfigurationImpl; import org.junit.jupiter.api.Test; import javax.annotation.Nullable; @@ -33,7 +33,7 @@ public class UtilsTest extends AbstractInstrumentationTest { private static final String fileSeparator = System.getProperty("file.separator"); @Nullable - private final String logEcsFormattingDestinationDir = config.getConfig(LoggingConfiguration.class).getLogEcsFormattingDestinationDir(); + private final String logEcsFormattingDestinationDir = config.getConfig(LoggingConfigurationImpl.class).getLogEcsFormattingDestinationDir(); private String computeReformattedLogFilePathWithConfiguredDir(String logFilePath) { return Utils.computeLogReformattingFilePath(logFilePath, logEcsFormattingDestinationDir); @@ -49,7 +49,7 @@ void testReformattedPathComputation() { @Test void testReplace() { - doReturn(LogEcsReformatting.REPLACE).when(config.getConfig(LoggingConfiguration.class)).getLogEcsReformatting(); + doReturn(LogEcsReformatting.REPLACE).when(config.getConfig(LoggingConfigurationImpl.class)).getLogEcsReformatting(); assertThat(computeReformattedLogFilePathWithConfiguredDir("/test/absolute/path/app.log")).isEqualTo(replaceFileSeparator("/test/absolute/path/app.ecs.json")); assertThat(computeReformattedLogFilePathWithConfiguredDir("/test/absolute/path/app")).isEqualTo(replaceFileSeparator("/test/absolute/path/app.ecs.json")); assertThat(computeReformattedLogFilePathWithConfiguredDir("/test/absolute/path/app.log.1")).isEqualTo(replaceFileSeparator("/test/absolute/path/app.log.ecs.json")); diff --git a/apm-agent-plugins/apm-logging-plugin/apm-slf4j-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-slf4j-plugin/pom.xml index f7762611bf..ef68a3977c 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-slf4j-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-slf4j-plugin/pom.xml @@ -5,7 +5,7 @@ apm-logging-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-slf4j-plugin diff --git a/apm-agent-plugins/apm-logging-plugin/apm-tomcat-logging-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/apm-tomcat-logging-plugin/pom.xml index da3f51e287..6ab4ccfb14 100644 --- a/apm-agent-plugins/apm-logging-plugin/apm-tomcat-logging-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/apm-tomcat-logging-plugin/pom.xml @@ -5,7 +5,7 @@ apm-logging-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-tomcat-logging-plugin diff --git a/apm-agent-plugins/apm-logging-plugin/pom.xml b/apm-agent-plugins/apm-logging-plugin/pom.xml index 465db69dae..6cded057a0 100644 --- a/apm-agent-plugins/apm-logging-plugin/pom.xml +++ b/apm-agent-plugins/apm-logging-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-logging-plugin diff --git a/apm-agent-plugins/apm-micrometer-plugin/pom.xml b/apm-agent-plugins/apm-micrometer-plugin/pom.xml index 5430e519a6..e30162460a 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/pom.xml +++ b/apm-agent-plugins/apm-micrometer-plugin/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 @@ -23,7 +23,7 @@ io.micrometer micrometer-core - 1.12.4 + 1.13.2 provided diff --git a/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerConfigInstrumentationTest.java b/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerConfigInstrumentationTest.java index 3b05335fb6..a4ceee4141 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerConfigInstrumentationTest.java +++ b/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerConfigInstrumentationTest.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -52,7 +52,7 @@ public class MicrometerConfigInstrumentationTest { @Before public void setUp() { config = SpyConfiguration.createSpyConfig(); - doReturn(50L).when(config.getConfig(ReporterConfiguration.class)).getMetricsIntervalMs(); + doReturn(50L).when(config.getConfig(ReporterConfigurationImpl.class)).getMetricsIntervalMs(); reporter = new MockReporter(); } @@ -74,7 +74,7 @@ public void testConfigMapWasUpdated() { @Test public void testConfigMapWasUpdatedWhenInstrumentConfigDisabled() { - doReturn(false).when(config.getConfig(CoreConfiguration.class)).isInstrument(); + doReturn(false).when(config.getConfig(CoreConfigurationImpl.class)).isInstrument(); ElasticApmAgent.initInstrumentation(MockTracer.createRealTracer(reporter, config), ByteBuddyAgent.install()); MicrometerMetricsReporter.OneSecondStepSimpleConfig oneSecondStepSimpleConfig = new MicrometerMetricsReporter.OneSecondStepSimpleConfig(); SimpleMeterRegistry registryOneSecondStep = new SimpleMeterRegistry(oneSecondStepSimpleConfig, Clock.SYSTEM); diff --git a/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerInstrumentationStepTest.java b/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerInstrumentationStepTest.java index 13ebb2a18c..8d5aae964e 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerInstrumentationStepTest.java +++ b/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerInstrumentationStepTest.java @@ -22,7 +22,7 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; import co.elastic.apm.agent.configuration.SpyConfiguration; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -60,7 +60,7 @@ public class MicrometerInstrumentationStepTest { @Before public void setUp() { config = SpyConfiguration.createSpyConfig(); - doReturn(30_000L).when(config.getConfig(ReporterConfiguration.class)).getMetricsIntervalMs(); + doReturn(30_000L).when(config.getConfig(ReporterConfigurationImpl.class)).getMetricsIntervalMs(); reporter = new MockReporter(); } @@ -83,7 +83,7 @@ public void testStepVsCumulativeMultiple() { @Test public void testStepVsCumulativeMultipleSameInterval() { - doReturn(1_000L).when(config.getConfig(ReporterConfiguration.class)).getMetricsIntervalMs(); + doReturn(1_000L).when(config.getConfig(ReporterConfigurationImpl.class)).getMetricsIntervalMs(); final FooBar result = new FooBar(21,21); testStepVsCumulative(result, true); } diff --git a/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerInstrumentationTest.java b/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerInstrumentationTest.java index 279cbb1f4d..236acd6c08 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerInstrumentationTest.java +++ b/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerInstrumentationTest.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.micrometer.core.instrument.Clock; @@ -52,7 +52,7 @@ public class MicrometerInstrumentationTest { @Before public void setUp() { config = SpyConfiguration.createSpyConfig(); - doReturn(50L).when(config.getConfig(ReporterConfiguration.class)).getMetricsIntervalMs(); + doReturn(50L).when(config.getConfig(ReporterConfigurationImpl.class)).getMetricsIntervalMs(); reporter = new MockReporter(); lastMeasuredMetricSetNumber = 0; lastFooSamples = 0; @@ -73,7 +73,7 @@ public void testRegisterMeterRegistry() { @Test public void testReportedWhenInstrumentConfigDisabled() { - doReturn(false).when(config.getConfig(CoreConfiguration.class)).isInstrument(); + doReturn(false).when(config.getConfig(CoreConfigurationImpl.class)).isInstrument(); ElasticApmAgent.initInstrumentation(MockTracer.createRealTracer(reporter, config), ByteBuddyAgent.install()); SimpleMeterRegistry registry = new SimpleMeterRegistry(new OneSecondStepSimpleConfig(), Clock.SYSTEM); registry.counter("foo").increment(); diff --git a/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializerTest.java b/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializerTest.java index 026936f4fc..bfb23e129b 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializerTest.java +++ b/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializerTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.micrometer; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import com.dslplatform.json.JsonWriter; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; @@ -50,7 +50,7 @@ public class MicrometerMeterRegistrySerializerTest { @BeforeAll static void setup() { - MetricsConfiguration config = mock(MetricsConfiguration.class); + MetricsConfigurationImpl config = mock(MetricsConfigurationImpl.class); serializer = new MicrometerMeterRegistrySerializer(config); } diff --git a/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporterTest.java b/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporterTest.java index 18b64638e1..51e685e7cf 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporterTest.java +++ b/apm-agent-plugins/apm-micrometer-plugin/src/test/java/co/elastic/apm/agent/micrometer/MicrometerMetricsReporterTest.java @@ -20,10 +20,10 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -74,7 +74,7 @@ void setUp() { meterRegistry = new CompositeMeterRegistry(Clock.SYSTEM, List.of(nestedCompositeMeterRegistry)); reporter = new MockReporter(); tracer = MockTracer.createRealTracer(reporter); - doReturn(61_000L).when(tracer.getConfig(ReporterConfiguration.class)).getMetricsIntervalMs(); + doReturn(61_000L).when(tracer.getConfig(ReporterConfigurationImpl.class)).getMetricsIntervalMs(); metricsReporter = new MicrometerMetricsReporter(tracer, true); //all calls to run() are explicit from the tests //note the default mode is CUMULATIVE, so no need to addConfig(meterRegistry, meterRegistryConfig); metricsReporter.registerMeterRegistry(meterRegistry); @@ -121,7 +121,7 @@ void testMultipleMetricSets() { @Test void testDisabledMetrics() { doReturn(List.of(WildcardMatcher.valueOf("root.metric"), WildcardMatcher.valueOf("root.metric.exclude.*"))) - .when(tracer.getConfig(ReporterConfiguration.class)).getDisableMetrics(); + .when(tracer.getConfig(ReporterConfigurationImpl.class)).getDisableMetrics(); List tags = List.of(Tag.of("foo", "bar")); meterRegistry.counter("root.metric", tags).increment(42); @@ -136,7 +136,7 @@ void testDisabledMetrics() { @Test void testDedotMetricName() { - assertThat(tracer.getConfig(MetricsConfiguration.class).isDedotCustomMetrics()).isTrue(); + assertThat(tracer.getConfig(MetricsConfigurationImpl.class).isDedotCustomMetrics()).isTrue(); meterRegistry.counter("foo.bar").increment(42); JsonNode metricSet = getSingleMetricSet(); @@ -145,7 +145,7 @@ void testDedotMetricName() { @Test void testDisableDedotMetricName() { - doReturn(false).when(tracer.getConfig(MetricsConfiguration.class)).isDedotCustomMetrics(); + doReturn(false).when(tracer.getConfig(MetricsConfigurationImpl.class)).isDedotCustomMetrics(); meterRegistry.counter("foo.bar").increment(42); JsonNode metricSet = getSingleMetricSet(); @@ -202,7 +202,7 @@ void testCounter() { @Test void testCounterWithMetricsIntervalDisabled() { - doReturn(0L).when(tracer.getConfig(ReporterConfiguration.class)).getMetricsIntervalMs(); + doReturn(0L).when(tracer.getConfig(ReporterConfigurationImpl.class)).getMetricsIntervalMs(); meterRegistry.counter("counter", List.of(Tag.of("foo", "bar"), Tag.of("baz", "qux"))).increment(42); List metricSets = getMetricSets(null); assertThat(metricSets).isEmpty(); diff --git a/apm-agent-plugins/apm-mongodb/apm-mongodb-common/pom.xml b/apm-agent-plugins/apm-mongodb/apm-mongodb-common/pom.xml index 0c96e2ca5e..349cb74464 100644 --- a/apm-agent-plugins/apm-mongodb/apm-mongodb-common/pom.xml +++ b/apm-agent-plugins/apm-mongodb/apm-mongodb-common/pom.xml @@ -4,7 +4,7 @@ apm-mongodb co.elastic.apm - 1.50.0 + 1.51.0 diff --git a/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/test/java/co/elastic/apm/agent/mongodb/AbstractMongoClientInstrumentationIT.java b/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/test/java/co/elastic/apm/agent/mongodb/AbstractMongoClientInstrumentationIT.java index 1ca709459c..fe9dcb46da 100644 --- a/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/test/java/co/elastic/apm/agent/mongodb/AbstractMongoClientInstrumentationIT.java +++ b/apm-agent-plugins/apm-mongodb/apm-mongodb-common/src/test/java/co/elastic/apm/agent/mongodb/AbstractMongoClientInstrumentationIT.java @@ -19,10 +19,9 @@ package co.elastic.apm.agent.mongodb; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.context.Destination; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.testutils.TestContainersUtils; import co.elastic.apm.agent.testutils.assertions.DbAssert; @@ -71,7 +70,7 @@ public void startTransaction() { @After public void endTransaction() throws Exception { - Transaction currentTransaction = tracer.currentTransaction(); + TransactionImpl currentTransaction = tracer.currentTransaction(); if (currentTransaction != null) { currentTransaction.deactivate().end(); } @@ -100,7 +99,7 @@ public void testErrorSpanHasFailureOutcome() throws Exception { // trying to drop when it does not exist creates an error dropCollection(); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(3); verifySpan(spans.get(0), getSpanName("create"), Outcome.SUCCESS); @@ -235,7 +234,7 @@ public void testCaptureAllCommands() throws Exception { private void checkReportedSpans(String... operations) { assertThat(reporter.getNumReportedSpans()).isEqualTo(operations.length); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); assertThat(spans).hasSize(operations.length); for (int i = 0; i < operations.length; i++) { verifySpan(spans.get(i), getSpanName(operations[i]), Outcome.SUCCESS); @@ -246,7 +245,7 @@ protected boolean isAsync(){ return false; } - private void verifySpan(Span span, String expectedName, Outcome expectedOutcome) { + private void verifySpan(SpanImpl span, String expectedName, Outcome expectedOutcome) { assertThat(span) .hasName(expectedName) diff --git a/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/pom.xml b/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/pom.xml index dca3d434dc..7f23b23c74 100644 --- a/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/pom.xml +++ b/apm-agent-plugins/apm-mongodb/apm-mongodb3-plugin/pom.xml @@ -3,7 +3,7 @@ apm-mongodb co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-mongodb/apm-mongodb4-plugin/pom.xml b/apm-agent-plugins/apm-mongodb/apm-mongodb4-plugin/pom.xml index 19f1b713dc..fd0b75ed2f 100644 --- a/apm-agent-plugins/apm-mongodb/apm-mongodb4-plugin/pom.xml +++ b/apm-agent-plugins/apm-mongodb/apm-mongodb4-plugin/pom.xml @@ -5,7 +5,7 @@ apm-mongodb co.elastic.apm - 1.50.0 + 1.51.0 apm-mongodb4-plugin diff --git a/apm-agent-plugins/apm-mongodb/pom.xml b/apm-agent-plugins/apm-mongodb/pom.xml index 43c63ec16c..87fa2da510 100644 --- a/apm-agent-plugins/apm-mongodb/pom.xml +++ b/apm-agent-plugins/apm-mongodb/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-mongodb diff --git a/apm-agent-plugins/apm-okhttp-plugin/pom.xml b/apm-agent-plugins/apm-okhttp-plugin/pom.xml index 432532edcc..752edab5f8 100644 --- a/apm-agent-plugins/apm-okhttp-plugin/pom.xml +++ b/apm-agent-plugins/apm-okhttp-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-okhttp-plugin diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientAsyncInstrumentation.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientAsyncInstrumentation.java index 6e192c571e..49e72ed2b7 100644 --- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientAsyncInstrumentation.java +++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientAsyncInstrumentation.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; import net.bytebuddy.asm.Advice; @@ -83,7 +83,7 @@ public static Object[] onBeforeEnqueue(final @Advice.Origin Class currentContext = tracer.currentContext(); + TraceState currentContext = tracer.currentContext(); if (currentContext.isPropagationRequired(request, OkHttp3RequestHeaderGetter.INSTANCE)) { Request.Builder builder = originalRequest.newBuilder(); currentContext.propagateContext(builder, OkHttp3RequestHeaderSetter.INSTANCE, request, OkHttp3RequestHeaderGetter.INSTANCE); diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientInstrumentation.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientInstrumentation.java index 0652951f09..9d63e4f9ce 100644 --- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientInstrumentation.java +++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttp3ClientInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.okhttp; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; import net.bytebuddy.asm.Advice; @@ -67,7 +67,7 @@ public static Object[] onBeforeExecute(final @Advice.FieldValue("originalRequest span.activate(); } - ElasticContext toPropagate = tracer.currentContext(); + TraceState toPropagate = tracer.currentContext(); if (toPropagate.isPropagationRequired(request, OkHttp3RequestHeaderGetter.INSTANCE)) { Request.Builder builder = ((Request) originalRequest).newBuilder(); toPropagate.propagateContext(builder, OkHttp3RequestHeaderSetter.INSTANCE, request, OkHttp3RequestHeaderGetter.INSTANCE); diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientAsyncInstrumentation.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientAsyncInstrumentation.java index aedf7110b8..b89237132a 100644 --- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientAsyncInstrumentation.java +++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientAsyncInstrumentation.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; import com.squareup.okhttp.Call; @@ -80,7 +80,7 @@ public static Object[] onBeforeEnqueue(final @Advice.Origin Class toPropagate = tracer.currentContext(); + TraceState toPropagate = tracer.currentContext(); if (toPropagate.isPropagationRequired(request, OkHttpRequestHeaderGetter.INSTANCE)) { Request.Builder builder = originalRequest.newBuilder(); toPropagate.propagateContext(builder, OkHttpRequestHeaderSetter.INSTANCE, request, OkHttpRequestHeaderGetter.INSTANCE); diff --git a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientInstrumentation.java b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientInstrumentation.java index 6707bc9206..d1e0d1d01b 100644 --- a/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientInstrumentation.java +++ b/apm-agent-plugins/apm-okhttp-plugin/src/main/java/co/elastic/apm/agent/okhttp/OkHttpClientInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.okhttp; import co.elastic.apm.agent.httpclient.HttpClientHelper; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; import com.squareup.okhttp.HttpUrl; @@ -64,7 +64,7 @@ public static Object[] onBeforeExecute(@Advice.FieldValue("originalRequest") @Nu span.activate(); } - ElasticContext toPropagate = tracer.currentContext(); + TraceState toPropagate = tracer.currentContext(); if (toPropagate.isPropagationRequired(request, OkHttpRequestHeaderGetter.INSTANCE)) { Request.Builder builder = request.newBuilder(); toPropagate.propagateContext(builder, OkHttpRequestHeaderSetter.INSTANCE, request, OkHttpRequestHeaderGetter.INSTANCE); diff --git a/apm-agent-plugins/apm-okhttp-test/pom.xml b/apm-agent-plugins/apm-okhttp-test/pom.xml index eafb9a701f..7a78147ab3 100644 --- a/apm-agent-plugins/apm-okhttp-test/pom.xml +++ b/apm-agent-plugins/apm-okhttp-test/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/pom.xml b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/pom.xml index 74b5a607fd..69d5af0b44 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/pom.xml +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm apm-opentelemetry - 1.50.0 + 1.51.0 apm-opentelemetry-embedded-metrics-sdk diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/proxy/ProxyDoubleHistogramBuilder.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/proxy/ProxyDoubleHistogramBuilder.java index 5d4b0034ec..e5ed3d380a 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/proxy/ProxyDoubleHistogramBuilder.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/proxy/ProxyDoubleHistogramBuilder.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.embeddedotel.proxy; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.tracer.GlobalTracer; import io.opentelemetry.api.metrics.DoubleHistogramBuilder; @@ -31,7 +31,7 @@ public class ProxyDoubleHistogramBuilder { public ProxyDoubleHistogramBuilder(DoubleHistogramBuilder delegate) { this.delegate = delegate; //apply default bucket boundaries - List boundaries = GlobalTracer.get().getConfig(MetricsConfiguration.class).getCustomMetricsHistogramBoundaries(); + List boundaries = GlobalTracer.get().getConfig(MetricsConfigurationImpl.class).getCustomMetricsHistogramBoundaries(); delegate.setExplicitBucketBoundariesAdvice(boundaries); } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/proxy/ProxyLongHistogramBuilder.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/proxy/ProxyLongHistogramBuilder.java index 4ff5bee219..a6b996466c 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/proxy/ProxyLongHistogramBuilder.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-embedded-metrics-sdk/src/main/java/co/elastic/apm/agent/embeddedotel/proxy/ProxyLongHistogramBuilder.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.embeddedotel.proxy; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.tracer.GlobalTracer; import io.opentelemetry.api.metrics.LongHistogramBuilder; @@ -32,7 +32,7 @@ public class ProxyLongHistogramBuilder { public ProxyLongHistogramBuilder(LongHistogramBuilder delegate) { this.delegate = delegate; //apply default bucket boundaries, they are guaranteed to be ordered - List boundaries = GlobalTracer.get().getConfig(MetricsConfiguration.class).getCustomMetricsHistogramBoundaries(); + List boundaries = GlobalTracer.get().getConfig(MetricsConfigurationImpl.class).getCustomMetricsHistogramBoundaries(); delegate.setExplicitBucketBoundariesAdvice(convertToLongBoundaries(boundaries)); } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-common/pom.xml b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-common/pom.xml index 2d3002927e..b2a0ebe0f7 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-common/pom.xml +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-common/pom.xml @@ -3,7 +3,7 @@ apm-opentelemetry-metrics-bridge-parent co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-latest/pom.xml b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-latest/pom.xml index baa2a5ecab..bdd3d6c2d3 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-latest/pom.xml +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-latest/pom.xml @@ -3,7 +3,7 @@ apm-opentelemetry-metrics-bridge-parent co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-v1_14/pom.xml b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-v1_14/pom.xml index 9249ebe41d..c259be6795 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-v1_14/pom.xml +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/apm-opentelemetry-metrics-bridge-v1_14/pom.xml @@ -3,7 +3,7 @@ apm-opentelemetry-metrics-bridge-parent co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/pom.xml b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/pom.xml index 74dc667735..a4a0ff3907 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/pom.xml +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metrics-bridge-parent/pom.xml @@ -3,7 +3,7 @@ apm-opentelemetry co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/pom.xml b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/pom.xml index ca8c0e3c61..04712e4f46 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/pom.xml +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm apm-opentelemetry - 1.50.0 + 1.51.0 apm-opentelemetry-metricsdk-plugin diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/AbstractOtelMetricsTest.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/AbstractOtelMetricsTest.java index 185e47ad99..eea1cc5142 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/AbstractOtelMetricsTest.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/AbstractOtelMetricsTest.java @@ -22,11 +22,11 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.agent.util.AtomicDouble; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleCounter; @@ -81,7 +81,7 @@ public abstract class AbstractOtelMetricsTest { protected static ConfigurationRegistry config; - private ReporterConfiguration reporterConfig; + private ReporterConfigurationImpl reporterConfig; /** * The meter provider is lazily initialized on first usage (when {@link #createMeter(String)} is called). @@ -99,7 +99,7 @@ public static synchronized void beforeAll() { reporter = mockInstrumentationSetup.getReporter(); //Metrics export should work even with instrument=false - CoreConfiguration coreConfig = config.getConfig(CoreConfiguration.class); + CoreConfigurationImpl coreConfig = config.getConfig(CoreConfigurationImpl.class); doReturn(false).when(coreConfig).isInstrument(); assertThat(tracer.isRunning()).isTrue(); @@ -115,7 +115,7 @@ public static synchronized void afterAll() { @BeforeEach public void setup() { SpyConfiguration.reset(config); - reporterConfig = config.getConfig(ReporterConfiguration.class); + reporterConfig = config.getConfig(ReporterConfigurationImpl.class); // we use explicit flush in tests instead of periodic reporting to prevent flakyness doReturn(1_000_000L).when(reporterConfig).getMetricsIntervalMs(); meterProvider = null; @@ -279,7 +279,7 @@ public void testSameMetricDifferentMeter() { @Test public void testDedotSettingIgnored() { - MetricsConfiguration config = tracer.getConfig(MetricsConfiguration.class); + MetricsConfigurationImpl config = tracer.getConfig(MetricsConfigurationImpl.class); doReturn(true).when(config).isDedotCustomMetrics(); Meter meter1 = createMeter("test"); @@ -295,7 +295,7 @@ public void testDedotSettingIgnored() { @Test public void testMetricDisabling() { - MetricsConfiguration config = tracer.getConfig(MetricsConfiguration.class); + MetricsConfigurationImpl config = tracer.getConfig(MetricsConfigurationImpl.class); doReturn(List.of( WildcardMatcher.valueOf("metric.a") )).when(reporterConfig).getDisableMetrics(); @@ -588,7 +588,7 @@ public void testUpDownCounter() { @Test public void testHistogram() { - MetricsConfiguration metricsConfig = config.getConfig(MetricsConfiguration.class); + MetricsConfigurationImpl metricsConfig = config.getConfig(MetricsConfigurationImpl.class); doReturn(List.of(5d, 10d, 25d)).when(metricsConfig).getCustomMetricsHistogramBoundaries(); Meter testMeter = createMeter("test"); @@ -641,7 +641,7 @@ public void testHistogram() { */ @Test public void testDefaultHistogramBuckets() { - MetricsConfiguration metricsConfig = config.getConfig(MetricsConfiguration.class); + MetricsConfigurationImpl metricsConfig = config.getConfig(MetricsConfigurationImpl.class); List boundaries = metricsConfig.getCustomMetricsHistogramBoundaries(); assertThat(boundaries).isNotEmpty(); diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/MetricExportTimingTest.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/MetricExportTimingTest.java index 21a934aa7d..d575f6a1ca 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/MetricExportTimingTest.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/MetricExportTimingTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.otelmetricsdk; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import io.opentelemetry.api.metrics.Meter; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import org.junit.jupiter.api.Test; @@ -34,7 +34,7 @@ public class MetricExportTimingTest extends AbstractInstrumentationTest { */ @Test void testMetricExportIntervalRespected() throws Exception { - ReporterConfiguration reporterConfig = tracer.getConfig(ReporterConfiguration.class); + ReporterConfigurationImpl reporterConfig = tracer.getConfig(ReporterConfigurationImpl.class); doReturn(50L).when(reporterConfig).getMetricsIntervalMs(); try (SdkMeterProvider meterProvider = SdkMeterProvider.builder().build()) { diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/PrivateUserSdkOtelMetricsTest.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/PrivateUserSdkOtelMetricsTest.java index 5bd9e711cf..336b71bc13 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/PrivateUserSdkOtelMetricsTest.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-metricsdk-plugin/src/test/java/co/elastic/apm/agent/otelmetricsdk/PrivateUserSdkOtelMetricsTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.otelmetricsdk; -import co.elastic.apm.agent.configuration.MetricsConfiguration; +import co.elastic.apm.agent.configuration.MetricsConfigurationImpl; import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.DoubleHistogramBuilder; import io.opentelemetry.api.metrics.Meter; @@ -120,7 +120,7 @@ public void testCustomHistogramView() { View.builder().setAggregation(Aggregation.explicitBucketHistogram(List.of(1.0, 5.0))).build() ); - MetricsConfiguration metricsConfig = config.getConfig(MetricsConfiguration.class); + MetricsConfigurationImpl metricsConfig = config.getConfig(MetricsConfigurationImpl.class); doReturn(List.of(42.0)).when(metricsConfig).getCustomMetricsHistogramBoundaries(); Meter testMeter = createMeter("test"); diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/pom.xml b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/pom.xml index 0a348527b1..e049ee0caa 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/pom.xml +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm apm-opentelemetry - 1.50.0 + 1.51.0 apm-opentelemetry-plugin diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/WithSpanInstrumentation.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/WithSpanInstrumentation.java index dda35da0d5..038179b1c6 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/WithSpanInstrumentation.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/WithSpanInstrumentation.java @@ -19,14 +19,15 @@ package co.elastic.apm.agent.opentelemetry; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.stacktrace.StacktraceConfiguration; +import co.elastic.apm.agent.impl.stacktrace.StacktraceConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.opentelemetry.tracing.OTelHelper; import co.elastic.apm.agent.sdk.bytebuddy.AnnotationValueOffsetMappingFactory; import co.elastic.apm.agent.sdk.bytebuddy.SimpleMethodSignatureOffsetMappingFactory; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; @@ -46,7 +47,6 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import static co.elastic.apm.agent.sdk.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; @@ -64,11 +64,11 @@ public class WithSpanInstrumentation extends AbstractOpenTelemetryInstrumentatio protected static final Tracer tracer = GlobalTracer.get(); private final CoreConfiguration coreConfig; - private final StacktraceConfiguration stacktraceConfig; + private final StacktraceConfigurationImpl stacktraceConfig; public WithSpanInstrumentation(ElasticApmTracer tracer) { coreConfig = tracer.getConfig(CoreConfiguration.class); - stacktraceConfig = tracer.getConfig(StacktraceConfiguration.class); + stacktraceConfig = tracer.getConfig(StacktraceConfigurationImpl.class); } @Override @@ -113,7 +113,7 @@ public static Object onMethodEnter( @Advice.Origin Method method, @Advice.AllArguments Object[] methodArguments) { - ElasticContext activeContext = tracer.currentContext(); + TraceState activeContext = tracer.currentContext(); final AbstractSpan parentSpan = activeContext.getSpan(); if (parentSpan == null) { logger.debug("Not creating span for {} because there is no currently active span.", signature); @@ -153,7 +153,7 @@ public static Object onMethodEnter( span.withName(spanName.isEmpty() ? signature : spanName) .activate(); - ((co.elastic.apm.agent.impl.transaction.Span) span).withOtelKind(OTelHelper.map(otelKind)); + ((SpanImpl) span).withOtelKind(OTelHelper.map(otelKind)); return span; } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/baggage/OtelBaggage.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/baggage/OtelBaggage.java index c4f77684b7..d037722c84 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/baggage/OtelBaggage.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/baggage/OtelBaggage.java @@ -18,6 +18,7 @@ */ package co.elastic.apm.agent.opentelemetry.baggage; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import io.opentelemetry.api.baggage.Baggage; @@ -26,9 +27,9 @@ public class OtelBaggage { - private static final WeakMap translationCache = WeakConcurrent.buildMap(); + private static final WeakMap translationCache = WeakConcurrent.buildMap(); - public static Baggage fromElasticBaggage(co.elastic.apm.agent.impl.baggage.Baggage elasticBaggage) { + public static Baggage fromElasticBaggage(BaggageImpl elasticBaggage) { BaggageBuilder builder = Baggage.builder(); for (String key : elasticBaggage.keys()) { builder.put(key, elasticBaggage.get(key), BaggageEntryMetadata.create(elasticBaggage.getMetadata(key))); @@ -39,13 +40,13 @@ public static Baggage fromElasticBaggage(co.elastic.apm.agent.impl.baggage.Bagga return result; } - public static co.elastic.apm.agent.impl.baggage.Baggage toElasticBaggage(Baggage otelBaggage) { + public static BaggageImpl toElasticBaggage(Baggage otelBaggage) { if (otelBaggage == null || otelBaggage.isEmpty()) { - return co.elastic.apm.agent.impl.baggage.Baggage.EMPTY; + return BaggageImpl.EMPTY; } - co.elastic.apm.agent.impl.baggage.Baggage translated = translationCache.get(otelBaggage); + BaggageImpl translated = translationCache.get(otelBaggage); if (translated == null) { - co.elastic.apm.agent.impl.baggage.Baggage.Builder builder = co.elastic.apm.agent.impl.baggage.Baggage.builder(); + BaggageImpl.Builder builder = BaggageImpl.builder(); otelBaggage.forEach((key, value) -> { String metadata = value.getMetadata().getValue(); builder.put(key, value.getValue(), metadata.isEmpty() ? null : metadata); diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/context/OTelContextStorage.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/context/OTelContextStorage.java index 0a57567a16..0c3075c6e7 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/context/OTelContextStorage.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/context/OTelContextStorage.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.opentelemetry.context; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.ElasticContext; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; import co.elastic.apm.agent.opentelemetry.tracing.OTelBridgeContext; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -66,7 +66,7 @@ public Scope attach(@Nullable Context toAttach) { @Nullable @Override public Context current() { - ElasticContext current = tracer.currentContext(); + TraceStateImpl current = tracer.currentContext(); if (current.isEmpty()) { return null; } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelBridgeContext.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelBridgeContext.java index 1de40831e2..1f52d4dfbf 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelBridgeContext.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelBridgeContext.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.opentelemetry.tracing; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.baggage.Baggage; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; import co.elastic.apm.agent.opentelemetry.baggage.OtelBaggage; import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; @@ -32,9 +32,9 @@ import java.util.Objects; /** - * Bridge implementation of OpenTelemetry {@link Context} that allows to provide compatibility with {@link ElasticContext}. + * Bridge implementation of OpenTelemetry {@link Context} that allows to provide compatibility with {@link TraceStateImpl}. */ -public class OTelBridgeContext extends ElasticContext implements Context, Scope { +public class OTelBridgeContext extends TraceStateImpl implements Context, Scope { /** * Original root context as returned by {@link Context#root()} before instrumentation. @@ -86,7 +86,7 @@ public static OTelBridgeContext bridgeRootContext(ElasticApmTracer tracer, Conte * @param currentContext elastic (currently active) context * @return bridged context with span as active */ - public static OTelBridgeContext wrapElasticActiveSpan(ElasticApmTracer tracer, ElasticContext currentContext) { + public static OTelBridgeContext wrapElasticActiveSpan(ElasticApmTracer tracer, TraceStateImpl currentContext) { if (root == null) { // Ensure that root context is being accessed at least once to capture the original root // OTel 1.0 directly calls ArrayBasedContext.root() which is not publicly accessible, later versions delegate @@ -108,7 +108,7 @@ public static OTelBridgeContext wrapElasticActiveSpan(ElasticApmTracer tracer, E @Nullable @Override - public AbstractSpan getSpan() { + public AbstractSpanImpl getSpan() { // get otel span from context Span span = Span.fromContext(otelContext); if (span instanceof OTelSpan) { @@ -118,11 +118,11 @@ public AbstractSpan getSpan() { } @Override - public Baggage getBaggage() { + public BaggageImpl getBaggage() { io.opentelemetry.api.baggage.Baggage otelBaggage = io.opentelemetry.api.baggage.Baggage.fromContext(otelContext); if (otelBaggage == null || otelBaggage.isEmpty()) { - return Baggage.EMPTY; + return BaggageImpl.EMPTY; } return OtelBaggage.toElasticBaggage(otelBaggage); } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpan.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpan.java index e107c16313..140be3594e 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpan.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpan.java @@ -18,11 +18,12 @@ */ package co.elastic.apm.agent.opentelemetry.tracing; -import co.elastic.apm.agent.impl.context.Url; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.context.UrlImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import co.elastic.apm.agent.impl.transaction.OTelSpanKind; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.sdk.internal.util.LoggerUtils; @@ -46,9 +47,9 @@ public class OTelSpan implements Span { static final String ILLEGAL_ATTRIBUTE_VALUE_TYPE_MESSAGE_FORMAT = "`%s` attribute's value type must be boolean, `%s` is illegal"; private static final Logger eventLogger = LoggerUtils.logOnce(LoggerFactory.getLogger(OTelSpan.class)); - private final AbstractSpan span; + private final AbstractSpanImpl span; - public OTelSpan(AbstractSpan span) { + public OTelSpan(AbstractSpanImpl span) { this.span = span; span.incrementReferences(); } @@ -113,17 +114,17 @@ public Span updateName(String name) { @Override public void end() { - if (span instanceof Transaction) { - onTransactionEnd((Transaction) span); - } else if (span instanceof co.elastic.apm.agent.impl.transaction.Span) { - onSpanEnd((co.elastic.apm.agent.impl.transaction.Span) span); + if (span instanceof TransactionImpl) { + onTransactionEnd((TransactionImpl) span); + } else if (span instanceof SpanImpl) { + onSpanEnd((SpanImpl) span); } span.end(); } - private void onTransactionEnd(Transaction t) { + private void onTransactionEnd(TransactionImpl t) { Map attributes = span.getOtelAttributes(); boolean isRpc = attributes.containsKey("rpc.system"); @@ -142,7 +143,7 @@ private void onTransactionEnd(Transaction t) { t.setFrameworkVersion(VersionUtils.getVersion(OpenTelemetry.class, "io.opentelemetry", "opentelemetry-api")); } - private void onSpanEnd(co.elastic.apm.agent.impl.transaction.Span s) { + private void onSpanEnd(SpanImpl s) { Map attributes = s.getOtelAttributes(); @@ -224,7 +225,7 @@ private void onSpanEnd(co.elastic.apm.agent.impl.transaction.Span s) { } } - netPort = Url.normalizePort(netPort, httpScheme); + netPort = UrlImpl.normalizePort(netPort, httpScheme); s.getContext().getServiceTarget() .withType(subType) @@ -264,10 +265,10 @@ private static URI parseURI(@Nullable String s) { @Override public void end(long timestamp, TimeUnit unit) { - if (span instanceof Transaction) { - onTransactionEnd((Transaction) span); - } else if (span instanceof co.elastic.apm.agent.impl.transaction.Span) { - onSpanEnd((co.elastic.apm.agent.impl.transaction.Span) span); + if (span instanceof TransactionImpl) { + onTransactionEnd((TransactionImpl) span); + } else if (span instanceof SpanImpl) { + onSpanEnd((SpanImpl) span); } span.end(unit.toMicros(timestamp)); } @@ -282,7 +283,7 @@ public boolean isRecording() { return span.isSampled(); } - public AbstractSpan getInternalSpan() { + public AbstractSpanImpl getInternalSpan() { return span; } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanBuilder.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanBuilder.java index c56200146a..659965fdef 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanBuilder.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanBuilder.java @@ -19,19 +19,18 @@ package co.elastic.apm.agent.opentelemetry.tracing; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.baggage.Baggage; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.baggage.BaggageImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import co.elastic.apm.agent.impl.transaction.MultiValueMapAccessor; -import co.elastic.apm.agent.impl.transaction.OTelSpanKind; -import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import co.elastic.apm.agent.opentelemetry.baggage.OtelBaggage; -import co.elastic.apm.agent.sdk.logging.Logger; -import co.elastic.apm.agent.sdk.logging.LoggerFactory; import co.elastic.apm.agent.sdk.internal.util.LoggerUtils; import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils; import co.elastic.apm.agent.sdk.internal.util.VersionUtils; +import co.elastic.apm.agent.sdk.logging.Logger; +import co.elastic.apm.agent.sdk.logging.LoggerFactory; +import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.common.AttributeKey; @@ -53,7 +52,8 @@ class OTelSpanBuilder implements SpanBuilder { - private static final Logger addLinkLogger = LoggerUtils.logOnce(LoggerFactory.getLogger(OTelSpanBuilder.class)); + private static final Logger addLinkLogger1 = LoggerUtils.logOnce(LoggerFactory.getLogger(OTelSpanBuilder.class)); + private static final Logger addLinkLogger2 = LoggerUtils.logOnce(LoggerFactory.getLogger(OTelSpanBuilder.class)); private final String spanName; private final ElasticApmTracer elasticApmTracer; @@ -86,15 +86,19 @@ public SpanBuilder setNoParent() { @Override public SpanBuilder addLink(SpanContext spanContext) { + if (!(spanContext instanceof OTelSpanContext)) { + addLinkLogger2.warn("Adding arbitrary span context to links is currently unsupported"); + return this; + } links.add(spanContext); return this; } @Override - public SpanBuilder addLink(SpanContext spanContext, Attributes attributes1) { + public SpanBuilder addLink(SpanContext spanContext, @Nullable Attributes attributes1) { addLink(spanContext); if (attributes1 != null && !attributes1.isEmpty()) { - addLinkLogger.warn("Adding attributes to links is currently unsupported - the links have been added but with no attributes, the following attributes have been ignored: %s",attributes1); + addLinkLogger1.warn("Adding attributes to links is currently unsupported - the links have been added but with no attributes, the following attributes have been ignored: %s", attributes1); } return this; } @@ -143,10 +147,10 @@ public SpanBuilder setStartTimestamp(long startTimestamp, TimeUnit unit) { @Override public Span startSpan() { - AbstractSpan span; + AbstractSpanImpl span; - Baggage parentBaggage; - AbstractSpan parentSpan = null; + BaggageImpl parentBaggage; + AbstractSpanImpl parentSpan = null; Context remoteContext = null; if (parent != null) { @@ -177,12 +181,12 @@ public Span startSpan() { } span.withName(spanName); - if (span instanceof Transaction) { - Transaction t = ((Transaction) span); + if (span instanceof TransactionImpl) { + TransactionImpl t = ((TransactionImpl) span); t.setFrameworkName("OpenTelemetry API"); String otelVersion = VersionUtils.getVersion(OpenTelemetry.class, "io.opentelemetry", "opentelemetry-api"); - if(otelVersion != null){ + if (otelVersion != null) { t.setFrameworkVersion(otelVersion); } } @@ -195,7 +199,7 @@ public Span startSpan() { // Add the links to the span for (int i = 0; i < links.size(); i++) { - span.addSpanLink(TraceContext.fromParentContext(), ((OTelSpanContext) links.get(i)).getElasticTraceContext()); + span.addSpanLink(TraceContextImpl.fromParentContext(), ((OTelSpanContext) links.get(i)).getElasticTraceContext()); } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanContext.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanContext.java index 74700ccd15..b5cc133882 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanContext.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/main/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanContext.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.opentelemetry.tracing; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.TraceFlags; import io.opentelemetry.api.trace.TraceState; @@ -28,11 +28,11 @@ import java.util.List; public class OTelSpanContext implements SpanContext { - private final TraceContext traceContext; + private final TraceContextImpl traceContext; - protected TraceContext getElasticTraceContext() {return traceContext;} + protected TraceContextImpl getElasticTraceContext() {return traceContext;} - public OTelSpanContext(TraceContext traceContext) { + public OTelSpanContext(TraceContextImpl traceContext) { this.traceContext = traceContext; } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/metrics/EmbeddedMetricSDKShutdownTest.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/metrics/EmbeddedMetricSDKShutdownTest.java index a95572aff4..c64671248f 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/metrics/EmbeddedMetricSDKShutdownTest.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/metrics/EmbeddedMetricSDKShutdownTest.java @@ -23,7 +23,7 @@ import co.elastic.apm.agent.bci.ElasticApmAgent; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.opentelemetry.OtelTestUtils; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.metrics.LongCounter; import io.opentelemetry.api.metrics.Meter; @@ -47,7 +47,7 @@ public void verifyMetricsFlushedOnAgentShutdown() { ElasticApmTracer tracer = mockInstrumentationSetup.getTracer(); MockReporter reporter = mockInstrumentationSetup.getReporter(); - ReporterConfiguration reporterConfig = mockInstrumentationSetup.getConfig().getConfig(ReporterConfiguration.class); + ReporterConfigurationImpl reporterConfig = mockInstrumentationSetup.getConfig().getConfig(ReporterConfigurationImpl.class); doReturn(1_000_000L).when(reporterConfig).getMetricsIntervalMs(); assertThat(tracer.isRunning()).isTrue(); ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install()); diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryAnnotationsTest.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryAnnotationsTest.java index 91d1580d7b..e78a7ac679 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryAnnotationsTest.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryAnnotationsTest.java @@ -18,8 +18,9 @@ */ package co.elastic.apm.agent.opentelemetry.tracing; -import co.elastic.apm.agent.impl.transaction.ElasticContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.testutils.assertions.Assertions; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanKind; @@ -55,7 +56,7 @@ public void after() { public void withSpanAnnotationTestWithMethodSignatureSpanName() { executeSpanInTransactionAndAssertTransaction((ignore) -> fooSpan()); - co.elastic.apm.agent.impl.transaction.Span firstSpan = reporter.getFirstSpan(); + SpanImpl firstSpan = reporter.getFirstSpan(); assertThat(firstSpan.getNameAsString()).isEqualTo("ElasticOpenTelemetryAnnotationsTest#fooSpan"); assertThat(reporter.getFirstSpan().isChildOf(reporter.getFirstTransaction())).isTrue(); } @@ -64,7 +65,7 @@ public void withSpanAnnotationTestWithMethodSignatureSpanName() { public void withSpanAnnotationTestWithSpanNameFromAnnotation() { executeSpanInTransactionAndAssertTransaction((ignore) -> barSpan()); - co.elastic.apm.agent.impl.transaction.Span firstSpan = reporter.getFirstSpan(); + SpanImpl firstSpan = reporter.getFirstSpan(); assertThat(firstSpan.getNameAsString()).isEqualTo("barSpan"); assertThat(reporter.getFirstSpan().isChildOf(reporter.getFirstTransaction())).isTrue(); } @@ -73,7 +74,7 @@ public void withSpanAnnotationTestWithSpanNameFromAnnotation() { public void withSpanAnnotationSpanAttributes() { executeSpanInTransactionAndAssertTransaction((ignore) -> fooSpanWithAttrs("foobar", "objectAsString", 2073, 2.69)); - co.elastic.apm.agent.impl.transaction.Span firstSpan = reporter.getFirstSpan(); + SpanImpl firstSpan = reporter.getFirstSpan(); assertThat(firstSpan.getNameAsString()).isEqualTo("ElasticOpenTelemetryAnnotationsTest#fooSpanWithAttrs"); assertThat(firstSpan.isChildOf(reporter.getFirstTransaction())).isTrue(); assertThat(firstSpan.getOtelAttributes().get("attr1")).isEqualTo("foobar"); @@ -93,7 +94,7 @@ private void executeSpanInTransactionAndAssertTransaction(Consumer function) assertThat(reporter.getTransactions()).hasSize(1); assertThat(reporter.getSpans()).hasSize(1); - Transaction reportedTransaction = reporter.getFirstTransaction(); + TransactionImpl reportedTransaction = reporter.getFirstTransaction(); assertThat(reportedTransaction.getNameAsString()).isEqualTo("transaction"); } @@ -122,7 +123,7 @@ protected void fooSpanWithAttrs(@SpanAttribute("attr1") String string, private void checkNoActiveContext() { Assertions.assertThat(tracer.currentContext()) .describedAs("no active elastic context is expected") - .satisfies(ElasticContext::isEmpty); + .satisfies(TraceStateImpl::isEmpty); assertThat(Context.current()) .describedAs("no active otel context is expected") .isSameAs(Context.root()) diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryTest.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryTest.java index 2c0a5ee8c2..e814e69645 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryTest.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/ElasticOpenTelemetryTest.java @@ -18,10 +18,7 @@ */ package co.elastic.apm.agent.opentelemetry.tracing; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; -import co.elastic.apm.agent.impl.transaction.OTelSpanKind; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.*; import co.elastic.apm.agent.opentelemetry.SemAttributes; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.dispatch.TextHeaderSetter; @@ -71,7 +68,7 @@ public void testTransaction() { } assertThat(reporter.getTransactions()).hasSize(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo("transaction"); assertThat(transaction.getBaggage()) .hasSize(1) @@ -94,7 +91,7 @@ public void testTracerBuilder() { .end(); assertThat(reporter.getTransactions()).hasSize(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo("transaction"); } @@ -109,7 +106,7 @@ public void testTransactionWithAttribute() { .end(); assertThat(reporter.getTransactions()).hasSize(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getOtelAttributes().get("boolean")).isEqualTo(true); assertThat(transaction.getOtelAttributes().get("long")).isEqualTo(42L); @@ -120,7 +117,7 @@ public void testTransactionWithAttribute() { @Test public void testBaggageInteroperability() { - ElasticContext elasticContext = tracer.currentContext().withUpdatedBaggage() + TraceStateImpl elasticContext = tracer.currentContext().withUpdatedBaggage() .put("foo", "elastic") .put("bar", "el2", "metadata") .buildContext() @@ -160,7 +157,7 @@ public void testTransactionWithSpanManualPropagation() { assertThat(reporter.getTransactions()).hasSize(1); assertThat(reporter.getSpans()).hasSize(1); - Transaction reportedTransaction = reporter.getFirstTransaction(); + TransactionImpl reportedTransaction = reporter.getFirstTransaction(); assertThat(reportedTransaction.getNameAsString()).isEqualTo("transaction"); assertThat(reporter.getFirstSpan().getNameAsString()).isEqualTo("span"); @@ -193,11 +190,11 @@ public void testOtelBaggageOnElasticSpan() { Baggage baggage = Baggage.builder().put("foo", "bar").build(); try (Scope scope = baggage.makeCurrent()) { - Transaction tr = tracer.startRootTransaction(null).activate(); + TransactionImpl tr = tracer.startRootTransaction(null).activate(); assertThat(tr).hasBaggage("foo", "bar"); Baggage baggage2 = Baggage.builder().put("foo2", "bar2").build(); try (Scope scope2 = baggage2.makeCurrent()) { - co.elastic.apm.agent.impl.transaction.Span elasticSpan = tracer.currentContext().createSpan(); + SpanImpl elasticSpan = tracer.currentContext().createSpan(); assertThat(elasticSpan) .hasBaggage("foo2", "bar2") .hasBaggageCount(1); @@ -284,8 +281,8 @@ public void otelBridgedRootContext() { .isSameAs(Context.current()); } - public ElasticContext checkBridgedContext(Context context) { - assertThat(context).isInstanceOf(ElasticContext.class); + public TraceStateImpl checkBridgedContext(Context context) { + assertThat(context).isInstanceOf(TraceStateImpl.class); // we have to check class name as the wrapper class is loaded in the plugin CL and it is also loadable from // the current CL, thus making class equality not work as expected @@ -293,7 +290,7 @@ public ElasticContext checkBridgedContext(Context context) { .describedAs("root context should be wrapped") .doesNotStartWith("io.opentelemetry"); - return (ElasticContext) context; + return (TraceStateImpl) context; } @Test @@ -349,7 +346,7 @@ private static void checkCurrentContext(Context expected, String assertMsg) { assertThat(expected) .describedAs("otel context should also be an elastic context") - .isInstanceOf(ElasticContext.class); + .isInstanceOf(TraceStateImpl.class); assertThat(tracer.currentContext()) .describedAs(assertMsg) @@ -415,7 +412,7 @@ public void contextActivationFromElastic() { ContextKey key = ContextKey.named("key"); Context context = Context.root().with(key, "value"); - ElasticContext bridgedContext = checkBridgedContext(context); + TraceStateImpl bridgedContext = checkBridgedContext(context); // activate context from elastic API using a bridged context try (co.elastic.apm.agent.tracer.Scope scope = bridgedContext.activateInScope()) { @@ -456,7 +453,7 @@ private void checkCurrentContextKey(ContextKey key, String expectedValue private void checkNoActiveContext() { assertThat(tracer.currentContext()) .describedAs("no active elastic context is expected") - .satisfies(ElasticContext::isEmpty); + .satisfies(TraceStateImpl::isEmpty); assertThat(Context.current()) .describedAs("no active otel context is expected") .isSameAs(Context.root()) @@ -466,7 +463,7 @@ private void checkNoActiveContext() { @Test public void otelStateWithActiveElasticTransaction() { - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); try { assertThat(tracer.currentContext()).isSameAs(transaction); @@ -493,7 +490,7 @@ public void otelStateWithActiveElasticTransaction() { @Test public void otelSpanOverActiveElasticTransaction() { - Transaction transaction = startTestRootTransaction(); + TransactionImpl transaction = startTestRootTransaction(); String spanId; try { @@ -520,7 +517,7 @@ public void otelSpanOverActiveElasticTransaction() { assertThat(reporter.getFirstTransaction()).isSameAs(transaction); assertThat(reporter.getNumReportedSpans()).isEqualTo(1); - AbstractSpan reportedSpan = reporter.getFirstSpan().getSpan(); + AbstractSpanImpl reportedSpan = reporter.getFirstSpan().getSpan(); assertThat(reportedSpan).isNotNull(); assertThat(reportedSpan.getNameAsString()).isEqualTo("otel span"); assertThat(reportedSpan.getTraceContext().getId().toString()).isEqualTo(spanId); @@ -529,7 +526,7 @@ public void otelSpanOverActiveElasticTransaction() { @Test public void overrideElasticTransactionName() { - Transaction transaction = startTestRootTransaction() + TransactionImpl transaction = startTestRootTransaction() .withName("Elastic Provided High-Prio Name", co.elastic.apm.agent.tracer.AbstractSpan.PRIORITY_USER_SUPPLIED); try { @@ -552,13 +549,13 @@ public void elasticSpanOverOtelSpan() { .spanBuilder("otel transaction") .startSpan(); - Transaction transaction; + TransactionImpl transaction; try (Scope scope = otelSpan.makeCurrent()) { transaction = tracer.currentTransaction(); assertThat(transaction).isNotNull(); - co.elastic.apm.agent.impl.transaction.Span elasticSpan = transaction.createSpan(); + SpanImpl elasticSpan = transaction.createSpan(); try (co.elastic.apm.agent.tracer.Scope elasticScope = elasticSpan.activateInScope()) { assertThat(tracer.getActive()).isNotNull(); tracer.getActive().withName("elastic span"); @@ -578,7 +575,7 @@ public void elasticSpanOverOtelSpan() { assertThat(transaction.getNameAsString()).isEqualTo("otel transaction"); assertThat(reporter.getNumReportedSpans()).isEqualTo(1); - AbstractSpan reportedSpan = reporter.getFirstSpan().getSpan(); + AbstractSpanImpl reportedSpan = reporter.getFirstSpan().getSpan(); assertThat(reportedSpan).isNotNull(); assertThat(reportedSpan.getNameAsString()).isEqualTo("elastic span"); assertThat(reportedSpan.getTraceContext().isChildOf(transaction.getTraceContext())).isTrue(); @@ -605,7 +602,7 @@ public void testOTelSpanAttributesCopiedAsIs() { )); } - private static void checkOTelAttributes(AbstractSpan context, Map expected) { + private static void checkOTelAttributes(AbstractSpanImpl context, Map expected) { assertThat(context.getOtelAttributes()) .containsAllEntriesOf(expected) .hasSameSizeAs(expected); @@ -662,7 +659,7 @@ public void startEndWithExplicitTimestamp() { } assertThat(reporter.getTransactions()).hasSize(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo("transaction"); assertThat(transaction.getOutcome()).isEqualTo(Outcome.FAILURE); assertThat(transaction.getTimestamp()).isEqualTo(startTransaction.toEpochMilli() * 1000); @@ -671,7 +668,7 @@ public void startEndWithExplicitTimestamp() { assertThat(reporter.getSpans()).hasSize(1); - co.elastic.apm.agent.impl.transaction.Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span.getNameAsString()).isEqualTo("span"); assertThat(span.getOutcome()).isEqualTo(Outcome.UNKNOWN); assertThat(span.getTimestamp()).isEqualTo(startSpan.toEpochMilli() * 1000); diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanDiscardingTest.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanDiscardingTest.java index 6ff7903bd0..9948dd67df 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanDiscardingTest.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanDiscardingTest.java @@ -18,7 +18,8 @@ */ package co.elastic.apm.agent.opentelemetry.tracing; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.configuration.TimeDuration; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.Span; @@ -41,7 +42,7 @@ public class OTelSpanDiscardingTest extends AbstractOpenTelemetryTest { @Before public void before() { - doReturn(TimeDuration.of("100ms")).when(config.getConfig(CoreConfiguration.class)).getSpanMinDuration(); + doReturn(TimeDuration.of("100ms")).when(config.getConfig(CoreConfigurationImpl.class)).getSpanMinDuration(); } @Test @@ -90,7 +91,7 @@ private void runTest(Scenario scenario) { } transaction.end(); assertThat(reporter.getTransactions()).hasSize(1); - List spans = reporter.getSpans(); + List spans = reporter.getSpans(); switch (scenario) { case DISCARD: case DISCARD_SET_EXPLICITLY: diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanLinkTest.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanLinkTest.java index ea1a8b10b0..60c1cd3a93 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanLinkTest.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/co/elastic/apm/agent/opentelemetry/tracing/OTelSpanLinkTest.java @@ -21,7 +21,7 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.ElasticApmTracerBuilder; import co.elastic.apm.agent.impl.sampling.ConstantSampler; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import co.elastic.apm.agent.opentelemetry.global.ElasticOpenTelemetry; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; @@ -62,12 +62,12 @@ void checkSpanLinks(int linkCount, boolean withAttributes) { SpanBuilder spanbuilder = tracer.spanBuilder("span"); assertThat(spanbuilder).isInstanceOf(OTelSpanBuilder.class); - TraceContext[] contexts = new TraceContext[linkCount]; + TraceContextImpl[] contexts = new TraceContextImpl[linkCount]; AttributesBuilder builder = Attributes.builder(); builder.put("key1", 33); builder.put("key2", true); for (int i = 0; i < linkCount; i++) { - TraceContext traceContext1 = TraceContext.with64BitId(etracer); + TraceContextImpl traceContext1 = TraceContextImpl.with64BitId(etracer); traceContext1.asRootSpan(ConstantSampler.of(false)); SpanContext context1 = new OTelSpanContext(traceContext1); if (withAttributes) { @@ -81,7 +81,7 @@ void checkSpanLinks(int linkCount, boolean withAttributes) { } OTelSpan span = (OTelSpan) spanbuilder.startSpan(); - List links = span.getInternalSpan().getSpanLinks(); + List links = span.getInternalSpan().getSpanLinks(); assertThat(links.size()).isEqualTo(linkCount); for (int i = 0; i < linkCount; i++) { diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java index c1d00c1029..dea9a4cb24 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-plugin/src/test/java/specs/OTelBridgeStepsDefinitions.java @@ -18,12 +18,9 @@ */ package specs; -import co.elastic.apm.agent.impl.context.ServiceTarget; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.OTelSpanKind; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.ServiceTargetImpl; +import co.elastic.apm.agent.impl.transaction.*; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.opentelemetry.global.ElasticOpenTelemetry; import co.elastic.apm.agent.opentelemetry.tracing.ElasticOpenTelemetryTest; import co.elastic.apm.agent.opentelemetry.tracing.OTelSpan; @@ -100,7 +97,7 @@ public void createOTelSpanWithRemoteContext() { @Then("Elastic bridged transaction has remote context as parent") public void bridgedTransactionWithRemoteContextParent() { - TraceContext traceContext = getBridgedTransaction().getTraceContext(); + TraceContextImpl traceContext = getBridgedTransaction().getTraceContext(); assertThat(traceContext.isRoot()).isFalse(); assertThat(traceContext.getParentId().toString()).isEqualTo(REMOTE_PARENT_ID); assertThat(traceContext.getTraceId().toString()).isEqualTo(REMOTE_PARENT_TRACE_ID); @@ -125,7 +122,7 @@ public void createOTelSpanWithoutParent(){ @Then("Elastic bridged transaction is a root transaction") public void bridgedTransactionIsRootTransaction() { - TraceContext traceContext = getBridgedTransaction().getTraceContext(); + TraceContextImpl traceContext = getBridgedTransaction().getTraceContext(); assertThat(traceContext.isRoot()).isTrue(); } @@ -146,7 +143,7 @@ public void bridgedSpanHasLocalParent() { SpanContext otelParentContext = io.opentelemetry.api.trace.Span.fromContext(localParentContext).getSpanContext(); - TraceContext bridgedSpanContext = getBridgedSpan().getTraceContext(); + TraceContextImpl bridgedSpanContext = getBridgedSpan().getTraceContext(); assertThat(bridgedSpanContext.getTraceId().toString()).isEqualTo(otelParentContext.getTraceId()); assertThat(bridgedSpanContext.getParentId().toString()).isEqualTo(otelParentContext.getSpanId()); } @@ -157,7 +154,7 @@ public void bridgedSpanHasLocalParent() { public void otelSpanIsCreatedWithKind(String kind) { // we have to use a parent transaction as we are creating a span // the parent transaction is created by another step definition, thus we reuse the existing state - Transaction parentTransaction = state.getTransaction(); + TransactionImpl parentTransaction = state.getTransaction(); Function createSpanWithKind = k -> { SpanBuilder spanBuilder = getOtel().getTracer("") @@ -262,14 +259,14 @@ public void bridgeSpanType(String type) { @Then("Elastic bridged {contextType} type is {string}") public void bridgeObjectType(String contextType, String expected) { - AbstractSpan bridgedObject = getBridgedAbstractSpan(); + AbstractSpanImpl bridgedObject = getBridgedAbstractSpan(); String type; - if (bridgedObject instanceof Transaction) { + if (bridgedObject instanceof TransactionImpl) { assertThat(contextType).isEqualTo("transaction"); - type = ((Transaction) bridgedObject).getType(); + type = ((TransactionImpl) bridgedObject).getType(); } else { assertThat(contextType).isEqualTo("span"); - type = ((Span) bridgedObject).getType(); + type = ((SpanImpl) bridgedObject).getType(); } assertThat(type).isEqualTo(expected); @@ -315,7 +312,7 @@ public void bridgedTransactionResultNull() { @Then("Elastic bridged span service target type is {string} and name is {string}") public void bridgedSpanTargetServiceType(String type, String name) { - ServiceTarget serviceTarget = getBridgedSpan().getContext().getServiceTarget(); + ServiceTargetImpl serviceTarget = getBridgedSpan().getContext().getServiceTarget(); assertThat(serviceTarget).hasType(type); if (name != null && !name.isEmpty()) { @@ -337,20 +334,20 @@ public void otelSpanEnds() { otelSpan.end(); } - private AbstractSpan getBridgedAbstractSpan() { - return getBridgedObject(AbstractSpan.class); + private AbstractSpanImpl getBridgedAbstractSpan() { + return getBridgedObject(AbstractSpanImpl.class); } - private Transaction getBridgedTransaction() { - return getBridgedObject(Transaction.class); + private TransactionImpl getBridgedTransaction() { + return getBridgedObject(TransactionImpl.class); } - private Span getBridgedSpan() { - return getBridgedObject(Span.class); + private SpanImpl getBridgedSpan() { + return getBridgedObject(SpanImpl.class); } - private > T getBridgedObject(Class expectedType) { - AbstractSpan internalSpan = otelSpan.getInternalSpan(); + private > T getBridgedObject(Class expectedType) { + AbstractSpanImpl internalSpan = otelSpan.getInternalSpan(); assertThat(internalSpan).isInstanceOf(expectedType); return expectedType.cast(internalSpan); } diff --git a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-test/pom.xml b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-test/pom.xml index 9718aa4406..f1ed785e52 100644 --- a/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-test/pom.xml +++ b/apm-agent-plugins/apm-opentelemetry/apm-opentelemetry-test/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm apm-opentelemetry - 1.50.0 + 1.51.0 ${project.groupId}:${project.artifactId} diff --git a/apm-agent-plugins/apm-opentelemetry/pom.xml b/apm-agent-plugins/apm-opentelemetry/pom.xml index 08e960a38d..b1643fd8e5 100644 --- a/apm-agent-plugins/apm-opentelemetry/pom.xml +++ b/apm-agent-plugins/apm-opentelemetry/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-agent-plugins - 1.50.0 + 1.51.0 apm-opentelemetry @@ -20,7 +20,7 @@ to make sure that in the future we stay compatible with the previous version. --> 1.32.0 - 1.23.1-alpha + 1.25.0-alpha 8 8 @@ -36,7 +36,6 @@ - ${project.groupId} apm-agent-core diff --git a/apm-agent-plugins/apm-opentracing-plugin/pom.xml b/apm-agent-plugins/apm-opentracing-plugin/pom.xml index 55a754dd64..d497b04a43 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/pom.xml +++ b/apm-agent-plugins/apm-opentracing-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-opentracing-plugin @@ -16,7 +16,6 @@ - ${project.groupId} apm-agent-core diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmScopeInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmScopeInstrumentation.java index e3becb8cca..92212b8cfc 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmScopeInstrumentation.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmScopeInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.opentracingimpl; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -34,8 +34,8 @@ public class ApmScopeInstrumentation extends OpenTracingBridgeInstrumentation { public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void release(@Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) @Nullable Object context) { - if (context instanceof AbstractSpan) { - ((AbstractSpan) context).deactivate(); + if (context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).deactivate(); } } } diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmSpanBuilderInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmSpanBuilderInstrumentation.java index b343ba3fe0..90a4b0ac35 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmSpanBuilderInstrumentation.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmSpanBuilderInstrumentation.java @@ -21,9 +21,9 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.sampling.ConstantSampler; import co.elastic.apm.agent.impl.sampling.Sampler; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; @@ -76,28 +76,28 @@ public static Object createSpan(@Advice.Argument(value = 0, typing = Assigner.Ty @Advice.FieldValue(value = "operationName") String operationName, @Advice.FieldValue(value = "microseconds") long microseconds, @Advice.Argument(1) @Nullable Iterable> baggage) { - AbstractSpan parent = null; - if (parentContext instanceof AbstractSpan) { - parent = (AbstractSpan) parentContext; + AbstractSpanImpl parent = null; + if (parentContext instanceof AbstractSpanImpl) { + parent = (AbstractSpanImpl) parentContext; } return doCreateTransactionOrSpan(parent, tags, operationName, microseconds, baggage, PrivilegedActionUtils.getClassLoader(spanBuilderClass)); } @Nullable - public static AbstractSpan doCreateTransactionOrSpan(@Nullable AbstractSpan parentContext, - Map tags, - String operationName, long microseconds, - @Nullable Iterable> baggage, ClassLoader applicationClassLoader) { - AbstractSpan result = null; + public static AbstractSpanImpl doCreateTransactionOrSpan(@Nullable AbstractSpanImpl parentContext, + Map tags, + String operationName, long microseconds, + @Nullable Iterable> baggage, ClassLoader applicationClassLoader) { + AbstractSpanImpl result = null; ElasticApmTracer tracer = OpenTracingBridgeInstrumentation.tracer.require(ElasticApmTracer.class); if (tracer != null) { if (parentContext == null) { result = createTransaction(tags, operationName, microseconds, baggage, tracer, applicationClassLoader); } else { if (microseconds >= 0) { - result = tracer.startSpan(TraceContext.fromParent(), parentContext, parentContext.getBaggage(), microseconds); + result = tracer.startSpan(TraceContextImpl.fromParent(), parentContext, parentContext.getBaggage(), microseconds); } else { - result = tracer.startSpan(TraceContext.fromParent(), parentContext, parentContext.getBaggage()); + result = tracer.startSpan(TraceContextImpl.fromParent(), parentContext, parentContext.getBaggage()); } } } @@ -116,8 +116,8 @@ public static AbstractSpan doCreateTransactionOrSpan(@Nullable AbstractSpan createTransaction(Map tags, String operationName, long microseconds, - @Nullable Iterable> baggage, ElasticApmTracer tracer, ClassLoader classLoader) { + private static AbstractSpanImpl createTransaction(Map tags, String operationName, long microseconds, + @Nullable Iterable> baggage, ElasticApmTracer tracer, ClassLoader classLoader) { if ("client".equals(tags.get("span.kind"))) { logger.info("Ignoring transaction '{}', as a span.kind client can never be a transaction. " + "Consider creating a span for the whole request.", operationName); @@ -130,7 +130,7 @@ private static AbstractSpan createTransaction(Map tags, Strin } else { sampler = tracer.getSampler(); } - Transaction transaction = tracer.startChildTransaction(baggage, OpenTracingTextMapBridge.instance(), sampler, microseconds, classLoader); + TransactionImpl transaction = tracer.startChildTransaction(baggage, OpenTracingTextMapBridge.instance(), sampler, microseconds, classLoader); if (transaction != null) { transaction.setFrameworkName(FRAMEWORK_NAME); } diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmSpanInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmSpanInstrumentation.java index 09a7e4c5b7..db9d43842e 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmSpanInstrumentation.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ApmSpanInstrumentation.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.opentracingimpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.util.ResultUtil; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -66,15 +66,15 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void finishInternal(@Advice.FieldValue(value = "dispatcher", typing = Assigner.Typing.DYNAMIC) @Nullable Object context, @Advice.Argument(0) long finishMicros) { - if (context instanceof AbstractSpan) { - doFinishInternal((AbstractSpan) context, finishMicros); + if (context instanceof AbstractSpanImpl) { + doFinishInternal((AbstractSpanImpl) context, finishMicros); } } - public static void doFinishInternal(AbstractSpan abstractSpan, long finishMicros) { + public static void doFinishInternal(AbstractSpanImpl abstractSpan, long finishMicros) { abstractSpan.incrementReferences(); - if (abstractSpan instanceof Transaction) { - Transaction transaction = (Transaction) abstractSpan; + if (abstractSpan instanceof TransactionImpl) { + TransactionImpl transaction = (TransactionImpl) abstractSpan; if (transaction.getType() == null) { if (transaction.getContext().getRequest().hasContent()) { transaction.withType(co.elastic.apm.agent.tracer.Transaction.TYPE_REQUEST); @@ -99,8 +99,8 @@ public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void setOperationName(@Advice.FieldValue(value = "dispatcher", typing = Assigner.Typing.DYNAMIC) @Nullable Object context, @Advice.Argument(0) @Nullable String operationName) { - if (context instanceof AbstractSpan) { - ((AbstractSpan) context).withName(operationName, PRIORITY_USER_SUPPLIED); + if (context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).withName(operationName, PRIORITY_USER_SUPPLIED); } else { logger.warn("Calling setOperationName on an already finished span"); } @@ -119,8 +119,8 @@ public static void log(@Advice.FieldValue(value = "dispatcher", typing = Assigne @Advice.Argument(0) long epochTimestampMicros, @Advice.Argument(1) Map fields) { - if (context instanceof AbstractSpan) { - AbstractSpan span = (AbstractSpan) context; + if (context instanceof AbstractSpanImpl) { + AbstractSpanImpl span = (AbstractSpanImpl) context; if ("error".equals(fields.get("event"))) { final Object errorObject = fields.get("error.object"); if (errorObject instanceof Throwable) { @@ -152,28 +152,28 @@ public static void handleTag(@Advice.FieldValue(value = "dispatcher", typing = A if (value == null) { return; } - if (abstractSpanObj instanceof Transaction) { - handleTransactionTag((Transaction) abstractSpanObj, key, value); - } else if (abstractSpanObj instanceof Span) { - handleSpanTag((Span) abstractSpanObj, key, value); + if (abstractSpanObj instanceof TransactionImpl) { + handleTransactionTag((TransactionImpl) abstractSpanObj, key, value); + } else if (abstractSpanObj instanceof SpanImpl) { + handleSpanTag((SpanImpl) abstractSpanObj, key, value); } else { logger.warn("Calling setTag on an already finished span"); } } - private static void handleTransactionTag(Transaction transaction, String key, Object value) { + private static void handleTransactionTag(TransactionImpl transaction, String key, Object value) { if (!handleSpecialTransactionTag(transaction, key, value)) { addTag(transaction, key, value); } } - private static void handleSpanTag(Span span, String key, Object value) { + private static void handleSpanTag(SpanImpl span, String key, Object value) { if (!handleSpecialSpanTag(span, key, value)) { addTag(span, key, value); } } - private static void addTag(AbstractSpan transaction, String key, Object value) { + private static void addTag(AbstractSpanImpl transaction, String key, Object value) { if (value instanceof Number) { transaction.addLabel(key, (Number) value); } else if (value instanceof Boolean) { @@ -185,7 +185,7 @@ private static void addTag(AbstractSpan transaction, String key, Object value // unfortunately, we can't use the constants in io.opentracing.tag.Tags, // as we can't declare a direct dependency on the OT API - private static boolean handleSpecialTransactionTag(Transaction transaction, String key, Object value) { + private static boolean handleSpecialTransactionTag(TransactionImpl transaction, String key, Object value) { if ("type".equals(key)) { transaction.withType(value.toString()); return true; @@ -228,7 +228,7 @@ private static boolean handleSpecialTransactionTag(Transaction transaction, Stri return false; } - private static boolean handleSpecialSpanTag(Span span, String key, Object value) { + private static boolean handleSpecialSpanTag(SpanImpl span, String key, Object value) { //noinspection IfCanBeSwitch if ("type".equals(key)) { if (span.getSubtype() == null && span.getAction() == null) { diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ElasticApmTracerInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ElasticApmTracerInstrumentation.java index fa9e090e80..fd992996fc 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ElasticApmTracerInstrumentation.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ElasticApmTracerInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.opentracingimpl; -import co.elastic.apm.agent.impl.Tracer; +import co.elastic.apm.agent.impl.ElasticApmTracer; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -30,7 +30,7 @@ public class ElasticApmTracerInstrumentation extends OpenTracingBridgeInstrument public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void close() { - tracer.require(Tracer.class).stop(); + tracer.require(ElasticApmTracer.class).stop(); } } diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ExternalSpanContextInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ExternalSpanContextInstrumentation.java index 30a05603d6..f6b618694c 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ExternalSpanContextInstrumentation.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ExternalSpanContextInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.opentracingimpl; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice.AssignReturned.ToFields.ToField; import net.bytebuddy.description.method.MethodDescription; @@ -75,10 +75,10 @@ public static Object toTraceId(@Advice.FieldValue(value = "textMap", typing = As @Advice.AssignReturned.ToReturned @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static String onExit(@Advice.FieldValue(value = "childTraceContext", typing = Assigner.Typing.DYNAMIC) @Nullable Object childTraceContextObj) { - if (!(childTraceContextObj instanceof TraceContext)) { + if (!(childTraceContextObj instanceof TraceContextImpl)) { return null; } - return ((TraceContext) childTraceContextObj).getTraceId().toString(); + return ((TraceContextImpl) childTraceContextObj).getTraceId().toString(); } } } @@ -106,19 +106,19 @@ public static Object toSpanId(@Advice.FieldValue(value = "textMap", typing = Ass @Advice.AssignReturned.ToReturned @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static String onExit(@Advice.FieldValue(value = "childTraceContext", typing = Assigner.Typing.DYNAMIC) @Nullable Object childTraceContextObj) { - if (!(childTraceContextObj instanceof TraceContext)) { + if (!(childTraceContextObj instanceof TraceContextImpl)) { return null; } - return ((TraceContext) childTraceContextObj).getParentId().toString(); + return ((TraceContextImpl) childTraceContextObj).getParentId().toString(); } } } @Nullable - public static TraceContext parseTextMap(Iterable> textMap) { + public static TraceContextImpl parseTextMap(Iterable> textMap) { ElasticApmTracer tracer = OpenTracingBridgeInstrumentation.tracer.require(ElasticApmTracer.class); if (tracer != null) { - TraceContext childTraceContext = TraceContext.with64BitId(tracer); + TraceContextImpl childTraceContext = TraceContextImpl.with64BitId(tracer); if (childTraceContext.asChildOf(textMap, OpenTracingTextMapBridge.instance())) { return childTraceContext; } diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ScopeManagerInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ScopeManagerInstrumentation.java index f0cdce5070..4b45451d81 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ScopeManagerInstrumentation.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/ScopeManagerInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.opentracingimpl; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -56,8 +56,8 @@ public ActivateInstrumentation() { public static class AdviceClass { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void doActivate(@Advice.Argument(value = 0, typing = Assigner.Typing.DYNAMIC) @Nullable Object context) { - if (context instanceof AbstractSpan) { - ((AbstractSpan) context).activate(); + if (context instanceof AbstractSpanImpl) { + ((AbstractSpanImpl) context).activate(); } } } diff --git a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/SpanContextInstrumentation.java b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/SpanContextInstrumentation.java index 9d81be2899..dcd48a9eac 100644 --- a/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/SpanContextInstrumentation.java +++ b/apm-agent-plugins/apm-opentracing-plugin/src/main/java/co/elastic/apm/agent/opentracingimpl/SpanContextInstrumentation.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.opentracingimpl; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.ElasticContext; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceStateImpl; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; import net.bytebuddy.asm.Advice; @@ -66,15 +66,15 @@ public static class AdviceClass { @Advice.AssignReturned.ToReturned @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static Iterable> baggageItems(@Advice.FieldValue(value = "traceContext", typing = Assigner.Typing.DYNAMIC) @Nullable Object context) { - if (context instanceof ElasticContext) { - return doGetBaggage((ElasticContext) context); + if (context instanceof TraceStateImpl) { + return doGetBaggage((TraceStateImpl) context); } else { logger.info("The traceContext is null"); return null; } } - public static Iterable> doGetBaggage(ElasticContext traceContext) { + public static Iterable> doGetBaggage(TraceStateImpl traceContext) { Map baggage = new HashMap(); traceContext.propagateContext(baggage, OpenTracingTextMapBridge.instance(), null); return baggage.entrySet(); @@ -93,10 +93,10 @@ public static class AdviceClass { @Advice.AssignReturned.ToReturned @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static String toTraceId(@Advice.FieldValue(value = "traceContext", typing = Assigner.Typing.DYNAMIC) @Nullable Object context) { - if (!(context instanceof AbstractSpan)) { + if (!(context instanceof AbstractSpanImpl)) { return null; } - AbstractSpan traceContext = (AbstractSpan) context; + AbstractSpanImpl traceContext = (AbstractSpanImpl) context; return traceContext.getTraceContext().getTraceId().toString(); } } @@ -113,10 +113,10 @@ public static class AdviceClass { @Advice.AssignReturned.ToReturned @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static String toTraceId(@Advice.FieldValue(value = "traceContext", typing = Assigner.Typing.DYNAMIC) @Nullable Object context) { - if (!(context instanceof AbstractSpan)) { + if (!(context instanceof AbstractSpanImpl)) { return null; } - AbstractSpan traceContext = (AbstractSpan) context; + AbstractSpanImpl traceContext = (AbstractSpanImpl) context; return traceContext.getTraceContext().getId().toString(); } } diff --git a/apm-agent-plugins/apm-process-plugin/pom.xml b/apm-agent-plugins/apm-process-plugin/pom.xml index c6f7d25720..44830d677a 100644 --- a/apm-agent-plugins/apm-process-plugin/pom.xml +++ b/apm-agent-plugins/apm-process-plugin/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessHelper.java b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessHelper.java index 15ce912362..288d2c6f82 100644 --- a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessHelper.java +++ b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessHelper.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.process; import co.elastic.apm.agent.sdk.state.GlobalVariables; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; @@ -54,7 +54,7 @@ public static boolean isTracingOnCurrentThread() { return inTracingContext.get() == Boolean.TRUE; } - static void startProcess(ElasticContext activeContext, Process process, List command) { + static void startProcess(TraceState activeContext, Process process, List command) { INSTANCE.doStartProcess(activeContext, process, command.get(0)); } @@ -73,7 +73,7 @@ static void endProcessSpan(@Nonnull Process process, int exitValue) { * @param process started process * @param processName process name */ - void doStartProcess(ElasticContext activeContext, @Nonnull Process process, @Nonnull String processName) { + void doStartProcess(TraceState activeContext, @Nonnull Process process, @Nonnull String processName) { if (inFlightSpans.contains(process)) { return; } diff --git a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessStartInstrumentation.java b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessStartInstrumentation.java index 929b0904ca..b746e70af7 100644 --- a/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessStartInstrumentation.java +++ b/apm-agent-plugins/apm-process-plugin/src/main/java/co/elastic/apm/agent/process/ProcessStartInstrumentation.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.process; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.type.TypeDescription; @@ -58,7 +58,7 @@ public static void onExit(@Advice.This ProcessBuilder processBuilder, @Advice.Return @Nullable Process process, @Advice.Thrown @Nullable Throwable t) { - ElasticContext activeContext = tracer.currentContext(); + TraceState activeContext = tracer.currentContext(); AbstractSpan parentSpan = activeContext.getSpan(); if (parentSpan == null) { return; diff --git a/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/CommonsExecAsyncInstrumentationTest.java b/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/CommonsExecAsyncInstrumentationTest.java index 616a6f69f2..931d856406 100644 --- a/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/CommonsExecAsyncInstrumentationTest.java +++ b/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/CommonsExecAsyncInstrumentationTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.process; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.test.JavaExecutable; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecuteResultHandler; @@ -78,8 +78,8 @@ void processWithExitValueCheck() throws Exception { terminateTransaction(); } - private static CompletableFuture> asyncProcessHasTransactionContext() throws Exception { - final CompletableFuture> future = new CompletableFuture<>(); + private static CompletableFuture> asyncProcessHasTransactionContext() throws Exception { + final CompletableFuture> future = new CompletableFuture<>(); DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler() { // note: calling super is required otherwise process termination is not detected and waits forever @@ -112,7 +112,7 @@ public void onProcessFailed(ExecuteException e) { } private static void startTransaction() { - Transaction transaction = tracer.startRootTransaction(CommonsExecAsyncInstrumentationTest.class.getClassLoader()); + TransactionImpl transaction = tracer.startRootTransaction(CommonsExecAsyncInstrumentationTest.class.getClassLoader()); assertThat(transaction).isNotNull(); transaction.withType("request") @@ -121,7 +121,7 @@ private static void startTransaction() { } private static void terminateTransaction() { - Transaction transaction = tracer.currentTransaction(); + TransactionImpl transaction = tracer.currentTransaction(); assertThat(transaction).isNotNull(); transaction.deactivate().end(); diff --git a/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/ProcessHelperTest.java b/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/ProcessHelperTest.java index 84f95db191..42d847c1a2 100644 --- a/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/ProcessHelperTest.java +++ b/apm-agent-plugins/apm-process-plugin/src/test/java/co/elastic/apm/agent/process/ProcessHelperTest.java @@ -20,10 +20,10 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.TransactionUtils; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; import org.junit.jupiter.api.BeforeEach; @@ -48,14 +48,14 @@ class ProcessHelperTest extends AbstractInstrumentationTest { // of this instrumentation is. Also, integration test cover this feature for the general case with a packaged // agent and thus they don't have such limitation - private Transaction transaction; + private TransactionImpl transaction; private WeakMap> storageMap; private ProcessHelper helper; @BeforeEach void before() { - transaction = new Transaction(tracer); + transaction = new TransactionImpl(tracer); TransactionUtils.fillTransaction(transaction); storageMap = WeakConcurrent.buildMap(); @@ -95,7 +95,7 @@ void checkSpanNaming() { helper.doEndProcess(process, true); - Span span = getFirstSpan(); + SpanImpl span = getFirstSpan(); assertThat(span.getNameAsString()).isEqualTo(binaryName); assertThat(span.getType()).isEqualTo("process"); @@ -109,7 +109,7 @@ void startTwiceShouldIgnore() { Process process = mock(Process.class); helper.doStartProcess(transaction, process, "hello"); - Span span = (Span) storageMap.get(process); + SpanImpl span = (SpanImpl) storageMap.get(process); helper.doStartProcess(transaction, process, "hello"); assertThat(storageMap.get(process)) @@ -223,7 +223,7 @@ void waitForWithTimeoutDoesNotEndProcessSpan() { helper.doEndProcess(process, true); assertThat(storageMap).isEmpty(); - Span span = getFirstSpan(); + SpanImpl span = getFirstSpan(); assertThat(span.getOutcome()).isEqualTo(Outcome.SUCCESS); } @@ -245,7 +245,7 @@ void destroyWithoutProcessTerminatedShouldEndSpan() { assertThat(getFirstSpan().getOutcome()).isEqualTo(Outcome.UNKNOWN); } - private Span getFirstSpan() { + private SpanImpl getFirstSpan() { assertThat(reporter.getSpans()).hasSize(1); return reporter.getSpans().get(0); } diff --git a/apm-agent-plugins/apm-profiling-plugin/pom.xml b/apm-agent-plugins/apm-profiling-plugin/pom.xml index 7f8022d5ec..1110191a05 100644 --- a/apm-agent-plugins/apm-profiling-plugin/pom.xml +++ b/apm-agent-plugins/apm-profiling-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-profiling-plugin @@ -16,7 +16,6 @@ - ${project.groupId} apm-agent-core diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/CallTree.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/CallTree.java index 3042fee406..a1252e9081 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/CallTree.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/CallTree.java @@ -18,11 +18,12 @@ */ package co.elastic.apm.agent.profiler; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import co.elastic.apm.agent.sdk.internal.collections.LongList; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.Span; import co.elastic.apm.agent.impl.transaction.StackFrame; -import co.elastic.apm.agent.impl.transaction.TraceContext; import co.elastic.apm.agent.profiler.collections.LongHashSet; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -71,12 +72,12 @@ public class CallTree implements Recyclable { * Used in {@link #spanify} to override the parent. */ @Nullable - private TraceContext activeContextOfDirectParent; + private TraceContextImpl activeContextOfDirectParent; private long deactivationTimestamp = -1; private boolean isSpan; private int depth; /** - * @see co.elastic.apm.agent.impl.transaction.AbstractSpan#childIds + * @see AbstractSpanImpl#childIds */ @Nullable private ChildList childIds; @@ -115,12 +116,12 @@ public CallTree getNthParent(int n) { return parent; } - public void activation(TraceContext traceContext, long activationTimestamp) { + public void activation(TraceContextImpl traceContext, long activationTimestamp) { this.activeContextOfDirectParent = traceContext; this.activationTimestamp = activationTimestamp; } - protected void handleDeactivation(TraceContext deactivatedSpan, long activationTimestamp, long deactivationTimestamp) { + protected void handleDeactivation(TraceContextImpl deactivatedSpan, long activationTimestamp, long deactivationTimestamp) { if (deactivatedSpan.idEquals(activeContextOfDirectParent)) { this.deactivationTimestamp = deactivationTimestamp; } else { @@ -167,7 +168,7 @@ public static CallTree.Root createRoot(ObjectPool rootPool, byte[] traceCo * @param minDurationNs * @param root */ - protected CallTree addFrame(List stackFrames, int index, @Nullable TraceContext activeSpan, long activationTimestamp, long nanoTime, ObjectPool callTreePool, long minDurationNs, Root root) { + protected CallTree addFrame(List stackFrames, int index, @Nullable TraceContextImpl activeSpan, long activationTimestamp, long nanoTime, ObjectPool callTreePool, long minDurationNs, Root root) { count++; lastSeen = nanoTime; // c ee ← traceContext not set - they are not a child of the active span but the frame below them @@ -227,7 +228,7 @@ private void transferMaybeChildIdsToChildIds() { } } - private CallTree addChild(StackFrame frame, List stackFrames, int index, @Nullable TraceContext traceContext, long activationTimestamp, long nanoTime, ObjectPool callTreePool, long minDurationNs, Root root) { + private CallTree addChild(StackFrame frame, List stackFrames, int index, @Nullable TraceContextImpl traceContext, long activationTimestamp, long nanoTime, ObjectPool callTreePool, long minDurationNs, Root root) { CallTree callTree = callTreePool.createInstance(); callTree.set(this, frame, nanoTime); if (traceContext != null) { @@ -375,13 +376,13 @@ private void toString(Appendable out, int level) throws IOException { } } - int spanify(CallTree.Root root, TraceContext parentContext, TraceContext nonInferredParentContext) { + int spanify(CallTree.Root root, TraceContextImpl parentContext, TraceContextImpl nonInferredParentContext) { int createdSpans = 0; if (activeContextOfDirectParent != null) { parentContext = activeContextOfDirectParent; nonInferredParentContext = activeContextOfDirectParent; } - Span span = null; + SpanImpl span = null; if (!isPillar() || isLeaf()) { createdSpans++; span = asSpan(root, parentContext, nonInferredParentContext); @@ -397,9 +398,9 @@ int spanify(CallTree.Root root, TraceContext parentContext, TraceContext nonInfe return createdSpans; } - protected Span asSpan(Root root, TraceContext parentContext, TraceContext nonInferredParentContext) { + protected SpanImpl asSpan(Root root, TraceContextImpl parentContext, TraceContextImpl nonInferredParentContext) { transferMaybeChildIdsToChildIds(); - Span span = parentContext.createSpan(root.getEpochMicros(this.start)) + SpanImpl span = parentContext.createSpan(root.getEpochMicros(this.start)) .withType("app") .withSubtype("inferred"); @@ -493,8 +494,8 @@ public void resetState() { /** * When a regular span is activated, - * we want it's {@link TraceContext#getId() span.id} to be added to the call tree that represents the - * {@linkplain CallTree.Root#topOfStack top of the stack} to ensure correct parent/child relationships via re-parenting (See also {@link Span#childIds}). + * we want it's {@link TraceContextImpl#getId() span.id} to be added to the call tree that represents the + * {@linkplain CallTree.Root#topOfStack top of the stack} to ensure correct parent/child relationships via re-parenting (See also {@link SpanImpl#childIds}). *

* However, the {@linkplain CallTree.Root#topOfStack current top of the stack} may turn out to not be the right target. * Consider this example: @@ -593,23 +594,23 @@ public static class Root extends CallTree implements Recyclable { * The context of the thread root, * mostly a transaction or a span which got activated in an auxiliary thread */ - protected TraceContext rootContext; + protected TraceContextImpl rootContext; /** * The context of the transaction or span which is currently {@link ElasticApmTracer#getActive() active}. * This is lazily deserialized from {@link #activeSpanSerialized} if there's an actual {@linkplain #addStackTrace stack trace} * for this activation. */ @Nullable - private TraceContext activeSpan; + private TraceContextImpl activeSpan; /** * The timestamp of when {@link #activeSpan} got activated */ private long activationTimestamp = -1; /** * The context of the transaction or span which is currently {@link ElasticApmTracer#getActive() active}, - * in its {@linkplain TraceContext#serialize serialized} form. + * in its {@linkplain TraceContextImpl#serialize serialized} form. */ - private byte[] activeSpanSerialized = new byte[TraceContext.SERIALIZED_LENGTH]; + private byte[] activeSpanSerialized = new byte[TraceContextImpl.SERIALIZED_LENGTH]; @Nullable private CallTree previousTopOfStack; @Nullable @@ -618,7 +619,7 @@ public static class Root extends CallTree implements Recyclable { private final LongHashSet activeSet = new LongHashSet(); public Root(ElasticApmTracer tracer) { - this.rootContext = TraceContext.with64BitId(tracer); + this.rootContext = TraceContextImpl.with64BitId(tracer); } private void set(byte[] traceContext, @Nullable String serviceName, @Nullable String serviceVersion, long nanoTime) { @@ -636,10 +637,10 @@ public void setActiveSpan(byte[] activeSpanSerialized, long timestamp) { public void onActivation(byte[] active, long timestamp) { setActiveSpan(active, timestamp); if (topOfStack != null) { - long spanId = TraceContext.getSpanId(active); + long spanId = TraceContextImpl.getSpanId(active); activeSet.add(spanId); if (!isNestedActivation(topOfStack)) { - topOfStack.addMaybeChildId(spanId, TraceContext.getParentId(active)); + topOfStack.addMaybeChildId(spanId, TraceContextImpl.getParentId(active)); } } } @@ -673,7 +674,7 @@ public void onDeactivation(byte[] deactivated, byte[] active, long timestamp) { // that's because isNestedActivation is only called if topOfStack != null // this optimizes for the case where we have no stack traces for a fast executing transaction if (topOfStack != null) { - long spanId = TraceContext.getSpanId(deactivated); + long spanId = TraceContextImpl.getSpanId(deactivated); activeSet.remove(spanId); } } @@ -684,7 +685,7 @@ public void addStackTrace(ElasticApmTracer tracer, List stackTrace, boolean firstFrameAfterActivation = false; if (activeSpan == null) { firstFrameAfterActivation = true; - activeSpan = TraceContext.with64BitId(tracer); + activeSpan = TraceContextImpl.with64BitId(tracer); activeSpan.deserialize(activeSpanSerialized, rootContext.getServiceName(), rootContext.getServiceVersion()); } previousTopOfStack = topOfStack; @@ -726,12 +727,12 @@ private CallTree findCommonAncestor(CallTree previousTopOfStack, CallTree topOfS /** * Creates spans for call tree nodes if they are either not a {@linkplain #isPillar() pillar} or are a {@linkplain #isLeaf() leaf}. - * Nodes which are not converted to {@link Span}s are part of the {@link Span#stackFrames} for the nodes which do get converted to a span. + * Nodes which are not converted to {@link SpanImpl}s are part of the {@link SpanImpl#stackFrames} for the nodes which do get converted to a span. *

* Parent/child relationships with the regular spans are maintained. * One exception is that an inferred span can't be the parent of a regular span. * That is because the regular spans have already been reported once the inferred spans are created. - * In the future, we might make it possible to update the {@link TraceContext#parentId} + * In the future, we might make it possible to update the {@link TraceContextImpl#parentId} * of a regular span so that it correctly reflects being a child of an inferred span. *

*/ @@ -744,7 +745,7 @@ public int spanify() { return createdSpans; } - public TraceContext getRootContext() { + public TraceContextImpl getRootContext() { return rootContext; } diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingActivationListener.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingActivationListener.java index 2e299f63d5..e139081dbd 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingActivationListener.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/ProfilingActivationListener.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.impl.ActivationListener; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import co.elastic.apm.agent.sdk.internal.ThreadUtil; import java.util.Objects; @@ -40,17 +40,17 @@ public ProfilingActivationListener(ElasticApmTracer tracer) { } @Override - public void beforeActivate(AbstractSpan context) { + public void beforeActivate(AbstractSpanImpl context) { if (context.isSampled() && !ThreadUtil.isVirtual(Thread.currentThread())) { - AbstractSpan active = tracer.getActive(); + AbstractSpanImpl active = tracer.getActive(); profiler.onActivation(context.getTraceContext(), active != null ? active.getTraceContext() : null); } } @Override - public void afterDeactivate(AbstractSpan deactivatedContext) { + public void afterDeactivate(AbstractSpanImpl deactivatedContext) { if (deactivatedContext.isSampled() && !ThreadUtil.isVirtual(Thread.currentThread())) { - AbstractSpan active = tracer.getActive(); + AbstractSpanImpl active = tracer.getActive(); profiler.onDeactivation(deactivatedContext.getTraceContext(), active != null ? active.getTraceContext() : null); } } diff --git a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java index 860a0896de..daa584520c 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/main/java/co/elastic/apm/agent/profiler/SamplingProfiler.java @@ -19,11 +19,11 @@ package co.elastic.apm.agent.profiler; import co.elastic.apm.agent.common.util.WildcardMatcher; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import co.elastic.apm.agent.tracer.AbstractLifecycleListener; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.Span; import co.elastic.apm.agent.impl.transaction.StackFrame; -import co.elastic.apm.agent.impl.transaction.TraceContext; import co.elastic.apm.agent.profiler.asyncprofiler.AsyncProfiler; import co.elastic.apm.agent.profiler.asyncprofiler.JfrParser; import co.elastic.apm.agent.profiler.collections.Long2ObjectHashMap; @@ -77,8 +77,8 @@ *

*

* The {@link #onActivation} and {@link #onDeactivation} methods are called by {@link ProfilingActivationListener} - * which register an {@link ActivationEvent} to a {@linkplain #eventBuffer ring buffer} whenever a {@link Span} - * gets {@link Span#activate()}d or {@link Span#deactivate()}d while a {@linkplain #profilingSessionOngoing profiling session is ongoing}. + * which register an {@link ActivationEvent} to a {@linkplain #eventBuffer ring buffer} whenever a {@link SpanImpl} + * gets {@link SpanImpl#activate()}d or {@link SpanImpl#deactivate()}d while a {@linkplain #profilingSessionOngoing profiling session is ongoing}. * A background thread consumes the {@link ActivationEvent}s and writes them to a {@linkplain #activationEventsBuffer direct buffer} * which is flushed to a {@linkplain #activationEventsFileChannel file}. * That is necessary because within a profiling session (which lasts 10s by default) there may be many more {@link ActivationEvent}s @@ -102,11 +102,11 @@ * After both the JFR file and the file containing the {@link ActivationEvent}s have been written, * it's now time to process them in tandem by correlating based on thread ids and timestamps. * The result of this correlation, performed by {@link #processTraces}, - * are {@link CallTree}s which are created for each thread which has seen an {@linkplain Span#activate() activation} + * are {@link CallTree}s which are created for each thread which has seen an {@linkplain SpanImpl#activate() activation} * and at least one stack trace. * Once {@linkplain ActivationEvent#handleDeactivationEvent(SamplingProfiler) handling the deactivation event} of the root span in a thread * (after which {@link ElasticApmTracer#getActive()} would return {@code null}), - * the {@link CallTree} is {@linkplain CallTree#spanify(CallTree.Root, TraceContext, TraceContext) converted into regular spans}. + * the {@link CallTree} is {@linkplain CallTree#spanify(CallTree.Root, TraceContextImpl, TraceContextImpl) converted into regular spans}. *

*

* Overall, the allocation rate does not depend on the number of {@link ActivationEvent}s but only on @@ -125,17 +125,17 @@ public class SamplingProfiler extends AbstractLifecycleListener implements Runna private static final int PRE_ALLOCATE_ACTIVATION_EVENTS_FILE_MB = 10; private static final int MAX_ACTIVATION_EVENTS_FILE_SIZE = ACTIVATION_EVENTS_IN_FILE * ActivationEvent.SERIALIZED_SIZE; private static final int ACTIVATION_EVENTS_BUFFER_SIZE = ActivationEvent.SERIALIZED_SIZE * 4 * 1024; - private final EventTranslatorTwoArg ACTIVATION_EVENT_TRANSLATOR = - new EventTranslatorTwoArg() { + private final EventTranslatorTwoArg ACTIVATION_EVENT_TRANSLATOR = + new EventTranslatorTwoArg() { @Override - public void translateTo(ActivationEvent event, long sequence, TraceContext active, TraceContext previouslyActive) { + public void translateTo(ActivationEvent event, long sequence, TraceContextImpl active, TraceContextImpl previouslyActive) { event.activation(active, Thread.currentThread().getId(), previouslyActive, nanoClock.nanoTime()); } }; - private final EventTranslatorTwoArg DEACTIVATION_EVENT_TRANSLATOR = - new EventTranslatorTwoArg() { + private final EventTranslatorTwoArg DEACTIVATION_EVENT_TRANSLATOR = + new EventTranslatorTwoArg() { @Override - public void translateTo(ActivationEvent event, long sequence, TraceContext active, TraceContext previouslyActive) { + public void translateTo(ActivationEvent event, long sequence, TraceContextImpl active, TraceContextImpl previouslyActive) { event.deactivation(active, Thread.currentThread().getId(), previouslyActive, nanoClock.nanoTime()); } }; @@ -173,7 +173,7 @@ public void translateTo(ActivationEvent event, long sequence, TraceContext activ @Nullable private FileChannel activationEventsFileChannel; private final ObjectPool callTreePool; - private final TraceContext contextForLogging; + private final TraceContextImpl contextForLogging; private boolean previouslyEnabled = false; @@ -208,7 +208,7 @@ public SamplingProfiler(final ElasticApmTracer tracer, NanoClock nanoClock, @Nul // tells the ring buffer to not override slots which have not been read yet this.eventBuffer.addGatingSequences(sequence); this.poller = eventBuffer.newPoller(); - contextForLogging = TraceContext.with64BitId(tracer); + contextForLogging = TraceContextImpl.with64BitId(tracer); this.callTreePool = tracer.getObjectPoolFactory().createRecyclableObjectPool(2 * 1024, new Allocator() { @Override public CallTree createInstance() { @@ -298,7 +298,7 @@ public ActivationEvent newInstance() { * @param previouslyActive the span which has previously been activated * @return {@code true}, if the event could be processed, {@code false} if the internal event queue is full which means the event has been discarded */ - public boolean onActivation(TraceContext activeSpan, @Nullable TraceContext previouslyActive) { + public boolean onActivation(TraceContextImpl activeSpan, @Nullable TraceContextImpl previouslyActive) { if (profilingSessionOngoing) { if (previouslyActive == null) { AsyncProfiler.getInstance(config.getProfilerLibDirectory(), config.getAsyncProfilerSafeMode()).enableProfilingCurrentThread(); @@ -323,7 +323,7 @@ public boolean onActivation(TraceContext activeSpan, @Nullable TraceContext prev * @param previouslyActive the span which has previously been activated * @return {@code true}, if the event could be processed, {@code false} if the internal event queue is full which means the event has been discarded */ - public boolean onDeactivation(TraceContext activeSpan, @Nullable TraceContext previouslyActive) { + public boolean onDeactivation(TraceContextImpl activeSpan, @Nullable TraceContextImpl previouslyActive) { if (profilingSessionOngoing) { if (previouslyActive == null) { AsyncProfiler.getInstance(config.getProfilerLibDirectory(), config.getAsyncProfilerSafeMode()).disableProfilingCurrentThread(); @@ -799,8 +799,8 @@ private static class ActivationEvent { Long.SIZE / Byte.SIZE + // timestamp Short.SIZE / Byte.SIZE + // serviceName index Short.SIZE / Byte.SIZE + // serviceVersion index - TraceContext.SERIALIZED_LENGTH + // traceContextBuffer - TraceContext.SERIALIZED_LENGTH + // previousContextBuffer + TraceContextImpl.SERIALIZED_LENGTH + // traceContextBuffer + TraceContextImpl.SERIALIZED_LENGTH + // previousContextBuffer 1 + // rootContext Long.SIZE / Byte.SIZE + // threadId 1; // activation @@ -816,21 +816,21 @@ private static class ActivationEvent { private String serviceName; @Nullable private String serviceVersion; - private byte[] traceContextBuffer = new byte[TraceContext.SERIALIZED_LENGTH]; - private byte[] previousContextBuffer = new byte[TraceContext.SERIALIZED_LENGTH]; + private byte[] traceContextBuffer = new byte[TraceContextImpl.SERIALIZED_LENGTH]; + private byte[] previousContextBuffer = new byte[TraceContextImpl.SERIALIZED_LENGTH]; private boolean rootContext; private long threadId; private boolean activation; - public void activation(TraceContext context, long threadId, @Nullable TraceContext previousContext, long nanoTime) { + public void activation(TraceContextImpl context, long threadId, @Nullable TraceContextImpl previousContext, long nanoTime) { set(context, threadId, true, previousContext != null ? previousContext : null, nanoTime); } - public void deactivation(TraceContext context, long threadId, @Nullable TraceContext previousContext, long nanoTime) { + public void deactivation(TraceContextImpl context, long threadId, @Nullable TraceContextImpl previousContext, long nanoTime) { set(context, threadId, false, previousContext != null ? previousContext : null, nanoTime); } - private void set(TraceContext traceContext, long threadId, boolean activation, @Nullable TraceContext previousContext, long nanoTime) { + private void set(TraceContextImpl traceContext, long threadId, boolean activation, @Nullable TraceContextImpl previousContext, long nanoTime) { traceContext.serialize(traceContextBuffer); this.threadId = threadId; this.activation = activation; @@ -887,7 +887,7 @@ private void startProfiling(SamplingProfiler samplingProfiler) { } } - private TraceContext deserialize(SamplingProfiler samplingProfiler, byte[] traceContextBuffer) { + private TraceContextImpl deserialize(SamplingProfiler samplingProfiler, byte[] traceContextBuffer) { samplingProfiler.contextForLogging.deserialize(traceContextBuffer, null, null); return samplingProfiler.contextForLogging; } diff --git a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/CallTreeSpanifyTest.java b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/CallTreeSpanifyTest.java index 738712e825..6fe80f177d 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/CallTreeSpanifyTest.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/CallTreeSpanifyTest.java @@ -22,9 +22,9 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.impl.transaction.StackFrame; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import co.elastic.apm.agent.objectpool.NoopObjectPool; import co.elastic.apm.agent.testutils.DisabledOnAppleSilicon; import org.junit.jupiter.api.AfterEach; @@ -77,25 +77,25 @@ void testSpanification() throws Exception { assertThat(callTree.spanify()).isEqualTo(4); assertThat(reporter.getSpans()).hasSize(4); assertThat(reporter.getSpans().stream() - .map(Span::getNameAsString) + .map(SpanImpl::getNameAsString) ).containsExactly("CallTreeTest#d", "CallTreeTest#b", "CallTreeTest#a", "CallTreeTest#e"); - Span d = reporter.getSpans().get(0); + SpanImpl d = reporter.getSpans().get(0); assertThat(d.getNameAsString()).isEqualTo("CallTreeTest#d"); assertThat(d.getDuration()).isEqualTo(TimeUnit.MILLISECONDS.toMicros(10)); assertThat(d.getStackFrames().stream().map(StackFrame::getMethodName)).containsExactly("c"); - Span b = reporter.getSpans().get(1); + SpanImpl b = reporter.getSpans().get(1); assertThat(b.getNameAsString()).isEqualTo("CallTreeTest#b"); assertThat(b.getDuration()).isEqualTo(TimeUnit.MILLISECONDS.toMicros(20)); assertThat(b.getStackFrames()).isEmpty(); - Span a = reporter.getSpans().get(2); + SpanImpl a = reporter.getSpans().get(2); assertThat(a.getNameAsString()).isEqualTo("CallTreeTest#a"); assertThat(a.getDuration()).isEqualTo(TimeUnit.MILLISECONDS.toMicros(30)); assertThat(a.getStackFrames()).isEmpty(); - Span e = reporter.getSpans().get(3); + SpanImpl e = reporter.getSpans().get(3); assertThat(e.getNameAsString()).isEqualTo("CallTreeTest#e"); assertThat(e.getDuration()).isEqualTo(TimeUnit.MILLISECONDS.toMicros(10)); assertThat(e.getStackFrames()).isEmpty(); @@ -103,13 +103,13 @@ void testSpanification() throws Exception { @Test void testCallTreeWithActiveSpan() { - TraceContext rootContext = CallTreeTest.rootTraceContext(tracer); + TraceContextImpl rootContext = CallTreeTest.rootTraceContext(tracer); CallTree.Root root = CallTree.createRoot(NoopObjectPool.ofRecyclable(() -> new CallTree.Root(tracer)), rootContext.serialize(), rootContext.getServiceName(), rootContext.getServiceVersion(),0); NoopObjectPool callTreePool = NoopObjectPool.ofRecyclable(CallTree::new); root.addStackTrace(tracer, List.of(StackFrame.of("A", "a")), 0, callTreePool, 0); - TraceContext spanContext = TraceContext.with64BitId(tracer); - TraceContext.fromParentContext().asChildOf(spanContext, rootContext); + TraceContextImpl spanContext = TraceContextImpl.with64BitId(tracer); + TraceContextImpl.fromParentContext().asChildOf(spanContext, rootContext); root.onActivation(spanContext.serialize(), TimeUnit.MILLISECONDS.toNanos(5)); root.addStackTrace(tracer, List.of(StackFrame.of("A", "b"), StackFrame.of("A", "a")), TimeUnit.MILLISECONDS.toNanos(10), callTreePool, 0); @@ -149,10 +149,10 @@ void testCallTreeWithActiveSpan() { @Test void testSpanWithInvertedActivation() { - TraceContext rootContext = CallTreeTest.rootTraceContext(tracer); + TraceContextImpl rootContext = CallTreeTest.rootTraceContext(tracer); - TraceContext childSpanContext = TraceContext.with64BitId(tracer); - TraceContext.fromParentContext().asChildOf(childSpanContext, rootContext); + TraceContextImpl childSpanContext = TraceContextImpl.with64BitId(tracer); + TraceContextImpl.fromParentContext().asChildOf(childSpanContext, rootContext); NoopObjectPool rootPool = NoopObjectPool.ofRecyclable(() -> new CallTree.Root(tracer)); NoopObjectPool childPool = NoopObjectPool.ofRecyclable(CallTree::new); @@ -177,7 +177,7 @@ void testSpanWithInvertedActivation() { @Test void testSpanWithNestedActivation() { - TraceContext rootContext = CallTreeTest.rootTraceContext(tracer); + TraceContextImpl rootContext = CallTreeTest.rootTraceContext(tracer); NoopObjectPool rootPool = NoopObjectPool.ofRecyclable(() -> new CallTree.Root(tracer)); NoopObjectPool childPool = NoopObjectPool.ofRecyclable(CallTree::new); diff --git a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/CallTreeTest.java b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/CallTreeTest.java index ae64d3387a..99040fba40 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/CallTreeTest.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/CallTreeTest.java @@ -21,16 +21,13 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.configuration.SpyConfiguration; +import co.elastic.apm.agent.impl.transaction.*; import co.elastic.apm.agent.tracer.configuration.TimeDuration; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.sampling.ConstantSampler; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.StackFrame; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.objectpool.NoopObjectPool; -import co.elastic.apm.agent.objectpool.ObjectPool; +import co.elastic.apm.agent.objectpool.ObservableObjectPool; import co.elastic.apm.agent.objectpool.impl.ListBasedObjectPool; import co.elastic.apm.agent.testutils.DisabledOnAppleSilicon; import org.junit.jupiter.api.AfterEach; @@ -84,9 +81,9 @@ void tearDown() throws IOException { @Test void testCallTree() { - TraceContext traceContext = TraceContext.with64BitId(MockTracer.create()); + TraceContextImpl traceContext = TraceContextImpl.with64BitId(MockTracer.create()); CallTree.Root root = CallTree.createRoot(NoopObjectPool.ofRecyclable(() -> new CallTree.Root(tracer)), traceContext.serialize(), traceContext.getServiceName(), traceContext.getServiceVersion(), 0); - ObjectPool callTreePool = ListBasedObjectPool.ofRecyclable(new ArrayList<>(), Integer.MAX_VALUE, CallTree::new); + ObservableObjectPool callTreePool = ListBasedObjectPool.ofRecyclable(new ArrayList<>(), Integer.MAX_VALUE, CallTree::new); root.addStackTrace(tracer, List.of(StackFrame.of("A", "a")), 0, callTreePool, 0); root.addStackTrace(tracer, List.of(StackFrame.of("A", "b"), StackFrame.of("A", "a")), TimeUnit.MILLISECONDS.toNanos(10), callTreePool, 0); root.addStackTrace(tracer, List.of(StackFrame.of("A", "b"), StackFrame.of("A", "a")), TimeUnit.MILLISECONDS.toNanos(20), callTreePool, 0); @@ -322,7 +319,7 @@ void testDectivationBeforeEnd2() throws Exception { */ @Test void testDectivationBeforeEnd_DontStealChildIdsOfUnrelatedActivations() throws Exception { - Map> spans = assertCallTree(new String[]{ + Map> spans = assertCallTree(new String[]{ " c c ", " b b ", "a a a aa", @@ -350,7 +347,7 @@ void testDectivationBeforeEnd_DontStealChildIdsOfUnrelatedActivations() throws E */ @Test void testDectivationBeforeEnd_DontStealChildIdsOfUnrelatedActivations_Nested() throws Exception { - Map> spans = assertCallTree(new String[]{ + Map> spans = assertCallTree(new String[]{ " c c ", " b b ", "a a a aa", @@ -487,7 +484,7 @@ void testActivationBetweenMethods_WithCommonAncestor() throws Exception { */ @Test void testNestedActivation() throws Exception { - Map> spans = assertCallTree(new String[]{ + Map> spans = assertCallTree(new String[]{ "a a a", " 12 21 " }, new Object[][] { @@ -507,7 +504,7 @@ void testNestedActivation() throws Exception { */ @Test void testNestedActivationAfterMethodEnds_RootChangesToC() throws Exception { - Map> spans = assertCallTree(new String[]{ + Map> spans = assertCallTree(new String[]{ " bbb ", " aaa ccc ", "1 23 321" @@ -564,7 +561,7 @@ void testRegularActivationFollowedByNestedActivationAfterMethodEnds() throws Exc */ @Test void testNestedActivationAfterMethodEnds_CommonAncestorA() throws Exception { - Map> spans = assertCallTree(new String[]{ + Map> spans = assertCallTree(new String[]{ " b b b ccc ", " aa a a aaa a ", "1 2 2 34 43 1" @@ -855,7 +852,7 @@ private void assertCallTree(String[] stackTraces, Object[][] expectedTree) throw assertCallTree(stackTraces, expectedTree, null); } - private Map> assertCallTree(String[] stackTraces, Object[][] expectedTree, @Nullable Object[][] expectedSpans) throws Exception { + private Map> assertCallTree(String[] stackTraces, Object[][] expectedTree, @Nullable Object[][] expectedSpans) throws Exception { CallTree.Root root = getCallTree(tracer, stackTraces); StringBuilder expectedResult = new StringBuilder(); for (int i = 0; i < expectedTree.length; i++) { @@ -879,7 +876,7 @@ private Map> assertCallTree(String[] stackTraces, Object if (expectedSpans != null) { root.spanify(); - Map> spans = reporter.getSpans() + Map> spans = reporter.getSpans() .stream() .collect(toMap( s -> s.getNameAsString().replaceAll(".*#", ""), @@ -896,7 +893,7 @@ private Map> assertCallTree(String[] stackTraces, Object String parentName = getParentName(expectedSpans, i, nestingLevel); assertThat(spans).containsKey(spanName); assertThat(spans).containsKey(parentName); - AbstractSpan span = spans.get(spanName); + AbstractSpanImpl span = spans.get(spanName); assertThat(span.isChildOf(spans.get(parentName))) .withFailMessage("Expected %s (%s) to be a child of %s (%s) but was %s (%s)", spanName, span.getTraceContext().getId(), @@ -904,7 +901,7 @@ private Map> assertCallTree(String[] stackTraces, Object reporter.getSpans() .stream() .filter(s -> s.getTraceContext().getId().equals(span.getTraceContext().getParentId())).findAny() - .map(Span::getNameAsString) + .map(SpanImpl::getNameAsString) .orElse(null), span.getTraceContext().getParentId()) .isTrue(); @@ -915,14 +912,14 @@ private Map> assertCallTree(String[] stackTraces, Object reporter.getSpans() .stream() .filter(s -> s.getTraceContext().getId().equals(span.getTraceContext().getParentId())).findAny() - .map(Span::getNameAsString) + .map(SpanImpl::getNameAsString) .orElse(null), span.getTraceContext().getParentId()) .isFalse(); assertThat(span.getDuration()) .describedAs("Unexpected duration for span %s", span) .isEqualTo(durationMs * 1000); - assertThat(Objects.requireNonNullElse(((Span) span).getStackFrames(), List.of()) + assertThat(Objects.requireNonNullElse(((SpanImpl) span).getStackFrames(), List.of()) .stream() .map(StackFrame::getMethodName) .collect(Collectors.toList())) @@ -960,12 +957,12 @@ public static CallTree.Root getCallTree(ElasticApmTracer tracer, String[] stackT FixedNanoClock nanoClock = (FixedNanoClock) profilingFactory.getNanoClock(); nanoClock.setNanoTime(0); profiler.setProfilingSessionOngoing(true); - Transaction transaction = tracer + TransactionImpl transaction = tracer .startRootTransaction(ConstantSampler.of(true), 0, null) .withName("Call Tree Root") .activate(); transaction.getTraceContext().getClock().init(0, 0); - Map> spanMap = new HashMap<>(); + Map> spanMap = new HashMap<>(); List stackTraceEvents = new ArrayList<>(); for (int i = 0; i < stackTraces[0].length(); i++) { nanoClock.setNanoTime(i * TimeUnit.MILLISECONDS.toNanos(10)); @@ -1014,17 +1011,17 @@ public StackTraceEvent(List trace, long nanoTime) { } } - private static void handleSpanEvent(ElasticApmTracer tracer, Map> spanMap, String name, long nanoTime) { + private static void handleSpanEvent(ElasticApmTracer tracer, Map> spanMap, String name, long nanoTime) { if (!spanMap.containsKey(name)) { - Span span = tracer.getActive().createSpan(nanoTime / 1000).appendToName(name).activate(); + SpanImpl span = tracer.getActive().createSpan(nanoTime / 1000).appendToName(name).activate(); spanMap.put(name, span); } else { spanMap.get(name).deactivate().end(nanoTime / 1000); } } - public static TraceContext rootTraceContext(ElasticApmTracer tracer) { - TraceContext traceContext = TraceContext.with64BitId(tracer); + public static TraceContextImpl rootTraceContext(ElasticApmTracer tracer) { + TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); traceContext.asRootSpan(ConstantSampler.of(true)); return traceContext; } diff --git a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerQueueTest.java b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerQueueTest.java index d6c0f9d368..1a68e2d2a0 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerQueueTest.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerQueueTest.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.objectpool.ObjectPoolFactory; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.objectpool.ObjectPoolFactoryImpl; import co.elastic.apm.agent.testutils.DisabledOnAppleSilicon; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; @@ -39,12 +39,12 @@ void testFillQueue() throws Exception { System.out.println(System.getProperty("os.name")); ElasticApmTracer tracer = MockTracer.create(); - when(tracer.getObjectPoolFactory()).thenReturn(new ObjectPoolFactory()); + when(tracer.getObjectPoolFactory()).thenReturn(new ObjectPoolFactoryImpl()); SamplingProfiler profiler = new SamplingProfiler(tracer, new SystemNanoClock()); profiler.setProfilingSessionOngoing(true); - TraceContext traceContext = TraceContext.with64BitId(tracer); + TraceContextImpl traceContext = TraceContextImpl.with64BitId(tracer); assertThat(profiler.onActivation(traceContext, null)).isTrue(); long timeAfterFirstEvent = System.nanoTime(); diff --git a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerReplay.java b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerReplay.java index e213f316cc..703c9f24e7 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerReplay.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerReplay.java @@ -20,6 +20,7 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -33,7 +34,7 @@ /** * Can be used in combination with the files created by * {@link ProfilingConfiguration#backupDiagnosticFiles} to replay the creation of profiler-inferred spans. - * This is useful, for example, to troubleshoot why {@link co.elastic.apm.agent.impl.transaction.Span#childIds} are set as expected. + * This is useful, for example, to troubleshoot why {@link SpanImpl#childIds} are set as expected. */ public class SamplingProfilerReplay { diff --git a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerTest.java b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerTest.java index 6e5816777e..de7e720185 100644 --- a/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerTest.java +++ b/apm-agent-plugins/apm-profiling-plugin/src/test/java/co/elastic/apm/agent/profiler/SamplingProfilerTest.java @@ -23,8 +23,8 @@ import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.configuration.SpyConfiguration; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.testutils.DisabledOnAppleSilicon; import co.elastic.apm.agent.tracer.Scope; import co.elastic.apm.agent.tracer.configuration.TimeDuration; @@ -163,7 +163,7 @@ void testProfileTransaction() throws Exception { setupProfiler(true); awaitProfilerStarted(profiler); - Transaction transaction = tracer.startRootTransaction(null).withName("transaction"); + TransactionImpl transaction = tracer.startRootTransaction(null).withName("transaction"); try (Scope scope = transaction.activateInScope()) { // makes sure that the rest will be captured by another profiling session // this tests that restoring which threads to profile works @@ -179,23 +179,23 @@ void testProfileTransaction() throws Exception { .timeout(5000, TimeUnit.MILLISECONDS) .untilAsserted(() -> assertThat(reporter.getSpans()).hasSize(5)); - Optional testProfileTransaction = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("SamplingProfilerTest#testProfileTransaction")).findAny(); + Optional testProfileTransaction = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("SamplingProfilerTest#testProfileTransaction")).findAny(); assertThat(testProfileTransaction).isPresent(); assertThat(testProfileTransaction.get().isChildOf(transaction)).isTrue(); - Optional inferredSpanA = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("SamplingProfilerTest#aInferred")).findAny(); + Optional inferredSpanA = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("SamplingProfilerTest#aInferred")).findAny(); assertThat(inferredSpanA).isPresent(); assertThat(inferredSpanA.get().isChildOf(testProfileTransaction.get())).isTrue(); - Optional explicitSpanB = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("bExplicit")).findAny(); + Optional explicitSpanB = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("bExplicit")).findAny(); assertThat(explicitSpanB).isPresent(); assertThat(explicitSpanB.get().isChildOf(inferredSpanA.get())).isTrue(); - Optional inferredSpanC = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("SamplingProfilerTest#cInferred")).findAny(); + Optional inferredSpanC = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("SamplingProfilerTest#cInferred")).findAny(); assertThat(inferredSpanC).isPresent(); assertThat(inferredSpanC.get().isChildOf(explicitSpanB.get())).isTrue(); - Optional inferredSpanD = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("SamplingProfilerTest#dInferred")).findAny(); + Optional inferredSpanD = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("SamplingProfilerTest#dInferred")).findAny(); assertThat(inferredSpanD).isPresent(); assertThat(inferredSpanD.get().isChildOf(inferredSpanC.get())).isTrue(); } @@ -208,7 +208,7 @@ void testVirtualThreadsExcluded() throws Exception { AtomicReference profilingActive = new AtomicReference<>(); Runnable task = () -> { - Transaction transaction = tracer.startRootTransaction(null).withName("transaction"); + TransactionImpl transaction = tracer.startRootTransaction(null).withName("transaction"); try (Scope scope = transaction.activateInScope()) { // makes sure that the rest will be captured by another profiling session // this tests that restoring which threads to profile works @@ -238,7 +238,7 @@ void testPostProcessingDisabled() throws Exception { doReturn(false).when(profilingConfig).isPostProcessingEnabled(); awaitProfilerStarted(profiler); - Transaction transaction = tracer.startRootTransaction(null).withName("transaction"); + TransactionImpl transaction = tracer.startRootTransaction(null).withName("transaction"); try (Scope scope = transaction.activateInScope()) { // makes sure that the rest will be captured by another profiling session // this tests that restoring which threads to profile works @@ -253,13 +253,13 @@ void testPostProcessingDisabled() throws Exception { .timeout(5000, TimeUnit.MILLISECONDS) .untilAsserted(() -> assertThat(reporter.getSpans()).hasSize(1)); - Optional explicitSpanB = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("bExplicit")).findAny(); + Optional explicitSpanB = reporter.getSpans().stream().filter(s -> s.getNameAsString().equals("bExplicit")).findAny(); assertThat(explicitSpanB).isPresent(); assertThat(explicitSpanB.get().isChildOf(transaction)).isTrue(); } - private void aInferred(Transaction transaction) throws Exception { - Span span = transaction.createSpan().withName("bExplicit").withType("custom"); + private void aInferred(TransactionImpl transaction) throws Exception { + SpanImpl span = transaction.createSpan().withName("bExplicit").withType("custom"); try (Scope spanScope = span.activateInScope()) { cInferred(); } finally { diff --git a/apm-agent-plugins/apm-quartz/apm-quartz-common/pom.xml b/apm-agent-plugins/apm-quartz/apm-quartz-common/pom.xml index 614504136b..38c1c1f67c 100644 --- a/apm-agent-plugins/apm-quartz/apm-quartz-common/pom.xml +++ b/apm-agent-plugins/apm-quartz/apm-quartz-common/pom.xml @@ -3,7 +3,7 @@ apm-quartz co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-quartz/apm-quartz-common/src/test/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentationTest.java b/apm-agent-plugins/apm-quartz/apm-quartz-common/src/test/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentationTest.java index bccc2f42a2..a5a5a417b0 100644 --- a/apm-agent-plugins/apm-quartz/apm-quartz-common/src/test/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-quartz/apm-quartz-common/src/test/java/co/elastic/apm/agent/quartzjob/AbstractJobTransactionNameInstrumentationTest.java @@ -21,8 +21,8 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.impl.TracerInternalApiUtils; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -73,12 +73,12 @@ void testJobManualCall() throws SchedulerException, InterruptedException { executeTestJobCreatingSpan(tracer, true); reporter.awaitTransactionCount(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); verifyTransaction(transaction, "TestJobCreatingSpan#execute"); assertThat(reporter.getNumReportedSpans()).isEqualTo(1); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span.getTraceContext().getParentId()).isEqualTo(transaction.getTraceContext().getId()); } @@ -103,7 +103,7 @@ void testJobWithResult() throws SchedulerException { JobDetail job = buildJobDetailTestJobWithResult("dummyJobName"); scheduler.scheduleJob(job, createTrigger()); - Transaction transaction = verifyTransactionFromJobDetails(job, Outcome.SUCCESS); + TransactionImpl transaction = verifyTransactionFromJobDetails(job, Outcome.SUCCESS); assertThat(transaction.getResult()).isEqualTo("this is the result"); } @@ -115,9 +115,9 @@ void testJobWithException() throws SchedulerException { verifyTransactionFromJobDetails(job, Outcome.FAILURE); } - abstract Transaction verifyTransactionFromJobDetails(JobDetail job, Outcome expectedOutcome); + abstract TransactionImpl verifyTransactionFromJobDetails(JobDetail job, Outcome expectedOutcome); - public Transaction verifyTransaction(Transaction transaction, String expectedName) { + public TransactionImpl verifyTransaction(TransactionImpl transaction, String expectedName) { assertThat(transaction.getType()).isEqualToIgnoringCase("scheduled"); assertThat(transaction.getNameAsString()) .isEqualTo(expectedName); diff --git a/apm-agent-plugins/apm-quartz/apm-quartz-plugin-1/pom.xml b/apm-agent-plugins/apm-quartz/apm-quartz-plugin-1/pom.xml index d37b1de83c..4f1c20260c 100644 --- a/apm-agent-plugins/apm-quartz/apm-quartz-plugin-1/pom.xml +++ b/apm-agent-plugins/apm-quartz/apm-quartz-plugin-1/pom.xml @@ -3,7 +3,7 @@ apm-quartz co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-quartz/apm-quartz-plugin-1/src/test/java/co/elastic/apm/agent/quartzjob/Quartz1JobTransactionNameInstrumentationTest.java b/apm-agent-plugins/apm-quartz/apm-quartz-plugin-1/src/test/java/co/elastic/apm/agent/quartzjob/Quartz1JobTransactionNameInstrumentationTest.java index 365104d42b..76019569b5 100644 --- a/apm-agent-plugins/apm-quartz/apm-quartz-plugin-1/src/test/java/co/elastic/apm/agent/quartzjob/Quartz1JobTransactionNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-quartz/apm-quartz-plugin-1/src/test/java/co/elastic/apm/agent/quartzjob/Quartz1JobTransactionNameInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.quartzjob; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import org.quartz.Job; import org.quartz.JobDetail; @@ -35,10 +35,10 @@ class Quartz1JobTransactionNameInstrumentationTest extends AbstractJobTransactionNameInstrumentationTest { @Override - public Transaction verifyTransactionFromJobDetails(JobDetail job, Outcome expectedOutcome) { + public TransactionImpl verifyTransactionFromJobDetails(JobDetail job, Outcome expectedOutcome) { reporter.awaitTransactionCount(1, 2000); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); await().untilAsserted(() -> assertThat(reporter.getTransactions().size()).isEqualTo(1)); verifyTransaction(transaction, String.format("%s.%s", job.getKey().getGroup(), job.getKey().getName())); @@ -111,7 +111,7 @@ public TestJobCreatingSpan(ElasticApmTracer tracer, boolean traced) { @Override public void execute(JobExecutionContext context) throws JobExecutionException { - Transaction transaction = tracer.currentTransaction(); + TransactionImpl transaction = tracer.currentTransaction(); if (traced) { assertThat(transaction).isNotNull(); transaction.createSpan().end(); diff --git a/apm-agent-plugins/apm-quartz/apm-quartz-plugin-2/pom.xml b/apm-agent-plugins/apm-quartz/apm-quartz-plugin-2/pom.xml index 78304557cd..c9e49dcbfc 100644 --- a/apm-agent-plugins/apm-quartz/apm-quartz-plugin-2/pom.xml +++ b/apm-agent-plugins/apm-quartz/apm-quartz-plugin-2/pom.xml @@ -3,7 +3,7 @@ apm-quartz co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-quartz/apm-quartz-plugin-2/src/test/java/co/elastic/apm/agent/quartzjob/Quartz2JobTransactionNameInstrumentationTest.java b/apm-agent-plugins/apm-quartz/apm-quartz-plugin-2/src/test/java/co/elastic/apm/agent/quartzjob/Quartz2JobTransactionNameInstrumentationTest.java index 2ec969cd59..5352cad882 100644 --- a/apm-agent-plugins/apm-quartz/apm-quartz-plugin-2/src/test/java/co/elastic/apm/agent/quartzjob/Quartz2JobTransactionNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-quartz/apm-quartz-plugin-2/src/test/java/co/elastic/apm/agent/quartzjob/Quartz2JobTransactionNameInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.quartzjob; import co.elastic.apm.agent.impl.ElasticApmTracer; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import org.junit.jupiter.api.Test; import org.quartz.Job; @@ -47,10 +47,10 @@ class Quartz2JobTransactionNameInstrumentationTest extends AbstractJobTransactionNameInstrumentationTest { @Override - public Transaction verifyTransactionFromJobDetails(JobDetail job, Outcome expectedOutcome) { + public TransactionImpl verifyTransactionFromJobDetails(JobDetail job, Outcome expectedOutcome) { reporter.awaitTransactionCount(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); await().untilAsserted(() -> assertThat(reporter.getTransactions().size()).isEqualTo(1)); verifyTransaction(transaction, String.format("%s.%s", job.getKey().getGroup(), job.getKey().getName())); @@ -128,7 +128,7 @@ public TestJobCreatingSpan(ElasticApmTracer tracer, boolean traced) { @Override public void execute(JobExecutionContext context) throws JobExecutionException { - Transaction transaction = tracer.currentTransaction(); + TransactionImpl transaction = tracer.currentTransaction(); if (traced) { assertThat(transaction).isNotNull(); transaction.createSpan().end(); diff --git a/apm-agent-plugins/apm-quartz/pom.xml b/apm-agent-plugins/apm-quartz/pom.xml index 3fe365c206..d1abbaa31f 100644 --- a/apm-agent-plugins/apm-quartz/pom.xml +++ b/apm-agent-plugins/apm-quartz/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-quartz diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/pom.xml b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/pom.xml index 26576db371..f8065e3f8b 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/pom.xml +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/pom.xml @@ -5,7 +5,7 @@ apm-rabbitmq co.elastic.apm - 1.50.0 + 1.51.0 apm-rabbitmq-plugin diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ChannelInstrumentation.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ChannelInstrumentation.java index 5fa4812ac1..81e3d6d531 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ChannelInstrumentation.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ChannelInstrumentation.java @@ -22,8 +22,9 @@ import co.elastic.apm.agent.rabbitmq.header.RabbitMQTextHeaderSetter; import co.elastic.apm.agent.sdk.DynamicTransformer; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Span; +import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; import com.rabbitmq.client.AMQP; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; @@ -137,10 +138,9 @@ public static Object[] onBasicPublish(@Advice.This Channel channel, if (exitSpan != null) { exchange = normalizeExchangeName(exchange); - + String transactionNameSuffix = normalizeExchangeName(resolveTransactionNameSuffix(exchange, routingKey)); exitSpan.withAction("send") - .withName("RabbitMQ SEND to ").appendToName(exchange); - + .withName("RabbitMQ SEND to ").appendToName(transactionNameSuffix); } properties = propagateTraceContext(tracer.currentContext(), properties); @@ -155,7 +155,7 @@ public static Object[] onBasicPublish(@Advice.This Channel channel, return new Object[]{properties, exitSpan}; } - private static AMQP.BasicProperties propagateTraceContext(ElasticContext toPropagate, + private static AMQP.BasicProperties propagateTraceContext(TraceState toPropagate, @Nullable AMQP.BasicProperties originalBasicProperties) { AMQP.BasicProperties properties = originalBasicProperties; if (properties == null) { @@ -174,6 +174,15 @@ private static AMQP.BasicProperties propagateTraceContext(ElasticContext toPr return properties.builder().headers(headersWithContext).build(); } + private static String resolveTransactionNameSuffix(String exchange, String routingKey) { + + if (MessagingConfiguration.RabbitMQNamingMode.ROUTING_KEY == AbstractBaseInstrumentation.getRabbitMQNamingMode()) { + return routingKey; + } else { + return exchange; + } + } + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false) public static void afterBasicPublish(@Advice.Enter @Nullable Object[] enterArray, @Advice.Thrown @Nullable Throwable throwable) { diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ConsumerInstrumentation.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ConsumerInstrumentation.java index 2ac2847c0c..5659022575 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ConsumerInstrumentation.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/main/java/co/elastic/apm/agent/rabbitmq/ConsumerInstrumentation.java @@ -20,6 +20,7 @@ import co.elastic.apm.agent.tracer.Transaction; import co.elastic.apm.agent.rabbitmq.header.RabbitMQTextHeaderGetter; +import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration.RabbitMQNamingMode; import co.elastic.apm.agent.tracer.metadata.Message; import co.elastic.apm.agent.sdk.internal.util.PrivilegedActionUtils; import com.rabbitmq.client.AMQP; @@ -106,8 +107,9 @@ public static Object onHandleDelivery(@Advice.Origin Class originClazz, return null; } + String transactionNameSuffix = getExchangeOrRoutingKey(envelope); transaction.withType("messaging") - .withName("RabbitMQ RECEIVE from ").appendToName(normalizeExchangeName(exchange)); + .withName("RabbitMQ RECEIVE from ").appendToName(normalizeExchangeName(transactionNameSuffix)); transaction.setFrameworkName("RabbitMQ"); @@ -129,5 +131,17 @@ public static void afterHandleDelivery(@Advice.Enter @Nullable final Object tran .end(); } } + + private static String getExchangeOrRoutingKey(Envelope envelope) { + if (null == envelope) { + return null; + } + + if (RabbitMQNamingMode.ROUTING_KEY == AbstractBaseInstrumentation.getRabbitMQNamingMode()) { + return envelope.getRoutingKey(); + } else { + return envelope.getExchange(); + } + } } } diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/test/java/co/elastic/apm/agent/rabbitmq/RabbitMQIT.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/test/java/co/elastic/apm/agent/rabbitmq/RabbitMQIT.java index b43f719046..05c2b52464 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/test/java/co/elastic/apm/agent/rabbitmq/RabbitMQIT.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-plugin/src/test/java/co/elastic/apm/agent/rabbitmq/RabbitMQIT.java @@ -43,19 +43,17 @@ */ import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.*; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; -import co.elastic.apm.agent.impl.context.Destination; +import co.elastic.apm.agent.impl.context.DestinationImpl; import co.elastic.apm.agent.impl.context.Headers; -import co.elastic.apm.agent.impl.context.Message; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Id; +import co.elastic.apm.agent.impl.context.MessageImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.testutils.TestContainersUtils; +import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration.RabbitMQNamingMode; import com.rabbitmq.client.AMQP; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; @@ -98,7 +96,7 @@ public class RabbitMQIT extends AbstractInstrumentationTest { private static final String IMAGE = "rabbitmq:3.7-management-alpine"; private static final RabbitMQContainer container = new RabbitMQContainer(IMAGE); - private static final String ROUTING_KEY = "test.key"; + private static final String TEST_ROUTING_KEY = "test.key"; private static final byte[] MSG = "Testing APM!".getBytes(); @@ -155,8 +153,8 @@ void contextPropagationWithProperties() throws IOException, InterruptedException void bodyCaptureNotSupported() throws IOException, InterruptedException { // body capture is not supported because at the RabbitMQ driver level // the message is provided as a byte array. - CoreConfiguration config = AbstractInstrumentationTest.config.getConfig(CoreConfiguration.class); - doReturn(CoreConfiguration.EventType.ALL).when(config).getCaptureBody(); + CoreConfigurationImpl config = AbstractInstrumentationTest.config.getConfig(CoreConfigurationImpl.class); + doReturn(CoreConfigurationImpl.EventType.ALL).when(config).getCaptureBody(); performTest( emptyProperties(), @@ -183,7 +181,7 @@ void headersCaptureEnabledByDefault() throws IOException, InterruptedException { @Test void headersCaptureDisabled() throws IOException, InterruptedException { - CoreConfiguration coreConfiguration = config.getConfig(CoreConfiguration.class); + CoreConfigurationImpl coreConfiguration = config.getConfig(CoreConfigurationImpl.class); doReturn(false).when(coreConfiguration).isCaptureHeaders(); testHeadersCapture(Map.of("message-header", "header value"), Map.of(), false); @@ -191,7 +189,7 @@ void headersCaptureDisabled() throws IOException, InterruptedException { @Test void headersCaptureSanitize() throws IOException, InterruptedException { - CoreConfiguration coreConfiguration = config.getConfig(CoreConfiguration.class); + CoreConfigurationImpl coreConfiguration = config.getConfig(CoreConfigurationImpl.class); doReturn(List.of(WildcardMatcher.valueOf("secret*"))).when(coreConfiguration).getSanitizeFieldNames(); testHeadersCapture( @@ -203,7 +201,8 @@ void headersCaptureSanitize() throws IOException, InterruptedException { ), true); } - private void testHeadersCapture(Map headersMap, Map expectedHeaders, boolean expectTracingHeaders) throws IOException, InterruptedException { + private void testHeadersCapture(Map headersMap, Map expectedHeaders, + boolean expectTracingHeaders) throws IOException, InterruptedException { performTest( propertiesMap(headersMap), false, @@ -228,6 +227,15 @@ void ignoreExchangeName() throws IOException, InterruptedException { }); } + @Test + void routingKeyInTransactionName() throws IOException, InterruptedException { + MessagingConfiguration messagingConfiguration = config.getConfig(MessagingConfiguration.class); + doReturn(RabbitMQNamingMode.ROUTING_KEY).when(messagingConfiguration).getRabbitMQNamingMode(); + + performTest(emptyProperties(), false, randString("exchange"), "different-routing-key", + (mt, ms) -> {}); + } + private void performTest(@Nullable AMQP.BasicProperties properties) throws IOException, InterruptedException { performTest(properties, false, randString("exchange"), (mt, ms) -> { }); @@ -236,11 +244,20 @@ private void performTest(@Nullable AMQP.BasicProperties properties) throws IOExc private void performTest(@Nullable AMQP.BasicProperties properties, boolean shouldIgnore, String channelName, - BiConsumer messageCheck) throws IOException, InterruptedException { + BiConsumer messageCheck) throws IOException, InterruptedException { + + performTest(properties, shouldIgnore, channelName, TEST_ROUTING_KEY, messageCheck); + } + + private void performTest(@Nullable AMQP.BasicProperties properties, + boolean shouldIgnore, + String channelName, + String routingKey, + BiConsumer messageCheck) throws IOException, InterruptedException { Channel channel = connection.createChannel(); String exchange = createExchange(channel, channelName); - String queue = createQueue(channel, exchange); + String queue = createQueue(channel, exchange, routingKey); CountDownLatch messageReceived = new CountDownLatch(1); @@ -248,7 +265,8 @@ private void performTest(@Nullable AMQP.BasicProperties properties, // using an anonymous class to ensure class matching is properly applied @Override - public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { + public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, + byte[] body) throws IOException { assertThat(properties).isNotNull(); Map headers = properties.getHeaders(); @@ -262,9 +280,9 @@ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProp } }); - Transaction rootTransaction = startTestRootTransaction("Rabbit-Test Root Transaction"); + TransactionImpl rootTransaction = startTestRootTransaction("Rabbit-Test Root Transaction"); - channel.basicPublish(exchange, ROUTING_KEY, properties, MSG); + channel.basicPublish(exchange, routingKey, properties, MSG); endRootTransaction(rootTransaction); @@ -285,17 +303,17 @@ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProp return; } - // 2 transactions, 1 span expected getReporter().awaitTransactionCount(2); getReporter().awaitSpanCount(1); - Transaction childTransaction = getNonRootTransaction(rootTransaction, getReporter().getTransactions()); + TransactionImpl childTransaction = getNonRootTransaction(rootTransaction, getReporter().getTransactions()); - checkTransaction(childTransaction, exchange); + String transactionNameSuffix = !routingKey.equals(TEST_ROUTING_KEY) ? routingKey: exchange; + checkTransaction(childTransaction, exchange, transactionNameSuffix, "RabbitMQ"); - Span span = getReporter().getSpans().get(0); - checkSendSpan(span, exchange); + SpanImpl span = getReporter().getSpans().get(0); + checkSendSpan(span, exchange, transactionNameSuffix); // span should be child of the first transaction checkParentChild(rootTransaction, span); @@ -303,13 +321,11 @@ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProp checkParentChild(span, childTransaction); // common assertions on span & transaction message - Message spanMessage = span.getContext().getMessage(); - Message transactionMessage = childTransaction.getContext().getMessage(); - + MessageImpl spanMessage = span.getContext().getMessage(); + MessageImpl transactionMessage = childTransaction.getContext().getMessage(); // test-specific assertions on captured message messageCheck.accept(transactionMessage, spanMessage); - } @Test @@ -324,12 +340,12 @@ void testPollingWithinTransactionNoMessage() throws IOException { reporter.awaitTransactionCount(1); reporter.awaitSpanCount(1); - Span pollingSpan = findSpanByAction("poll"); + SpanImpl pollingSpan = findSpanByAction("poll"); checkPollSpan(pollingSpan, null, queueName, "", false); } @NotNull - private Span findSpanByAction(String action) { + private SpanImpl findSpanByAction(String action) { return reporter.getSpans().stream().filter(span -> Objects.requireNonNull(span.getAction()).equals(action)).findFirst().get(); } @@ -345,10 +361,10 @@ void testPollingWithinTransactionGetMessage() throws IOException { reporter.awaitTransactionCount(1); reporter.awaitSpanCount(2); - Span sendSpan = findSpanByAction("send"); + SpanImpl sendSpan = findSpanByAction("send"); checkSendSpan(sendSpan, exchange); - Span pollingSpan = findSpanByAction("poll"); + SpanImpl pollingSpan = findSpanByAction("poll"); checkPollSpan(pollingSpan, sendSpan, queueName, exchange, true); } @@ -395,7 +411,7 @@ void testPollingIgnoreExchangeName() throws IOException { private String declareAndBindQueue(String queue, String exchange, Channel channel) { try { channel.queueDeclare(queue, false, false, false, null); - channel.queueBind(queue, exchange, ROUTING_KEY); + channel.queueBind(queue, exchange, TEST_ROUTING_KEY); return queue; } catch (IOException e) { throw new IllegalStateException(e); @@ -407,13 +423,13 @@ private void pollingTest(boolean withinTransaction, boolean withResult, Supplier String queue = createQueue.get(); - Transaction rootTransaction = null; + TransactionImpl rootTransaction = null; if (withinTransaction) { rootTransaction = startTestRootTransaction("Rabbit-Test Root Transaction"); } if (withResult) { - channel.basicPublish(exchange, ROUTING_KEY, emptyProperties(), MSG); + channel.basicPublish(exchange, TEST_ROUTING_KEY, emptyProperties(), MSG); } channel.basicGet(queue, true); @@ -467,7 +483,7 @@ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProp .build(); - Transaction rootTransaction = startTestRootTransaction("Rabbit-Test Root Transaction"); + TransactionImpl rootTransaction = startTestRootTransaction("Rabbit-Test Root Transaction"); channel.basicPublish(exchange, rpcQueueName, properties, MSG); @@ -509,10 +525,10 @@ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProp // parent/child relationships are used to find who is who as we don't have other fields like name // to distinguish them - Span clientRequestRpc = null; - Span serverReplyRpc = null; - for (Span s : getReporter().getSpans()) { - Id spanParentId = s.getTraceContext().getParentId(); + SpanImpl clientRequestRpc = null; + SpanImpl serverReplyRpc = null; + for (SpanImpl s : getReporter().getSpans()) { + IdImpl spanParentId = s.getTraceContext().getParentId(); if (rootTransaction.getTraceContext().getId().equals(spanParentId)) { // client request is child of root transaction assertThat(clientRequestRpc).isNull(); @@ -525,11 +541,11 @@ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProp assertThat(clientRequestRpc).isNotNull(); assertThat(serverReplyRpc).isNotNull(); - Transaction serverSideRpc = null; - Transaction clientSideRpc = null; - for (Transaction t : getReporter().getTransactions()) { + TransactionImpl serverSideRpc = null; + TransactionImpl clientSideRpc = null; + for (TransactionImpl t : getReporter().getTransactions()) { if (t != rootTransaction) { - Id transactionParentId = t.getTraceContext().getParentId(); + IdImpl transactionParentId = t.getTraceContext().getParentId(); if (clientRequestRpc.getTraceContext().getId().equals(transactionParentId)) { assertThat(serverSideRpc).isNull(); serverSideRpc = t; @@ -557,13 +573,13 @@ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProp } - private void endRootTransaction(Transaction rootTransaction) { + private void endRootTransaction(TransactionImpl rootTransaction) { rootTransaction.deactivate().end(); } - static Transaction getNonRootTransaction(Transaction rootTransaction, List transactions) { - Transaction childTransaction = null; - for (Transaction t : transactions) { + static TransactionImpl getNonRootTransaction(TransactionImpl rootTransaction, List transactions) { + TransactionImpl childTransaction = null; + for (TransactionImpl t : transactions) { if (t != rootTransaction) { assertThat(childTransaction).isNull(); childTransaction = t; @@ -573,9 +589,9 @@ static Transaction getNonRootTransaction(Transaction rootTransaction, List()).build(); } - static void checkParentChild(AbstractSpan parent, AbstractSpan child) { + static void checkParentChild(AbstractSpanImpl parent, AbstractSpanImpl child) { assertThat(child.getTraceContext().getParentId()) .describedAs("child (%s) should be a child of (%s)", child, parent) .isEqualTo(parent.getTraceContext().getId()); @@ -613,14 +629,18 @@ static void checkParentChild(AbstractSpan parent, AbstractSpan child) { .isEqualTo(parent.getTraceContext().getTraceId()); } - private static void checkTransaction(Transaction transaction, String exchange) { + private static void checkTransaction(TransactionImpl transaction, String exchange) { checkTransaction(transaction, exchange, "RabbitMQ"); } - static void checkTransaction(Transaction transaction, String exchange, String frameworkName) { + static void checkTransaction(TransactionImpl transaction, String exchange, String frameworkName) { + checkTransaction(transaction, exchange, exchange, frameworkName); + } + + static void checkTransaction(TransactionImpl transaction, String exchange, String transactionNameSuffix, String frameworkName) { assertThat(transaction.getType()).isEqualTo("messaging"); assertThat(transaction.getNameAsString()) - .isEqualTo("RabbitMQ RECEIVE from %s", exchange.isEmpty() ? "" : exchange); + .isEqualTo("RabbitMQ RECEIVE from %s", transactionNameSuffix.isEmpty() ? "" : transactionNameSuffix); assertThat(transaction.getFrameworkName()).isEqualTo(frameworkName); assertThat(transaction.getOutcome()).isEqualTo(Outcome.SUCCESS); @@ -628,7 +648,7 @@ static void checkTransaction(Transaction transaction, String exchange, String fr checkMessage(transaction.getContext().getMessage(), exchange, true); } - private static void checkMessage(Message message, String queueName, boolean withRoutingKeyCheck) { + private static void checkMessage(MessageImpl message, String queueName, boolean withRoutingKeyCheck) { assertThat(message.getQueueName()).isEqualTo(queueName); // RabbitMQ does not provide timestamp by default @@ -641,7 +661,7 @@ private static void checkMessage(Message message, String queueName, boolean with } - private static void checkMessageBodyNotCaptured(Message message) { + private static void checkMessageBodyNotCaptured(MessageImpl message) { assertThat(message.getBodyForRead()).describedAs("body capture isn't supported").isNull(); } @@ -651,7 +671,7 @@ private static void checkMessageBodyNotCaptured(Message message) { "traceparent" }; - private static void checkDistributedTracingHeaders(Message message, boolean expectTracingHeaders) { + private static void checkDistributedTracingHeaders(MessageImpl message, boolean expectTracingHeaders) { HashMap headersMap = getHeadersMap(message); if (expectTracingHeaders) { assertThat(headersMap) @@ -664,7 +684,7 @@ private static void checkDistributedTracingHeaders(Message message, boolean expe } } - private static void checkHeaders(Message message, Map expectedHeaders) { + private static void checkHeaders(MessageImpl message, Map expectedHeaders) { HashMap headersMap = getHeadersMap(message); for (String key : DISTRIBUTED_TRACING_HEADERS) { headersMap.remove(key); @@ -674,22 +694,31 @@ private static void checkHeaders(Message message, Map expectedHe .containsAllEntriesOf(expectedHeaders); } - private static HashMap getHeadersMap(Message message) { + private static HashMap getHeadersMap(MessageImpl message) { Headers headers = message.getHeaders(); HashMap headersMap = new HashMap<>(); headers.forEach(h -> headersMap.put(h.getKey(), h.getValue().toString())); return headersMap; } - private static void checkSendSpan(Span span, String exchange) { - checkSendSpan(span, exchange, connection.getAddress().getHostAddress(), connection.getPort()); + private static void checkSendSpan(SpanImpl span, String exchange) { + checkSendSpan(span, exchange, exchange, connection.getAddress().getHostAddress(), connection.getPort()); + } + + private static void checkSendSpan(SpanImpl span, String exchange, String spanNameSuffix) { + checkSendSpan(span, exchange, spanNameSuffix, connection.getAddress().getHostAddress(), connection.getPort()); + } + + static void checkSendSpan(SpanImpl span, String exchange, String host, int port) { + checkSendSpan(span, exchange, exchange, host, port); } - static void checkSendSpan(Span span, String exchange, String host, int port) { + static void checkSendSpan(SpanImpl span, String exchange, String spanNameSuffix, String host, int port) { String exchangeName = exchange.isEmpty() ? "" : exchange; + String spanName = spanNameSuffix.isEmpty() ? "" : spanNameSuffix; checkSpanCommon(span, "send", - String.format("RabbitMQ SEND to %s", exchangeName), + String.format("RabbitMQ SEND to %s", spanName), exchangeName, true ); @@ -697,7 +726,7 @@ static void checkSendSpan(Span span, String exchange, String host, int port) { checkSpanDestination(span, host, port, String.format("rabbitmq/%s", exchangeName)); } - private static void checkPollSpan(Span pollSpan, @Nullable Span sendSpan, String queue, String normalizedExchange, boolean withRoutingKeyCheck) { + private static void checkPollSpan(SpanImpl pollSpan, @Nullable SpanImpl sendSpan, String queue, String normalizedExchange, boolean withRoutingKeyCheck) { checkSpanCommon(pollSpan, "poll", String.format("RabbitMQ POLL from %s", queue), @@ -710,7 +739,7 @@ private static void checkPollSpan(Span pollSpan, @Nullable Span sendSpan, String String.format("rabbitmq/%s", normalizedExchange) ); - List spanLinks = pollSpan.getSpanLinks(); + List spanLinks = pollSpan.getSpanLinks(); if (sendSpan != null) { assertThat(spanLinks).hasSize(1); assertThat(spanLinks.get(0).getTraceId()).isEqualTo(sendSpan.getTraceContext().getTraceId()); @@ -720,7 +749,7 @@ private static void checkPollSpan(Span pollSpan, @Nullable Span sendSpan, String } } - private static void checkSpanCommon(Span span, String expectedAction, String expectedName, String expectedQueueName, boolean withRoutingKeyCheck) { + private static void checkSpanCommon(SpanImpl span, String expectedAction, String expectedName, String expectedQueueName, boolean withRoutingKeyCheck) { assertThat(span.getType()).isEqualTo("messaging"); assertThat(span.getSubtype()).isEqualTo("rabbitmq"); assertThat(span.getAction()).isEqualTo(expectedAction); @@ -733,8 +762,8 @@ private static void checkSpanCommon(Span span, String expectedAction, String exp assertThat(span.getOutcome()).isEqualTo(Outcome.SUCCESS); } - static void checkSpanDestination(Span span, String expectedHostAddress, int expectedPort, String expectedResource) { - Destination destination = span.getContext().getDestination(); + static void checkSpanDestination(SpanImpl span, String expectedHostAddress, int expectedPort, String expectedResource) { + DestinationImpl destination = span.getContext().getDestination(); assertThat(destination.getAddress().toString()).isEqualTo(expectedHostAddress); assertThat(destination.getPort()).isEqualTo(expectedPort); diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/pom.xml b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/pom.xml index edd6fc6883..11278f1746 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/pom.xml +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/pom.xml @@ -5,7 +5,7 @@ apm-rabbitmq co.elastic.apm - 1.50.0 + 1.51.0 apm-rabbitmq-spring diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/AbstractRabbitMqTest.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/AbstractRabbitMqTest.java index fef5420765..6cafbc1ecb 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/AbstractRabbitMqTest.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/AbstractRabbitMqTest.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; import org.junit.Test; @@ -31,7 +31,6 @@ import static co.elastic.apm.agent.rabbitmq.RabbitMQIT.getNonRootTransaction; import static co.elastic.apm.agent.rabbitmq.TestConstants.QUEUE_NAME; import static co.elastic.apm.agent.rabbitmq.TestConstants.TOPIC_EXCHANGE_NAME; -import static co.elastic.apm.agent.tracer.configuration.MessagingConfiguration.JmsStrategy.POLLING; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.Mockito.doReturn; @@ -42,9 +41,9 @@ public abstract class AbstractRabbitMqTest extends RabbitMqTestBase { @Test public void verifyThatTransactionWithSpanCreated() { rabbitTemplate.convertAndSend(TOPIC_EXCHANGE_NAME, TestConstants.ROUTING_KEY, MESSAGE); - Transaction receiveTransaction = reporter.getFirstTransaction(1000); + TransactionImpl receiveTransaction = reporter.getFirstTransaction(1000); checkTransaction(receiveTransaction, TOPIC_EXCHANGE_NAME, "Spring AMQP"); - Span testSpan = reporter.getFirstSpan(1000); + SpanImpl testSpan = reporter.getFirstSpan(1000); assertThat(testSpan.getNameAsString()).isEqualTo("testSpan"); assertThat(testSpan.getType()).isEqualTo("custom"); checkParentChild(receiveTransaction, testSpan); @@ -56,9 +55,9 @@ public void verifyThatTransactionWithSpanCreated_NamingModeQueue() { doReturn(MessagingConfiguration.RabbitMQNamingMode.QUEUE).when(messagingConfiguration).getRabbitMQNamingMode(); rabbitTemplate.convertAndSend(TOPIC_EXCHANGE_NAME, TestConstants.ROUTING_KEY, MESSAGE); - Transaction receiveTransaction = reporter.getFirstTransaction(1000); + TransactionImpl receiveTransaction = reporter.getFirstTransaction(1000); checkTransaction(receiveTransaction, QUEUE_NAME, "Spring AMQP"); - Span testSpan = reporter.getFirstSpan(1000); + SpanImpl testSpan = reporter.getFirstSpan(1000); assertThat(testSpan.getNameAsString()).isEqualTo("testSpan"); assertThat(testSpan.getType()).isEqualTo("custom"); checkParentChild(receiveTransaction, testSpan); @@ -66,23 +65,23 @@ public void verifyThatTransactionWithSpanCreated_NamingModeQueue() { @Test public void verifyThatTransactionWithSpanCreated_DistributedTracing() { - Transaction rootTransaction = startTestRootTransaction("Rabbit-Test Root Transaction"); + TransactionImpl rootTransaction = startTestRootTransaction("Rabbit-Test Root Transaction"); rabbitTemplate.convertAndSend(TOPIC_EXCHANGE_NAME, TestConstants.ROUTING_KEY, MESSAGE); rootTransaction.deactivate().end(); getReporter().awaitTransactionCount(2); getReporter().awaitSpanCount(2); - Transaction receiveTransaction = getNonRootTransaction(rootTransaction, getReporter().getTransactions()); + TransactionImpl receiveTransaction = getNonRootTransaction(rootTransaction, getReporter().getTransactions()); checkTransaction(receiveTransaction, TOPIC_EXCHANGE_NAME, "Spring AMQP"); assertThat(receiveTransaction.getSpanCount().getTotal().get()).isEqualTo(1); - List spans = getReporter().getSpans(); - Span sendSpan = spans.stream().filter(span -> span.getType().equals("messaging")).findFirst().get(); + List spans = getReporter().getSpans(); + SpanImpl sendSpan = spans.stream().filter(span -> span.getType().equals("messaging")).findFirst().get(); checkSendSpan(sendSpan, TOPIC_EXCHANGE_NAME, LOCALHOST_ADDRESS, container.getAmqpPort()); checkParentChild(sendSpan, receiveTransaction); - Span testSpan = spans.stream().filter(span -> span.getType().equals("custom")).findFirst().get(); + SpanImpl testSpan = spans.stream().filter(span -> span.getType().equals("custom")).findFirst().get(); assertThat(testSpan.getNameAsString()).isEqualTo("testSpan"); checkParentChild(receiveTransaction, testSpan); } @@ -90,27 +89,27 @@ public void verifyThatTransactionWithSpanCreated_DistributedTracing() { @Test public void verifyTransactionWithDefaultExchangeName() { rabbitTemplate.convertAndSend(TestConstants.QUEUE_NAME, MESSAGE); - Transaction receiveTransaction = reporter.getFirstTransaction(1000); + TransactionImpl receiveTransaction = reporter.getFirstTransaction(1000); checkTransaction(receiveTransaction, "", "Spring AMQP"); assertThat(receiveTransaction.getSpanCount().getTotal().get()).isEqualTo(1); - Span testSpan = reporter.getFirstSpan(1000); + SpanImpl testSpan = reporter.getFirstSpan(1000); assertThat(testSpan.getNameAsString()).isEqualTo("testSpan"); } @Test public void verifyTransactionWithDefaultExchangeName_DistributedTracing() { - Transaction rootTransaction = startTestRootTransaction("Rabbit-Test Root Transaction"); + TransactionImpl rootTransaction = startTestRootTransaction("Rabbit-Test Root Transaction"); rabbitTemplate.convertAndSend(TestConstants.QUEUE_NAME, MESSAGE); rootTransaction.deactivate().end(); getReporter().awaitTransactionCount(2); getReporter().awaitSpanCount(2); - Transaction receiveTransaction = getNonRootTransaction(rootTransaction, getReporter().getTransactions()); + TransactionImpl receiveTransaction = getNonRootTransaction(rootTransaction, getReporter().getTransactions()); checkTransaction(receiveTransaction, "", "Spring AMQP"); assertThat(receiveTransaction.getSpanCount().getTotal().get()).isEqualTo(1); - Span sendSpan = getReporter().getSpans().stream().filter(span -> span.getType().equals("messaging")).findFirst().get(); + SpanImpl sendSpan = getReporter().getSpans().stream().filter(span -> span.getType().equals("messaging")).findFirst().get(); checkSendSpan(sendSpan, "", LOCALHOST_ADDRESS, container.getAmqpPort()); checkParentChild(sendSpan, receiveTransaction); } diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/FanoutIT.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/FanoutIT.java index 6a636b5929..6d2dca3192 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/FanoutIT.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/FanoutIT.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.rabbitmq.config.FanoutConfiguration; import org.junit.Test; import org.junit.runner.RunWith; @@ -46,15 +46,15 @@ public void verifyThatTransactionWithSpanCreated() { getReporter().awaitTransactionCount(2); getReporter().awaitSpanCount(2); - List transactionList = getReporter().getTransactions(); + List transactionList = getReporter().getTransactions(); assertThat(transactionList.size()).isEqualTo(2); - for (Transaction transaction : transactionList) { + for (TransactionImpl transaction : transactionList) { assertThat(transaction.getNameAsString()).isEqualTo("RabbitMQ RECEIVE from foobar"); assertThat(transaction.getSpanCount().getTotal().get()).isEqualTo(1); } - List testSpans = getReporter().getSpans(); - for (Span testSpan : testSpans) { + List testSpans = getReporter().getSpans(); + for (SpanImpl testSpan : testSpans) { assertThat(testSpan.getNameAsString()).isEqualTo("testSpan"); } } diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchIT.java b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchIT.java index 361fd0af00..a77243764d 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchIT.java +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-spring/src/test/java/co/elastic/apm/agent/rabbitmq/SpringAmqpBatchIT.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.rabbitmq; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.rabbitmq.components.batch.BatchListenerComponent; import co.elastic.apm.agent.rabbitmq.config.BatchConfiguration; import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration; @@ -63,17 +63,17 @@ public void testTransactionPerMessage_noDistributedTracing() { getReporter().awaitTransactionCount(4); - List transactionList = getReporter().getTransactions(); + List transactionList = getReporter().getTransactions(); assertThat(transactionList.size()).isEqualTo(4); - for (Transaction transaction : transactionList) { + for (TransactionImpl transaction : transactionList) { assertThat(transaction.getNameAsString()).isEqualTo("Spring AMQP RECEIVE from "); assertThat(transaction.getSpanCount().getTotal().get()).isEqualTo(1); } - List spans = getReporter().getSpans(); + List spans = getReporter().getSpans(); assertThat(spans.size()).isEqualTo(4); - for (Span span : spans) { + for (SpanImpl span : spans) { assertThat(span.getNameAsString()).isEqualTo("testSpan"); } } @@ -82,7 +82,7 @@ public void testTransactionPerMessage_noDistributedTracing() { public void testTransactionPerMessage_withDistributedTracing() { doReturn(MessagingConfiguration.BatchStrategy.SINGLE_HANDLING).when(config.getConfig(MessagingConfiguration.class)).getMessageBatchStrategy(); - Transaction rootTraceTransaction = getTracer().startRootTransaction(null); + TransactionImpl rootTraceTransaction = getTracer().startRootTransaction(null); Objects.requireNonNull(rootTraceTransaction).activate(); batchingRabbitTemplate.convertAndSend(TestConstants.QUEUE_NAME, "hello"); @@ -95,30 +95,30 @@ public void testTransactionPerMessage_withDistributedTracing() { // 4 custom spans and 2 send spans because batch size is configured to 2 getReporter().awaitSpanCount(6); - List customSpans = getReporter().getSpans().stream() + List customSpans = getReporter().getSpans().stream() .filter(span -> Objects.equals(span.getType(), "custom")) .sorted(Comparator.comparing(span -> span.getTraceContext().getId().toString())) .collect(Collectors.toList()); assertThat(customSpans.size()).isEqualTo(4); - for (Span span : customSpans) { + for (SpanImpl span : customSpans) { assertThat(span.getNameAsString()).isEqualTo("testSpan"); assertThat(span.getTraceContext().getTraceId().toString()).isEqualTo(traceId); } - List sendSpans = getReporter().getSpans().stream() + List sendSpans = getReporter().getSpans().stream() .filter(span -> Objects.equals(span.getType(), "messaging")) .sorted(Comparator.comparing(span -> span.getTraceContext().getId().toString())) .collect(Collectors.toList()); assertThat(sendSpans.size()).isEqualTo(2); - for (Span span : sendSpans) { + for (SpanImpl span : sendSpans) { assertThat(span.getNameAsString()).isEqualTo("RabbitMQ SEND to "); assertThat(span.getTraceContext().getTraceId().toString()).isEqualTo(traceId); } getReporter().awaitTransactionCount(4); - List transactionList = new ArrayList<>(getReporter().getTransactions()); + List transactionList = new ArrayList<>(getReporter().getTransactions()); assertThat(transactionList.size()).isEqualTo(4); - for (Transaction transaction : transactionList) { + for (TransactionImpl transaction : transactionList) { assertThat(transaction.getNameAsString()).isEqualTo("Spring AMQP RECEIVE from "); assertThat(transaction.getSpanCount().getTotal().get()).isEqualTo(1); assertThat(transaction.getTraceContext().getTraceId().toString()).isEqualTo(traceId); @@ -138,7 +138,7 @@ public void testTransactionPerMessage_withDistributedTracing() { @Test public void testTransactionPerBatch() { - Transaction rootTraceTransaction = getTracer().startRootTransaction(null); + TransactionImpl rootTraceTransaction = getTracer().startRootTransaction(null); Objects.requireNonNull(rootTraceTransaction).activate(); batchingRabbitTemplate.convertAndSend(TestConstants.QUEUE_NAME, "hello"); @@ -148,14 +148,14 @@ public void testTransactionPerBatch() { // expecting one transaction per batch, of which configured size is 2 getReporter().awaitTransactionCount(2); - List transactionList = getReporter().getTransactions(); + List transactionList = getReporter().getTransactions(); getReporter().awaitUntilTimeout(200, () -> assertThat(transactionList.size()).isEqualTo(2)); - List spans = getReporter().getSpans(); + List spans = getReporter().getSpans(); // Expecting 2 send spans (one per two-message batch) and 4 custom test-spans assertThat(spans.size()).isEqualTo(6); - List sendSpans = getReporter().getSpans().stream() + List sendSpans = getReporter().getSpans().stream() .filter(span -> Objects.equals(span.getNameAsString(), "RabbitMQ SEND to ")) .collect(Collectors.toList()); assertThat(sendSpans.size()).isEqualTo(2); @@ -164,7 +164,7 @@ public void testTransactionPerBatch() { assertThat(span.getTraceContext().getParentId()).isEqualTo(rootTraceTransaction.getTraceContext().getId()); }); - List testSpans = getReporter().getSpans().stream() + List testSpans = getReporter().getSpans().stream() .filter(span -> Objects.equals(span.getNameAsString(), "testSpan")) .collect(Collectors.toList()); assertThat(testSpans.size()).isEqualTo(4); @@ -174,7 +174,7 @@ public void testTransactionPerBatch() { assertThat(span.getTraceContext().getTraceId()).isNotEqualTo(rootTraceTransaction.getTraceContext().getTraceId()); }); - for (Transaction transaction : transactionList) { + for (TransactionImpl transaction : transactionList) { assertThat(transaction.getNameAsString()).isEqualTo("Spring AMQP Message Batch Processing"); assertThat(transaction.getSpanCount().getTotal().get()).isEqualTo(2); assertThat(testSpans.stream() @@ -183,10 +183,10 @@ public void testTransactionPerBatch() { ).isEqualTo(2); assertThat(transaction.getTraceContext().getTraceId()).isNotEqualTo(rootTraceTransaction.getTraceContext().getTraceId()); - List spanLinks = transaction.getSpanLinks(); + List spanLinks = transaction.getSpanLinks(); // we expect one span link because each batch of two messages is related to a single send span assertThat(spanLinks.size()).isEqualTo(1); - TraceContext spanLink = spanLinks.get(0); + TraceContextImpl spanLink = spanLinks.get(0); assertThat(sendSpans.stream().anyMatch(sendSpan -> sendSpan.getTraceContext().getId().equals(spanLink.getParentId()))).isTrue(); assertThat(sendSpans.stream().anyMatch(sendSpan -> sendSpan.getTraceContext().getTraceId().equals(spanLink.getTraceId()))).isTrue(); } diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-test-3/pom.xml b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-test-3/pom.xml index a524901739..277a893018 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-test-3/pom.xml +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-test-3/pom.xml @@ -5,7 +5,7 @@ apm-rabbitmq co.elastic.apm - 1.50.0 + 1.51.0 apm-rabbitmq-test-3 diff --git a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-test-4/pom.xml b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-test-4/pom.xml index b7fad3e593..a96df80934 100644 --- a/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-test-4/pom.xml +++ b/apm-agent-plugins/apm-rabbitmq/apm-rabbitmq-test-4/pom.xml @@ -5,7 +5,7 @@ apm-rabbitmq co.elastic.apm - 1.50.0 + 1.51.0 apm-rabbitmq-test-4 diff --git a/apm-agent-plugins/apm-rabbitmq/pom.xml b/apm-agent-plugins/apm-rabbitmq/pom.xml index 2418b90876..7ee5a9bce2 100644 --- a/apm-agent-plugins/apm-rabbitmq/pom.xml +++ b/apm-agent-plugins/apm-rabbitmq/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-rabbitmq diff --git a/apm-agent-plugins/apm-reactor-plugin/pom.xml b/apm-agent-plugins/apm-reactor-plugin/pom.xml index 4aa2434152..a5ba1e858a 100644 --- a/apm-agent-plugins/apm-reactor-plugin/pom.xml +++ b/apm-agent-plugins/apm-reactor-plugin/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-agent-plugins - 1.50.0 + 1.51.0 apm-reactor-plugin diff --git a/apm-agent-plugins/apm-reactor-plugin/src/main/java/co/elastic/apm/agent/reactor/TracedSubscriber.java b/apm-agent-plugins/apm-reactor-plugin/src/main/java/co/elastic/apm/agent/reactor/TracedSubscriber.java index a1438d936b..5b381c78b2 100644 --- a/apm-agent-plugins/apm-reactor-plugin/src/main/java/co/elastic/apm/agent/reactor/TracedSubscriber.java +++ b/apm-agent-plugins/apm-reactor-plugin/src/main/java/co/elastic/apm/agent/reactor/TracedSubscriber.java @@ -23,7 +23,7 @@ import co.elastic.apm.agent.sdk.state.GlobalVariables; import co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent; import co.elastic.apm.agent.sdk.weakconcurrent.WeakMap; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; @@ -47,7 +47,7 @@ public class TracedSubscriber implements CoreSubscriber { private static final AtomicBoolean isRegistered = GlobalVariables.get(ReactorInstrumentation.class, "reactor-hook-enabled", new AtomicBoolean(false)); - private static final ReferenceCountedMap, ElasticContext> contextMap = GlobalTracer.get().newReferenceCountedMap(); + private static final ReferenceCountedMap, TraceState> contextMap = GlobalTracer.get().newReferenceCountedMap(); private static final String HOOK_KEY = "elastic-apm"; @@ -57,13 +57,13 @@ public class TracedSubscriber implements CoreSubscriber { private final Context context; - TracedSubscriber(CoreSubscriber subscriber, Tracer tracer, ElasticContext context) { + TracedSubscriber(CoreSubscriber subscriber, Tracer tracer, TraceState context) { this.subscriber = subscriber; this.tracer = tracer; contextMap.put(this, context); // store our span/transaction into reactor context for later lookup without relying on active tracer state - this.context = subscriber.currentContext().put(ElasticContext.class, context); + this.context = subscriber.currentContext().put(TraceState.class, context); } @Override @@ -78,7 +78,7 @@ public Context currentContext() { */ @Override public void onSubscribe(Subscription s) { - ElasticContext context = getContext(); + TraceState context = getContext(); boolean hasActivated = doEnter("onSubscribe", context); Throwable thrown = null; try { @@ -99,7 +99,7 @@ public void onSubscribe(Subscription s) { */ @Override public void onNext(T next) { - ElasticContext context = getContext(); + TraceState context = getContext(); boolean hasActivated = doEnter("onNext", context); Throwable thrown = null; try { @@ -120,7 +120,7 @@ public void onNext(T next) { */ @Override public void onError(Throwable t) { - ElasticContext context = getContext(); + TraceState context = getContext(); boolean hasActivated = doEnter("onError", context); try { subscriber.onError(t); @@ -135,7 +135,7 @@ public void onError(Throwable t) { */ @Override public void onComplete() { - ElasticContext context = getContext(); + TraceState context = getContext(); boolean hasActivated = doEnter("onComplete", context); try { subscriber.onComplete(); @@ -152,7 +152,7 @@ public void onComplete() { * @param context context * @return {@literal true} if context has been activated */ - private boolean doEnter(String method, @Nullable ElasticContext context) { + private boolean doEnter(String method, @Nullable TraceState context) { debugTrace(true, method, context); if (context == null || tracer.currentContext() == context) { @@ -171,7 +171,7 @@ private boolean doEnter(String method, @Nullable ElasticContext context) { * @param method method name (only for debugging) * @param context context */ - private void doExit(boolean deactivate, String method, @Nullable ElasticContext context) { + private void doExit(boolean deactivate, String method, @Nullable TraceState context) { debugTrace(false, method, context); if (context == null || !deactivate) { @@ -194,7 +194,7 @@ private void discardIf(boolean condition) { contextMap.remove(this); } - private void debugTrace(boolean isEnter, String method, @Nullable ElasticContext context) { + private void debugTrace(boolean isEnter, String method, @Nullable TraceState context) { if (!log.isTraceEnabled()) { return; } @@ -205,7 +205,7 @@ private void debugTrace(boolean isEnter, String method, @Nullable ElasticContext * @return context associated with {@literal this}. */ @Nullable - private ElasticContext getContext() { + private TraceState getContext() { return contextMap.get(this); } @@ -252,11 +252,11 @@ public CoreSubscriber apply(Publisher publisher, CoreSubscriber active = tracer.currentContext(); + TraceState active = tracer.currentContext(); // fallback to using context-stored span/transaction if not already active if (active.isEmpty()) { - active = subscriber.currentContext().getOrDefault(ElasticContext.class, null); + active = subscriber.currentContext().getOrDefault(TraceState.class, null); } if (active == null || active.isEmpty()) { diff --git a/apm-agent-plugins/apm-reactor-plugin/src/test/java/co/elastic/apm/agent/reactor/TracedSubscriberTest.java b/apm-agent-plugins/apm-reactor-plugin/src/test/java/co/elastic/apm/agent/reactor/TracedSubscriberTest.java index aa99e7c493..90ebb2290a 100644 --- a/apm-agent-plugins/apm-reactor-plugin/src/test/java/co/elastic/apm/agent/reactor/TracedSubscriberTest.java +++ b/apm-agent-plugins/apm-reactor-plugin/src/test/java/co/elastic/apm/agent/reactor/TracedSubscriberTest.java @@ -20,9 +20,9 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.impl.baggage.BaggageContext; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; +import co.elastic.apm.agent.tracer.TraceState; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -45,7 +45,7 @@ class TracedSubscriberTest extends AbstractInstrumentationTest { private static final Scheduler PUBLISH_SCHEDULER = Schedulers.newElastic("publish"); @Nullable - private Transaction transaction; + private TransactionImpl transaction; private static long mainThreadId; @@ -239,7 +239,7 @@ private static long currentThreadId() { return Thread.currentThread().getId(); } - static Predicate inMainThread(@Nullable AbstractSpan expectedContext, int expectedValue) { + static Predicate inMainThread(@Nullable AbstractSpanImpl expectedContext, int expectedValue) { return observation -> { observation.checkThread(true) .checkActiveContext(expectedContext) @@ -248,7 +248,7 @@ static Predicate inMainThread(@Nullable AbstractSpan expecte }; } - static Predicate inOtherThread(@Nullable ElasticContext expectedContext, int expectedValue) { + static Predicate inOtherThread(@Nullable TraceState expectedContext, int expectedValue) { return observation -> { observation .checkActiveContext(expectedContext) @@ -278,7 +278,7 @@ static Predicate noActiveContext(int expectedValue) { */ private static class TestObservation { @Nullable - private final ElasticContext activeContext; + private final TraceState activeContext; private final Long threadId; private final int value; @@ -314,7 +314,7 @@ TestObservation checkThread(boolean mainThread) { return this; } - TestObservation checkActiveContext(@Nullable ElasticContext expectedActiveContext) { + TestObservation checkActiveContext(@Nullable TraceState expectedActiveContext) { if (expectedActiveContext == null) { assertThat(activeContext.isEmpty()) .describedAs("unexpected active context in thread %d", threadId) @@ -334,7 +334,7 @@ TestObservation checkValue(int expectedValue) { } - private static void checkActiveContext(@Nullable AbstractSpan expectedActive) { + private static void checkActiveContext(@Nullable AbstractSpanImpl expectedActive) { assertThat(tracer.getActive()) .describedAs("active context not available") .isNotNull() diff --git a/apm-agent-plugins/apm-redis-plugin/apm-jedis-2-tests/pom.xml b/apm-agent-plugins/apm-redis-plugin/apm-jedis-2-tests/pom.xml index 7fc6378873..a18f749aea 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-jedis-2-tests/pom.xml +++ b/apm-agent-plugins/apm-redis-plugin/apm-jedis-2-tests/pom.xml @@ -5,7 +5,7 @@ apm-redis-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-jedis-2-tests diff --git a/apm-agent-plugins/apm-redis-plugin/apm-jedis-3-tests/pom.xml b/apm-agent-plugins/apm-redis-plugin/apm-jedis-3-tests/pom.xml index 6f70d6886c..884abcd4bb 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-jedis-3-tests/pom.xml +++ b/apm-agent-plugins/apm-redis-plugin/apm-jedis-3-tests/pom.xml @@ -5,7 +5,7 @@ apm-redis-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-jedis-3-tests diff --git a/apm-agent-plugins/apm-redis-plugin/apm-jedis-4-plugin/pom.xml b/apm-agent-plugins/apm-redis-plugin/apm-jedis-4-plugin/pom.xml index 74be2c6883..1a254e62b8 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-jedis-4-plugin/pom.xml +++ b/apm-agent-plugins/apm-redis-plugin/apm-jedis-4-plugin/pom.xml @@ -5,7 +5,7 @@ apm-redis-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-jedis-4-plugin diff --git a/apm-agent-plugins/apm-redis-plugin/apm-jedis-5-tests/pom.xml b/apm-agent-plugins/apm-redis-plugin/apm-jedis-5-tests/pom.xml index 299a78e47e..1a2b55695f 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-jedis-5-tests/pom.xml +++ b/apm-agent-plugins/apm-redis-plugin/apm-jedis-5-tests/pom.xml @@ -5,7 +5,7 @@ apm-redis-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-jedis-5-tests @@ -46,7 +46,7 @@ redis.clients jedis - 5.1.2 + 5.1.3 test diff --git a/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/pom.xml b/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/pom.xml index 17bc10cb7d..011369298f 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/pom.xml +++ b/apm-agent-plugins/apm-redis-plugin/apm-jedis-plugin/pom.xml @@ -5,7 +5,7 @@ apm-redis-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-jedis-plugin diff --git a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-3-tests/pom.xml b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-3-tests/pom.xml index a348c446e9..3222af65d1 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-3-tests/pom.xml +++ b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-3-tests/pom.xml @@ -3,7 +3,7 @@ apm-redis-plugin co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/pom.xml b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/pom.xml index 6cb3754145..09e489d14d 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/pom.xml +++ b/apm-agent-plugins/apm-redis-plugin/apm-lettuce-plugin/pom.xml @@ -3,7 +3,7 @@ apm-redis-plugin co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-redis-plugin/apm-redis-common/pom.xml b/apm-agent-plugins/apm-redis-plugin/apm-redis-common/pom.xml index 3323224624..162b49ce34 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-redis-common/pom.xml +++ b/apm-agent-plugins/apm-redis-plugin/apm-redis-common/pom.xml @@ -5,7 +5,7 @@ apm-redis-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-redis-common diff --git a/apm-agent-plugins/apm-redis-plugin/apm-redis-common/src/test/java/co/elastic/apm/agent/redis/AbstractRedisInstrumentationTest.java b/apm-agent-plugins/apm-redis-plugin/apm-redis-common/src/test/java/co/elastic/apm/agent/redis/AbstractRedisInstrumentationTest.java index 87237dda14..f4f7b2581e 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-redis-common/src/test/java/co/elastic/apm/agent/redis/AbstractRedisInstrumentationTest.java +++ b/apm-agent-plugins/apm-redis-plugin/apm-redis-common/src/test/java/co/elastic/apm/agent/redis/AbstractRedisInstrumentationTest.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.redis; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.context.Destination; +import co.elastic.apm.agent.impl.context.DestinationImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; import org.junit.After; import org.junit.Before; import org.junit.jupiter.api.AfterEach; @@ -62,7 +62,7 @@ public final void initRedis() throws IOException { @After @AfterEach public final void stopRedis() { - Transaction transaction = tracer.currentTransaction(); + TransactionImpl transaction = tracer.currentTransaction(); if (transaction != null) { transaction.deactivate().end(); } @@ -71,18 +71,18 @@ public final void stopRedis() { public void assertTransactionWithRedisSpans(String... commands) { await().untilAsserted(() -> assertThat(reporter.getSpans()).hasSize(commands.length)); - assertThat(reporter.getSpans().stream().map(Span::getNameAsString)).containsExactly(commands); - assertThat(reporter.getSpans().stream().map(Span::getType).distinct()).containsExactly("db"); - assertThat(reporter.getSpans().stream().map(Span::getSubtype).distinct()).containsExactly("redis"); - assertThat(reporter.getSpans().stream().map(Span::getAction).distinct()).containsExactly("query"); - assertThat(reporter.getSpans().stream().map(Span::isExit).distinct()).containsExactly(true); - assertThat(reporter.getSpans().stream().map(Span::getOutcome).distinct()).containsExactly(Outcome.SUCCESS); + assertThat(reporter.getSpans().stream().map(SpanImpl::getNameAsString)).containsExactly(commands); + assertThat(reporter.getSpans().stream().map(SpanImpl::getType).distinct()).containsExactly("db"); + assertThat(reporter.getSpans().stream().map(SpanImpl::getSubtype).distinct()).containsExactly("redis"); + assertThat(reporter.getSpans().stream().map(SpanImpl::getAction).distinct()).containsExactly("query"); + assertThat(reporter.getSpans().stream().map(SpanImpl::isExit).distinct()).containsExactly(true); + assertThat(reporter.getSpans().stream().map(SpanImpl::getOutcome).distinct()).containsExactly(Outcome.SUCCESS); verifyDestinationDetails(reporter.getSpans()); } - private void verifyDestinationDetails(List spanList) { - for (Span span : spanList) { - Destination destination = span.getContext().getDestination(); + private void verifyDestinationDetails(List spanList) { + for (SpanImpl span : spanList) { + DestinationImpl destination = span.getContext().getDestination(); if (destinationAddressSupported()) { assertThat(destination.getAddress().toString()).isEqualTo(expectedAddress); assertThat(destination.getPort()).isEqualTo(redisPort); diff --git a/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/pom.xml b/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/pom.xml index 8fd8be942b..3affe7abf0 100644 --- a/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/pom.xml +++ b/apm-agent-plugins/apm-redis-plugin/apm-redisson-plugin/pom.xml @@ -5,7 +5,7 @@ apm-redis-plugin co.elastic.apm - 1.50.0 + 1.51.0 apm-redisson-plugin diff --git a/apm-agent-plugins/apm-redis-plugin/pom.xml b/apm-agent-plugins/apm-redis-plugin/pom.xml index 99a386a1dc..d0ddda2d60 100644 --- a/apm-agent-plugins/apm-redis-plugin/pom.xml +++ b/apm-agent-plugins/apm-redis-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-redis-plugin diff --git a/apm-agent-plugins/apm-scala-concurrent-plugin/pom.xml b/apm-agent-plugins/apm-scala-concurrent-plugin/pom.xml index cf14ac34e2..5082c7b807 100644 --- a/apm-agent-plugins/apm-scala-concurrent-plugin/pom.xml +++ b/apm-agent-plugins/apm-scala-concurrent-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-scala-concurrent-plugin diff --git a/apm-agent-plugins/apm-scala-concurrent-plugin/src/main/java/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentation.java b/apm-agent-plugins/apm-scala-concurrent-plugin/src/main/java/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentation.java index 59277bfc5c..e9f604f95c 100644 --- a/apm-agent-plugins/apm-scala-concurrent-plugin/src/main/java/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentation.java +++ b/apm-agent-plugins/apm-scala-concurrent-plugin/src/main/java/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentation.java @@ -19,9 +19,8 @@ package co.elastic.apm.agent.scalaconcurrent; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; -import co.elastic.apm.agent.tracer.AbstractSpan; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Tracer; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; import net.bytebuddy.asm.Advice; @@ -43,7 +42,7 @@ public abstract class FutureInstrumentation extends ElasticApmInstrumentation { private static final Tracer tracer = GlobalTracer.get(); @SuppressWarnings("WeakerAccess") - public static final ReferenceCountedMap> promisesToContext = tracer.newReferenceCountedMap(); + public static final ReferenceCountedMap> promisesToContext = tracer.newReferenceCountedMap(); @Nonnull @Override @@ -66,7 +65,7 @@ public ElementMatcher getMethodMatcher() { public static class AdviceClass { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void onExit(@Advice.This Object thiz) { - final ElasticContext context = tracer.currentContext(); + final TraceState context = tracer.currentContext(); if (!context.isEmpty()) { promisesToContext.put(thiz, context); } @@ -93,7 +92,7 @@ public static class AdviceClass { public static Object onEnter(@Advice.This Object thiz) { // We cannot remove yet, as this may decrement the ref count of the span to 0 if it has already ended, // thus causing it to be recycled just before we activate it on the current thread. So we first get(). - ElasticContext context = promisesToContext.get(thiz); + TraceState context = promisesToContext.get(thiz); if (context != null) { context.activate(); // Now it's safe to remove, as ref count is at least 2 @@ -105,7 +104,7 @@ public static Object onEnter(@Advice.This Object thiz) { @Advice.OnMethodExit(suppress = Throwable.class, inline = false) public static void onExit(@Advice.Enter @Nullable Object contextObj) { if (contextObj != null) { - ElasticContext context = (ElasticContext) contextObj; + TraceState context = (TraceState) contextObj; context.deactivate(); } } diff --git a/apm-agent-plugins/apm-scala-concurrent-plugin/src/test/scala/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentationSpec.scala b/apm-agent-plugins/apm-scala-concurrent-plugin/src/test/scala/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentationSpec.scala index 79e7a296e4..3dd92274e8 100644 --- a/apm-agent-plugins/apm-scala-concurrent-plugin/src/test/scala/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentationSpec.scala +++ b/apm-agent-plugins/apm-scala-concurrent-plugin/src/test/scala/co/elastic/apm/agent/scalaconcurrent/FutureInstrumentationSpec.scala @@ -2,7 +2,7 @@ package co.elastic.apm.agent.scalaconcurrent import co.elastic.apm.agent.MockReporter import co.elastic.apm.agent.bci.ElasticApmAgent -import co.elastic.apm.agent.configuration.{CoreConfiguration, SpyConfiguration} +import co.elastic.apm.agent.configuration.{CoreConfigurationImpl, SpyConfiguration} import co.elastic.apm.agent.impl.{ElasticApmTracer, ElasticApmTracerBuilder} import munit.FunSuite import net.bytebuddy.agent.ByteBuddyAgent @@ -17,12 +17,12 @@ class FutureInstrumentationSpec extends FunSuite { private var reporter: MockReporter = _ private var tracer: ElasticApmTracer = _ - private var coreConfiguration: CoreConfiguration = _ + private var CoreConfigurationImpl: CoreConfigurationImpl = _ override def beforeEach(context: BeforeEach): Unit = { reporter = new MockReporter val config: ConfigurationRegistry = SpyConfiguration.createSpyConfig - coreConfiguration = config.getConfig(classOf[CoreConfiguration]) + CoreConfigurationImpl = config.getConfig(classOf[CoreConfigurationImpl]) tracer = new ElasticApmTracerBuilder().configurationRegistry(config).reporter(reporter).build ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install) tracer.start(false) diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin-jakartaee-test/pom.xml b/apm-agent-plugins/apm-scheduled-annotation-plugin-jakartaee-test/pom.xml index 301ec36602..518805891c 100644 --- a/apm-agent-plugins/apm-scheduled-annotation-plugin-jakartaee-test/pom.xml +++ b/apm-agent-plugins/apm-scheduled-annotation-plugin-jakartaee-test/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin/pom.xml b/apm-agent-plugins/apm-scheduled-annotation-plugin/pom.xml index ac581544a4..33aee9d478 100644 --- a/apm-agent-plugins/apm-scheduled-annotation-plugin/pom.xml +++ b/apm-agent-plugins/apm-scheduled-annotation-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-scheduled-annotation-plugin diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/AbstractScheduledInstrumentationTest.java b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/AbstractScheduledInstrumentationTest.java index 7503ada5ce..9d07159abd 100644 --- a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/AbstractScheduledInstrumentationTest.java +++ b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/AbstractScheduledInstrumentationTest.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.scheduled; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Transaction; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -31,8 +31,8 @@ public abstract class AbstractScheduledInstrumentationTest extends AbstractInstrumentationTest { - protected static List checkTransactions(AbstractCounter counter, int expectedCount, String expectedName) { - List transactions = reporter.getTransactions(); + protected static List checkTransactions(AbstractCounter counter, int expectedCount, String expectedName) { + List transactions = reporter.getTransactions(); assertThat(transactions).hasSize(counter.getInvocationCount()).hasSize(expectedCount); transactions.forEach(t -> { assertThat(t.getNameAsString()).isEqualTo(expectedName); @@ -40,9 +40,9 @@ protected static List checkTransactions(AbstractCounter counter, in return transactions; } - protected static void checkOutcome(List transactions, Outcome outcome) { + protected static void checkOutcome(List transactions, Outcome outcome) { assertThat(transactions.stream() - .map(AbstractSpan::getOutcome) + .map(AbstractSpanImpl::getOutcome) .collect(Collectors.toSet())) .containsExactly(outcome); } diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/AbstractScheduledTransactionNameInstrumentationTest.java b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/AbstractScheduledTransactionNameInstrumentationTest.java index 9ad8b35a74..38195697cc 100644 --- a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/AbstractScheduledTransactionNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/AbstractScheduledTransactionNameInstrumentationTest.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.scheduled; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Transaction; import org.junit.jupiter.api.Test; import java.util.List; @@ -35,7 +35,7 @@ void testJeeScheduledAnnotatedMethodsAreTraced() { jeeCounter.scheduled(); jeeCounter.scheduled(); jeeCounter.scheduled(); - List transactions = checkTransactions(jeeCounter, 3, "JeeCounterImpl#scheduled"); + List transactions = checkTransactions(jeeCounter, 3, "JeeCounterImpl#scheduled"); checkOutcome(transactions, Outcome.SUCCESS); } @@ -44,7 +44,7 @@ void testJeeJ7RepeatableScheduledAnnotatedMethodsAreTraced() { JeeCounter jeeCounter = createJeeCounterImpl(); jeeCounter.scheduledJava7Repeatable(); jeeCounter.scheduledJava7Repeatable(); - List transactions = checkTransactions(jeeCounter, 2, "JeeCounterImpl#scheduledJava7Repeatable"); + List transactions = checkTransactions(jeeCounter, 2, "JeeCounterImpl#scheduledJava7Repeatable"); checkOutcome(transactions, Outcome.SUCCESS); } @@ -54,7 +54,7 @@ void testThrownErrorOutcomes() { assertThatThrownBy(throwCounter::throwingException); - List transactions = checkTransactions(throwCounter, 1, "ThrowingCounterImpl#throwingException"); + List transactions = checkTransactions(throwCounter, 1, "ThrowingCounterImpl#throwingException"); checkOutcome(transactions, Outcome.FAILURE); } diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/SpringScheduledTransactionNameInstrumentationTest.java b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/SpringScheduledTransactionNameInstrumentationTest.java index 0f3e936d9a..f10e4263b7 100644 --- a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/SpringScheduledTransactionNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/SpringScheduledTransactionNameInstrumentationTest.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.scheduled; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; -import co.elastic.apm.agent.impl.transaction.Transaction; import org.junit.jupiter.api.Test; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Schedules; @@ -34,7 +34,7 @@ void testSpringScheduledAnnotatedMethodsAreTraced() { springCounter.scheduled(); springCounter.scheduled(); - List transactions = checkTransactions(springCounter, 2, "SpringCounter#scheduled"); + List transactions = checkTransactions(springCounter, 2, "SpringCounter#scheduled"); checkOutcome(transactions, Outcome.SUCCESS); } @@ -44,7 +44,7 @@ void testSpringJ8RepeatableScheduledAnnotatedMethodsAreTraced() { springCounter.scheduledJava8Repeatable(); springCounter.scheduledJava8Repeatable(); - List transactions = checkTransactions(springCounter, 2, "SpringCounter#scheduledJava8Repeatable"); + List transactions = checkTransactions(springCounter, 2, "SpringCounter#scheduledJava8Repeatable"); checkOutcome(transactions, Outcome.SUCCESS); } @@ -54,7 +54,7 @@ void testSpringJ7RepeatableScheduledAnnotatedMethodsAreTraced() { springCounter.scheduledJava7Repeatable(); springCounter.scheduledJava7Repeatable(); - List transactions = checkTransactions(springCounter, 2, "SpringCounter#scheduledJava7Repeatable"); + List transactions = checkTransactions(springCounter, 2, "SpringCounter#scheduledJava7Repeatable"); checkOutcome(transactions, Outcome.SUCCESS); } diff --git a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentationTest.java b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentationTest.java index 51bde1ac88..49c8a4e1a0 100644 --- a/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentationTest.java +++ b/apm-agent-plugins/apm-scheduled-annotation-plugin/src/test/java/co/elastic/apm/agent/scheduled/TimerTaskInstrumentationTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.scheduled; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.Test; import java.util.Timer; @@ -40,11 +40,11 @@ void testTimerTask_scheduleWithFixedRate() { assertThat(reporter.getTransactions() .stream() - .map(AbstractSpan::getNameAsString)) + .map(AbstractSpanImpl::getNameAsString)) .containsExactly("TestTimerTask#run", "TestTimerTask#run"); assertThat(reporter.getTransactions() .stream() - .map(Transaction::getFrameworkName)) + .map(TransactionImpl::getFrameworkName)) .containsExactly("TimerTask", "TimerTask"); } @@ -57,7 +57,7 @@ void testTimerTask_scheduleWithFixedDelay() { assertThat(reporter.getTransactions() .stream() - .map(AbstractSpan::getNameAsString)) + .map(AbstractSpanImpl::getNameAsString)) .containsExactly("TestTimerTask#run", "TestTimerTask#run"); } diff --git a/apm-agent-plugins/apm-servlet-jakarta-test/pom.xml b/apm-agent-plugins/apm-servlet-jakarta-test/pom.xml index c204bc33d5..8d9f648693 100644 --- a/apm-agent-plugins/apm-servlet-jakarta-test/pom.xml +++ b/apm-agent-plugins/apm-servlet-jakarta-test/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-servlet-jakarta-test diff --git a/apm-agent-plugins/apm-servlet-jakarta-test/src/test/java/co/elastic/apm/agent/servlet/JakartaAsyncServletTest.java b/apm-agent-plugins/apm-servlet-jakarta-test/src/test/java/co/elastic/apm/agent/servlet/JakartaAsyncServletTest.java index 380761ceb1..8cb7e8a300 100644 --- a/apm-agent-plugins/apm-servlet-jakarta-test/src/test/java/co/elastic/apm/agent/servlet/JakartaAsyncServletTest.java +++ b/apm-agent-plugins/apm-servlet-jakarta-test/src/test/java/co/elastic/apm/agent/servlet/JakartaAsyncServletTest.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.servlet; -import co.elastic.apm.agent.impl.context.TransactionContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.eclipse.jetty.servlet.ServletContextHandler; import org.junit.jupiter.api.Test; @@ -99,7 +99,7 @@ private void assertHasOneTransaction(String path, Predicate bodyPredicat assertThat(reporter.getFirstTransaction(500)).isNotNull(); assertThat(reporter.getTransactions()).hasSize(1); assertThat(reporter.getFirstTransaction().getNameAsString()).contains("Servlet").contains("#doGet"); - final TransactionContext context = reporter.getFirstTransaction().getContext(); + final TransactionContextImpl context = reporter.getFirstTransaction().getContext(); assertThat(context.getRequest().getUrl().getPathname()).isEqualTo(path); assertThat(context.getResponse().getStatusCode()).isEqualTo(status); } @@ -109,7 +109,7 @@ public static class AsyncStartServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final AsyncContext asyncContext = req.startAsync(); - final Transaction transaction = tracer.currentTransaction(); + final TransactionImpl transaction = tracer.currentTransaction(); asyncContext.start(() -> { try { assertThat(tracer.getActive()).isSameAs(transaction); diff --git a/apm-agent-plugins/apm-servlet-jakarta-test/src/test/java/co/elastic/apm/agent/servlet/JakartaServletInstrumentationTest.java b/apm-agent-plugins/apm-servlet-jakarta-test/src/test/java/co/elastic/apm/agent/servlet/JakartaServletInstrumentationTest.java index 74cc1431e1..1cc7760dab 100644 --- a/apm-agent-plugins/apm-servlet-jakarta-test/src/test/java/co/elastic/apm/agent/servlet/JakartaServletInstrumentationTest.java +++ b/apm-agent-plugins/apm-servlet-jakarta-test/src/test/java/co/elastic/apm/agent/servlet/JakartaServletInstrumentationTest.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.servlet; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.TracerInternalApiUtils; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.util.ResultUtil; -import co.elastic.apm.agent.impl.transaction.Span; import jakarta.servlet.DispatcherType; import jakarta.servlet.Filter; import jakarta.servlet.FilterChain; @@ -133,21 +133,21 @@ void testClientError() throws Exception { @Test void testForward_DispatchSpansDisabled() throws Exception { - doReturn(false).when(getConfig().getConfig(CoreConfiguration.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); + doReturn(false).when(getConfig().getConfig(CoreConfigurationImpl.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); callServlet(1, "/forward"); assertThat(reporter.getSpans()).isEmpty(); } @Test void testInclude_DispatchSpansDisabled() throws Exception { - doReturn(false).when(getConfig().getConfig(CoreConfiguration.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); + doReturn(false).when(getConfig().getConfig(CoreConfigurationImpl.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); callServlet(1, "/include"); assertThat(reporter.getSpans()).isEmpty(); } @Test void testClientError_DispatchSpansDisabled() throws Exception { - doReturn(false).when(getConfig().getConfig(CoreConfiguration.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); + doReturn(false).when(getConfig().getConfig(CoreConfigurationImpl.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); callServlet(1, "/unknown", "Hello Error!", 404); assertThat(reporter.getSpans()).isEmpty(); // TODO - ERROR NOT CAPTURED @@ -174,7 +174,7 @@ void testServletInstrumentationWithPathInfo() throws Exception { void testForwardWithPathInfo_verifyThatSpanNameContainsOriginalServletPathAndPathInfo() throws Exception { callServlet(1, "/forward/path", "Hello World! /forward-path-info", 200); assertThat(reporter.getSpans().size()).isEqualTo(1); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span.getType()).isEqualTo(SPAN_TYPE); assertThat(span.getSubtype()).isEqualTo(SPAN_SUBTYPE); assertThat(span.getAction()).isEqualTo(FORWARD.getAction()); @@ -185,7 +185,7 @@ void testForwardWithPathInfo_verifyThatSpanNameContainsOriginalServletPathAndPat void testIncludeWithPathInfo_verifyThatSpanNameContainsOriginalServletPathAndPathInfo() throws Exception { callServlet(1, "/include/path", "Hello World! /include-path-info", 200); assertThat(reporter.getSpans().size()).isEqualTo(1); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span.getType()).isEqualTo(SPAN_TYPE); assertThat(span.getSubtype()).isEqualTo(SPAN_SUBTYPE); assertThat(span.getAction()).isEqualTo(INCLUDE.getAction()); diff --git a/apm-agent-plugins/apm-servlet-plugin/pom.xml b/apm-agent-plugins/apm-servlet-plugin/pom.xml index 4150a4e955..951f02fc31 100644 --- a/apm-agent-plugins/apm-servlet-plugin/pom.xml +++ b/apm-agent-plugins/apm-servlet-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-servlet-plugin diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletApiAdvice.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletApiAdvice.java index 65695644e1..077cc52742 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletApiAdvice.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletApiAdvice.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.servlet; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Scope; @@ -127,7 +127,7 @@ public static activeContext = tracer.currentContext(); + final TraceState activeContext = tracer.currentContext(); final AbstractSpan parentSpan = activeContext.getSpan(); if (parentSpan != null) { Object servletPath = null; diff --git a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletServiceNameHelper.java b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletServiceNameHelper.java index e58bdf02dc..85bc37bb26 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletServiceNameHelper.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletServiceNameHelper.java @@ -18,7 +18,6 @@ */ package co.elastic.apm.agent.servlet; -import co.elastic.apm.agent.tracer.service.ServiceAwareTracer; import co.elastic.apm.agent.tracer.service.ServiceInfo; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; @@ -44,11 +43,6 @@ public static void determineServiceName(ServletContextAdapter void determineServiceName(ServletContextAdapter ServiceInfo detectServiceInfo(ServletContextAdapter adapter, ServletContext servletContext, ClassLoader servletContextClassLoader) { diff --git a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ApmFilterTest.java b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ApmFilterTest.java index 9182631d7a..ab877431d7 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ApmFilterTest.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ApmFilterTest.java @@ -19,14 +19,14 @@ package co.elastic.apm.agent.servlet; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.TracerInternalApiUtils; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Response; -import co.elastic.apm.agent.impl.context.TransactionContext; -import co.elastic.apm.agent.impl.context.Url; +import co.elastic.apm.agent.impl.context.RequestImpl; +import co.elastic.apm.agent.impl.context.ResponseImpl; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; +import co.elastic.apm.agent.impl.context.UrlImpl; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -63,13 +63,13 @@ class ApmFilterTest extends AbstractInstrumentationTest { private WebConfiguration webConfiguration; - private CoreConfiguration coreConfiguration; + private CoreConfigurationImpl coreConfiguration; private MockFilterChain filterChain; @BeforeEach void setUp() { webConfiguration = tracer.getConfig(WebConfiguration.class); - coreConfiguration = tracer.getConfig(CoreConfiguration.class); + coreConfiguration = tracer.getConfig(CoreConfigurationImpl.class); filterChain = new MockFilterChain(); } @@ -92,8 +92,8 @@ void testURLTransaction() throws IOException, ServletException { request.setQueryString("foo=bar"); filterChain.doFilter(request, new MockHttpServletResponse()); - TransactionContext transactionContext = reporter.getFirstTransaction().getContext(); - Url url = transactionContext.getRequest().getUrl(); + TransactionContextImpl transactionContext = reporter.getFirstTransaction().getContext(); + UrlImpl url = transactionContext.getRequest().getUrl(); assertThat(url.getProtocol()).isEqualTo("http"); assertThat(url.getSearch()).isEqualTo("foo=bar"); assertThat(url.getPort()).isEqualTo(80); @@ -285,11 +285,11 @@ void testAllHeaderRecording() throws IOException, ServletException { mockResponse.addHeader("bar", "baz"); filterChain.doFilter(get, mockResponse); assertThat(reporter.getTransactions()).hasSize(1); - final Request request = reporter.getFirstTransaction().getContext().getRequest(); + final RequestImpl request = reporter.getFirstTransaction().getContext().getRequest(); assertThat(request.getHeaders().isEmpty()).isFalse(); assertThat(request.getHeaders().get("foo")).isEqualTo("bar"); assertThat(request.getCookies().get("foo")).isEqualTo("bar"); - final Response response = reporter.getFirstTransaction().getContext().getResponse(); + final ResponseImpl response = reporter.getFirstTransaction().getContext().getResponse(); assertThat(response.getHeaders().get("foo")).isEqualTo("bar"); assertThat(response.getHeaders().get("bar")).isEqualTo("baz"); } @@ -340,7 +340,7 @@ public void destroy() { private static class SimpleTestFilter implements Filter { @Nullable - AbstractSpan active = null; + AbstractSpanImpl active = null; @Override public void init(FilterConfig filterConfig) { diff --git a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/AsyncServletTest.java b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/AsyncServletTest.java index 953f4a6287..ebe91e2ce7 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/AsyncServletTest.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/AsyncServletTest.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.servlet; -import co.elastic.apm.agent.impl.context.TransactionContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.eclipse.jetty.servlet.ServletContextHandler; import org.junit.jupiter.api.Test; @@ -98,7 +98,7 @@ private void assertHasOneTransaction(String path, Predicate bodyPredicat assertThat(reporter.getFirstTransaction(500)).isNotNull(); assertThat(reporter.getTransactions()).hasSize(1); assertThat(reporter.getFirstTransaction().getNameAsString()).contains("Servlet").contains("#doGet"); - final TransactionContext context = reporter.getFirstTransaction().getContext(); + final TransactionContextImpl context = reporter.getFirstTransaction().getContext(); assertThat(context.getRequest().getUrl().getPathname()).isEqualTo(path); assertThat(context.getResponse().getStatusCode()).isEqualTo(status); } @@ -108,7 +108,7 @@ public static class AsyncStartServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { final AsyncContext asyncContext = req.startAsync(); - final Transaction transaction = tracer.currentTransaction(); + final TransactionImpl transaction = tracer.currentTransaction(); asyncContext.start(() -> { try { assertThat(tracer.getActive()).isSameAs(transaction); diff --git a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/InitServiceNameInstrumentationTest.java b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/InitServiceNameInstrumentationTest.java index e5414a459e..24ccdcaec4 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/InitServiceNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/InitServiceNameInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.servlet; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.TraceContext; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockFilterConfig; import org.springframework.mock.web.MockServletConfig; @@ -98,7 +98,7 @@ void testFilterInit() { } private void assertServiceInfo() { - TraceContext traceContext = reporter.getFirstTransaction().getTraceContext(); + TraceContextImpl traceContext = reporter.getFirstTransaction().getTraceContext(); assertThat(traceContext.getServiceName()).isEqualTo("service-name-from-manifest"); assertThat(traceContext.getServiceVersion()).isEqualTo("1.42.0"); } diff --git a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ServletInstrumentationTest.java b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ServletInstrumentationTest.java index 255602a91c..cfb953495a 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ServletInstrumentationTest.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ServletInstrumentationTest.java @@ -18,10 +18,10 @@ */ package co.elastic.apm.agent.servlet; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.TracerInternalApiUtils; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.util.ResultUtil; -import co.elastic.apm.agent.impl.transaction.Span; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Transaction; import okhttp3.Response; @@ -125,7 +125,7 @@ void testInclude_verifyThatSpanNameContainsTargetServletPath() throws Exception void testClientError() throws Exception { callServlet(1, "/unknown", "Hello Error!", 404); assertThat(reporter.getSpans().size()).isEqualTo(1); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span.getType()).isEqualTo(SPAN_TYPE); assertThat(span.getSubtype()).isEqualTo(SPAN_SUBTYPE); assertThat(span.getAction()).isEqualTo(ERROR.getAction()); @@ -136,21 +136,21 @@ void testClientError() throws Exception { @Test void testForward_DispatchSpansDisabled() throws Exception { - doReturn(false).when(getConfig().getConfig(CoreConfiguration.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); + doReturn(false).when(getConfig().getConfig(CoreConfigurationImpl.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); callServlet(1, "/forward"); assertThat(reporter.getSpans()).isEmpty(); } @Test void testInclude_DispatchSpansDisabled() throws Exception { - doReturn(false).when(getConfig().getConfig(CoreConfiguration.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); + doReturn(false).when(getConfig().getConfig(CoreConfigurationImpl.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); callServlet(1, "/include"); assertThat(reporter.getSpans()).isEmpty(); } @Test void testClientError_DispatchSpansDisabled() throws Exception { - doReturn(false).when(getConfig().getConfig(CoreConfiguration.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); + doReturn(false).when(getConfig().getConfig(CoreConfigurationImpl.class)).isInstrumentationEnabled(eq(Constants.SERVLET_API_DISPATCH)); callServlet(1, "/unknown", "Hello Error!", 404); assertThat(reporter.getSpans()).isEmpty(); assertThat(reporter.getErrors().size()).isEqualTo(1); @@ -176,7 +176,7 @@ void testServletInstrumentationWithPathInfo() throws Exception { void testForwardWithPathInfo_verifyThatSpanNameContainsOriginalServletPathAndPathInfo() throws Exception { callServlet(1, "/forward/path", "Hello World! /forward-path-info", 200); assertThat(reporter.getSpans().size()).isEqualTo(1); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span.getType()).isEqualTo(SPAN_TYPE); assertThat(span.getSubtype()).isEqualTo(SPAN_SUBTYPE); assertThat(span.getAction()).isEqualTo(FORWARD.getAction()); @@ -187,7 +187,7 @@ void testForwardWithPathInfo_verifyThatSpanNameContainsOriginalServletPathAndPat void testIncludeWithPathInfo_verifyThatSpanNameContainsOriginalServletPathAndPathInfo() throws Exception { callServlet(1, "/include/path", "Hello World! /include-path-info", 200); assertThat(reporter.getSpans().size()).isEqualTo(1); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span.getType()).isEqualTo(SPAN_TYPE); assertThat(span.getSubtype()).isEqualTo(SPAN_SUBTYPE); assertThat(span.getAction()).isEqualTo(INCLUDE.getAction()); diff --git a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ServletTransactionHelperTest.java b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ServletTransactionHelperTest.java index 4e8ca7c636..13dc1d44e3 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ServletTransactionHelperTest.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/ServletTransactionHelperTest.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.MockTracer; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.tracer.util.TransactionNameUtils; import org.junit.jupiter.api.BeforeEach; @@ -53,14 +53,14 @@ void setUp() { @Test void setTransactionNameByServletClass() { - Transaction transaction = new Transaction(MockTracer.create()); + TransactionImpl transaction = new TransactionImpl(MockTracer.create()); TransactionNameUtils.setTransactionNameByServletClass("GET", ServletTransactionHelperTest.class, transaction.getAndOverrideName(PRIORITY_LOW_LEVEL_FRAMEWORK)); assertThat(transaction.getNameAsString()).isEqualTo("ServletTransactionHelperTest#doGet"); } @Test void setTransactionNameByServletClassNullMethod() { - Transaction transaction = new Transaction(MockTracer.create()); + TransactionImpl transaction = new TransactionImpl(MockTracer.create()); TransactionNameUtils.setTransactionNameByServletClass(null, ServletTransactionHelperTest.class, transaction.getAndOverrideName(PRIORITY_LOW_LEVEL_FRAMEWORK)); assertThat(transaction.getNameAsString()).isEqualTo("ServletTransactionHelperTest"); } @@ -86,7 +86,7 @@ void testGroupUrlsOverridesServletName() { WildcardMatcher.valueOf("/foo/bar/*") )).when(webConfig).getUrlGroups(); - Transaction transaction = new Transaction(MockTracer.create()); + TransactionImpl transaction = new TransactionImpl(MockTracer.create()); TransactionNameUtils.setTransactionNameByServletClass("GET", ServletTransactionHelperTest.class, transaction.getAndOverrideName(PRIORITY_LOW_LEVEL_FRAMEWORK)); servletTransactionHelper.applyDefaultTransactionName("GET", "/foo/bar/baz", null, transaction); assertThat(transaction.getNameAsString()).isEqualTo("GET /foo/bar/*"); @@ -94,7 +94,7 @@ void testGroupUrlsOverridesServletName() { @Nonnull private String getTransactionName(String method, String path) { - Transaction transaction = new Transaction(MockTracer.create()); + TransactionImpl transaction = new TransactionImpl(MockTracer.create()); servletTransactionHelper.applyDefaultTransactionName(method, path, null, transaction); return transaction.getNameAsString(); } diff --git a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/TestRequestBodyCapturing.java b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/TestRequestBodyCapturing.java index c4a8f01257..e83b5c491c 100644 --- a/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/TestRequestBodyCapturing.java +++ b/apm-agent-plugins/apm-servlet-plugin/src/test/java/co/elastic/apm/agent/servlet/TestRequestBodyCapturing.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.servlet; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.report.serialize.SerializationConstants; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; import org.apache.commons.lang3.RandomStringUtils; @@ -52,7 +52,7 @@ import java.util.Collections; import java.util.stream.Stream; -import static co.elastic.apm.agent.impl.context.AbstractContext.REDACTED_CONTEXT_STRING; +import static co.elastic.apm.agent.impl.context.AbstractContextImpl.REDACTED_CONTEXT_STRING; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doReturn; @@ -62,7 +62,7 @@ class TestRequestBodyCapturing extends AbstractInstrumentationTest { private InputStreamConsumer streamConsumer; private InputStreamCloser streamCloser; private WebConfiguration webConfiguration; - private CoreConfiguration coreConfiguration; + private CoreConfigurationImpl coreConfiguration; private MockFilterChain filterChain; static Stream streamConsumers() { @@ -86,8 +86,8 @@ static Stream streamConsumers() { @BeforeEach void setUp() { webConfiguration = tracer.getConfig(WebConfiguration.class); - coreConfiguration = tracer.getConfig(CoreConfiguration.class); - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + coreConfiguration = tracer.getConfig(CoreConfigurationImpl.class); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); filterChain = new MockFilterChain(new HttpServlet() { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { @@ -117,7 +117,7 @@ void testReadTextPlain(InputStreamConsumer consumer) throws Exception { @Test void testCaptureBodyOff() throws Exception { - doReturn(CoreConfiguration.EventType.OFF).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.OFF).when(coreConfiguration).getCaptureBody(); executeRequest(filterChain, "foo".getBytes(StandardCharsets.UTF_8), "text/plain"); final Object body = reporter.getFirstTransaction().getContext().getRequest().getBody(); @@ -127,19 +127,19 @@ void testCaptureBodyOff() throws Exception { @ParameterizedTest @ValueSource(strings = {"ALL", "TRANSACTIONS", "ERRORS"}) - void testCaptureBodyNotOff(CoreConfiguration.EventType eventType) throws Exception { + void testCaptureBodyNotOff(CoreConfigurationImpl.EventType eventType) throws Exception { streamCloser = is -> { throw new RuntimeException(); }; doReturn(eventType).when(coreConfiguration).getCaptureBody(); executeRequest(filterChain, "foo".getBytes(StandardCharsets.UTF_8), "text/plain"); - final Transaction transaction = reporter.getFirstTransaction(); + final TransactionImpl transaction = reporter.getFirstTransaction(); final Object body = transaction.getContext().getRequest().getBody(); assertThat(body).isNotNull(); // this is not [REDACTED] in this test as the BodyProcessor is not active in MockReporter assertThat(body.toString()).isEqualTo("foo"); - final ErrorCapture error = reporter.getFirstError(); + final ErrorCaptureImpl error = reporter.getFirstError(); assertThat(error).isNotNull(); assertThat(error.getContext().getRequest().getBody().toString()).isEqualTo("foo"); } @@ -215,7 +215,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I @Test void testTrackPostParams() throws IOException, ServletException { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/foo/bar"); request.addParameter("foo", "bar"); request.addParameter("baz", "qux", "quux"); @@ -230,7 +230,7 @@ void testTrackPostParams() throws IOException, ServletException { @Test void testTrackPostParamsDisabled() throws IOException, ServletException { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); doReturn(Collections.emptyList()).when(webConfiguration).getCaptureContentTypes(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/foo/bar"); request.addParameter("foo", "bar"); @@ -243,7 +243,7 @@ void testTrackPostParamsDisabled() throws IOException, ServletException { @Test void testNoExplicitEndOfInput() { - final Transaction transaction = tracer.startRootTransaction(getClass().getClassLoader()); + final TransactionImpl transaction = tracer.startRootTransaction(getClass().getClassLoader()); transaction.getContext().getRequest().withBodyBuffer(); transaction.end(); assertThat(reporter.getFirstTransaction().getContext().getRequest().getBody().toString()).isEqualTo(""); diff --git a/apm-agent-plugins/apm-sparkjava-plugin/pom.xml b/apm-agent-plugins/apm-sparkjava-plugin/pom.xml index 8a4010b842..d153339d75 100644 --- a/apm-agent-plugins/apm-sparkjava-plugin/pom.xml +++ b/apm-agent-plugins/apm-sparkjava-plugin/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-sparkjava-plugin/src/test/java/co/elastic/apm/agent/sparkjava/RoutesAdviceTest.java b/apm-agent-plugins/apm-sparkjava-plugin/src/test/java/co/elastic/apm/agent/sparkjava/RoutesAdviceTest.java index 7af62208e9..f9ae3d93e5 100644 --- a/apm-agent-plugins/apm-sparkjava-plugin/src/test/java/co/elastic/apm/agent/sparkjava/RoutesAdviceTest.java +++ b/apm-agent-plugins/apm-sparkjava-plugin/src/test/java/co/elastic/apm/agent/sparkjava/RoutesAdviceTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.sparkjava; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import okhttp3.OkHttpClient; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -72,7 +72,7 @@ void testTransactionName() throws IOException { okhttp3.Response response = httpClient.newCall(request).execute(); assertThat(response.body().string()).isEqualTo("bar"); - Transaction transaction = reporter.getFirstTransaction(500); + TransactionImpl transaction = reporter.getFirstTransaction(500); assertThat(transaction.getNameAsString()).isEqualTo("GET /foo/:bar"); assertThat(transaction.getFrameworkName()).isEqualTo("Spark"); assertThat(transaction.getFrameworkVersion()).isEqualTo("2.9.3"); diff --git a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-restclient-test/pom.xml b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-restclient-test/pom.xml index 4ddcd2544c..913eaa4f1a 100644 --- a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-restclient-test/pom.xml +++ b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-restclient-test/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-spring-resttemplate - 1.50.0 + 1.51.0 apm-spring-restclient-test @@ -20,7 +20,7 @@ org.springframework.boot spring-boot-dependencies - 3.2.5 + 3.3.2 pom import diff --git a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/pom.xml b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/pom.xml index 19fb3ad601..8cad64b281 100644 --- a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/pom.xml +++ b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-spring-resttemplate - 1.50.0 + 1.51.0 apm-spring-resttemplate-plugin @@ -23,7 +23,7 @@ org.springframework.boot spring-boot-dependencies - 3.2.5 + 3.3.2 pom import diff --git a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/test/java/co/elastic/apm/agent/resttemplate/FeignClientTest.java b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/test/java/co/elastic/apm/agent/resttemplate/FeignClientTest.java index ae9ebf00d1..f98244285f 100644 --- a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/test/java/co/elastic/apm/agent/resttemplate/FeignClientTest.java +++ b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/test/java/co/elastic/apm/agent/resttemplate/FeignClientTest.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.resttemplate; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.context.Http; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.HttpImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.junit.WireMockRule; import feign.Feign; @@ -46,7 +46,7 @@ public class FeignClientTest extends AbstractInstrumentationTest { @Rule public WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.wireMockConfig().dynamicPort(), false); - private Transaction rootTransaction; + private TransactionImpl rootTransaction; private String baseUrl = null; @@ -78,8 +78,8 @@ public void testThatSpanCreated() { reporter.awaitSpanCount(1); - Span span = reporter.getFirstSpan(); - Http http = span.getContext().getHttp(); + SpanImpl span = reporter.getFirstSpan(); + HttpImpl http = span.getContext().getHttp(); assertThat(span.getNameAsString()).isEqualTo("GET 127.0.0.1"); assertThat(http.getMethod()).isEqualTo("GET"); diff --git a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/test/java/co/elastic/apm/agent/resttemplate/SprintRestTemplateIntegration.java b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/test/java/co/elastic/apm/agent/resttemplate/SprintRestTemplateIntegration.java index 40a099941a..ef90f32d6e 100644 --- a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/test/java/co/elastic/apm/agent/resttemplate/SprintRestTemplateIntegration.java +++ b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-plugin/src/test/java/co/elastic/apm/agent/resttemplate/SprintRestTemplateIntegration.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.resttemplate; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.context.Http; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.HttpImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; import com.github.tomakehurst.wiremock.junit.WireMockRule; import org.junit.After; @@ -42,7 +42,7 @@ public class SprintRestTemplateIntegration extends AbstractInstrumentationTest { private final RestTemplate restTemplate; - private Transaction rootTransaction; + private TransactionImpl rootTransaction; private final boolean expectSpan; @@ -83,8 +83,8 @@ public void getRoot() { } else { reporter.awaitSpanCount(1); - Span span = reporter.getFirstSpan(); - Http http = span.getContext().getHttp(); + SpanImpl span = reporter.getFirstSpan(); + HttpImpl http = span.getContext().getHttp(); assertThat(http.getMethod()).isEqualTo("GET"); assertThat(http.getUrl().toString()).isEqualTo(url); } diff --git a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-test/pom.xml b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-test/pom.xml index 2ef7c70d08..01d9ddd8bb 100644 --- a/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-test/pom.xml +++ b/apm-agent-plugins/apm-spring-resttemplate/apm-spring-resttemplate-test/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-spring-resttemplate - 1.50.0 + 1.51.0 apm-spring-resttemplate-test diff --git a/apm-agent-plugins/apm-spring-resttemplate/pom.xml b/apm-agent-plugins/apm-spring-resttemplate/pom.xml index dab8f7b927..e4fca8d718 100644 --- a/apm-agent-plugins/apm-spring-resttemplate/pom.xml +++ b/apm-agent-plugins/apm-spring-resttemplate/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-agent-plugins - 1.50.0 + 1.51.0 apm-spring-resttemplate diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml index a1db679e10..e0b395c222 100755 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-spring-webflux - 1.50.0 + 1.51.0 apm-spring-webclient-plugin diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientExchangeFunctionInstrumentation.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientExchangeFunctionInstrumentation.java index 54e651ae9a..6ae015d439 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientExchangeFunctionInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webclient-plugin/src/main/java/co/elastic/apm/agent/springwebclient/WebClientExchangeFunctionInstrumentation.java @@ -20,11 +20,10 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; -import co.elastic.apm.agent.tracer.AbstractSpan; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.Tracer; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument; import net.bytebuddy.description.NamedElement; @@ -86,7 +85,7 @@ public static Object[] onBefore(@Advice.Argument(0) ClientRequest clientRequest) span.activate(); } - ElasticContext toPropagate = tracer.currentContext(); + TraceState toPropagate = tracer.currentContext(); if (!toPropagate.isEmpty()) { ClientRequest.Builder builder = ClientRequest.from(clientRequest); toPropagate.propagateContext(builder, WebClientRequestHeaderSetter.INSTANCE, null); diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-common-spring5/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-common-spring5/pom.xml index 5ec0534412..709fab3dec 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-common-spring5/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-common-spring5/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm apm-spring-webflux - 1.50.0 + 1.51.0 apm-spring-webflux-common-spring5 diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-common/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-common/pom.xml index 391ceebcbe..c74d903e43 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-common/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-common/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm apm-spring-webflux - 1.50.0 + 1.51.0 apm-spring-webflux-common diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml index 27ea35261f..84d32fc284 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-spring-webflux - 1.50.0 + 1.51.0 apm-spring-webflux-plugin diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml index c6a16bfe7f..b67b4f557f 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-spring-webflux - 1.50.0 + 1.51.0 apm-spring-webflux-spring5 diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/main/java/co/elastic/apm/agent/springwebflux/TransactionAwareSubscriber.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/main/java/co/elastic/apm/agent/springwebflux/TransactionAwareSubscriber.java index 3747089052..e3bc75bda2 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/main/java/co/elastic/apm/agent/springwebflux/TransactionAwareSubscriber.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/main/java/co/elastic/apm/agent/springwebflux/TransactionAwareSubscriber.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Transaction; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; @@ -72,7 +72,7 @@ class TransactionAwareSubscriber implements CoreSubscriber, Subscription { // store transaction into subscriber context it can be looked-up by reactor when the transaction // is not already active in current thread. - this.context = subscriber.currentContext().put(ElasticContext.class, transaction); + this.context = subscriber.currentContext().put(TraceState.class, transaction); } @Override diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/AbstractServerInstrumentationTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/AbstractServerInstrumentationTest.java index 7b75f987a3..e27585baad 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/AbstractServerInstrumentationTest.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/AbstractServerInstrumentationTest.java @@ -19,12 +19,12 @@ package co.elastic.apm.agent.springwebflux; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.Url; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.context.RequestImpl; +import co.elastic.apm.agent.impl.context.UrlImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.springwebflux.testapp.GreetingWebClient; import co.elastic.apm.agent.springwebflux.testapp.WebFluxApplication; @@ -121,9 +121,9 @@ private void hello(boolean expectHeaders) { String expectedName = client.useFunctionalEndpoint() ? "GET /functional/hello" : "GreetingAnnotated#getHello"; - Transaction transaction = checkTransaction(getFirstTransaction(), expectedName, "GET", 200); + TransactionImpl transaction = checkTransaction(getFirstTransaction(), expectedName, "GET", 200); - Request request = transaction.getContext().getRequest(); + RequestImpl request = transaction.getContext().getRequest(); checkUrl(transaction, "/hello"); @@ -160,7 +160,7 @@ private void hello(boolean expectHeaders) { @Test void headerCaptureDisabled() { - CoreConfiguration coreConfig = getConfig().getConfig(CoreConfiguration.class); + CoreConfigurationImpl coreConfig = getConfig().getConfig(CoreConfigurationImpl.class); doReturn(false).when(coreConfig).isCaptureHeaders(); hello(false); @@ -172,7 +172,7 @@ void dispatch404() { .expectErrorMatches(expectClientError(404)) .verify(); - Transaction transaction = checkTransaction(getFirstTransaction(), "GET unknown route", "GET", 404); + TransactionImpl transaction = checkTransaction(getFirstTransaction(), "GET unknown route", "GET", 404); assertThat(transaction.getResult()).isEqualTo("HTTP 4xx"); assertThat(transaction.getContext().getRequest().getMethod()).isEqualTo("GET"); @@ -189,7 +189,7 @@ void dispatch404_usePathAsName() { .expectErrorMatches(expectClientError(404)) .verify(); - Transaction transaction = checkTransaction(getFirstTransaction(), "GET /*/error-404", "GET", 404); + TransactionImpl transaction = checkTransaction(getFirstTransaction(), "GET /*/error-404", "GET", 404); assertThat(transaction.getResult()).isEqualTo("HTTP 4xx"); assertThat(transaction.getContext().getRequest().getMethod()).isEqualTo("GET"); @@ -240,7 +240,7 @@ void transactionDuration() { .verifyComplete(); String expectedName = client.useFunctionalEndpoint() ? "GET /functional/duration" : "GreetingAnnotated#duration"; - Transaction transaction = checkTransaction(getFirstTransaction(), expectedName, "GET", 200); + TransactionImpl transaction = checkTransaction(getFirstTransaction(), expectedName, "GET", 200); assertThat(transaction.getDurationMs()) .isCloseTo(duration * 1d, Offset.offset(duration / 2d)); @@ -257,7 +257,7 @@ void shouldInstrumentPathWithParameters() { String expectedName = client.useFunctionalEndpoint() ? "GET " + client.getPathPrefix() + "/with-parameters/{id}" : "GreetingAnnotated#withParameters"; - Transaction transaction = checkTransaction(getFirstTransaction(), expectedName, "GET", 200); + TransactionImpl transaction = checkTransaction(getFirstTransaction(), expectedName, "GET", 200); checkUrl(transaction, "/with-parameters/1234"); } @@ -407,7 +407,7 @@ private static Predicate> checkSSE(final int index) { } private void checkChildSpans(String expectedName, String pathAndQuery) { - Transaction transaction = checkTransaction(getFirstTransaction(), expectedName, "GET", 200); + TransactionImpl transaction = checkTransaction(getFirstTransaction(), expectedName, "GET", 200); checkUrl(transaction, pathAndQuery); @@ -417,8 +417,8 @@ private void checkChildSpans(String expectedName, String pathAndQuery) { }); } - static void checkUrl(GreetingWebClient client, Transaction transaction, String pathAndQuery) { - Url url = transaction.getContext().getRequest().getUrl(); + static void checkUrl(GreetingWebClient client, TransactionImpl transaction, String pathAndQuery) { + UrlImpl url = transaction.getContext().getRequest().getUrl(); assertThat(url.getProtocol()).isEqualTo("http"); assertThat(url.getHostname()).isEqualTo("localhost"); @@ -439,19 +439,19 @@ static void checkUrl(GreetingWebClient client, Transaction transaction, String p .isEqualTo(String.format("http://localhost:%d%s%s", client.getPort(), client.getPathPrefix(), pathAndQuery)); } - private void checkUrl(Transaction transaction, String pathAndQuery) { + private void checkUrl(TransactionImpl transaction, String pathAndQuery) { checkUrl(client, transaction, pathAndQuery); } - protected Transaction getFirstTransaction() { + protected TransactionImpl getFirstTransaction() { return reporter.getFirstTransaction(200); } - protected ErrorCapture getFirstError() { + protected ErrorCaptureImpl getFirstError() { return reporter.getFirstError(200); } - static Transaction checkTransaction(Transaction transaction, String expectedName, String expectedMethod, int expectedStatus) { + static TransactionImpl checkTransaction(TransactionImpl transaction, String expectedName, String expectedMethod, int expectedStatus) { assertThat(transaction.getType()).isEqualTo("request"); assertThat(transaction.getNameAsString()).isEqualTo(expectedName); diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/ServletContainerTest.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/ServletContainerTest.java index 3ce767dcec..f1c1c75e9c 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/ServletContainerTest.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-spring5/src/test/java/co/elastic/apm/agent/springwebflux/ServletContainerTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.springwebflux; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.springwebflux.testapp.GreetingWebClient; import co.elastic.apm.agent.springwebflux.testapp.WebFluxApplication; import org.junit.jupiter.api.AfterAll; @@ -71,7 +71,7 @@ void shouldOnlyCreateOneTransaction() throws InterruptedException { .verifyComplete(); // at least one transaction expected - Transaction transaction = reporter.getFirstTransaction(200); + TransactionImpl transaction = reporter.getFirstTransaction(200); // transaction naming should be set by webflux instrumentation AbstractServerInstrumentationTest.checkTransaction(transaction, "GET /functional/with-parameters/{id}", "GET", 200); diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/pom.xml b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/pom.xml index 58db150146..3ee5822e47 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-spring-webflux - 1.50.0 + 1.51.0 apm-spring-webflux-testapp @@ -37,6 +37,12 @@ + + ${project.groupId} + apm-agent-core + ${project.version} + + org.springframework.boot spring-boot-starter-webflux @@ -96,7 +102,7 @@ org.springframework.boot spring-boot-maven-plugin - 3.2.0 + 3.3.0 co.elastic.apm.agent.springwebflux.testapp.WebFluxApplication diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingAnnotated.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingAnnotated.java index 3ce7f49bc5..338cd24982 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingAnnotated.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingAnnotated.java @@ -19,13 +19,12 @@ package co.elastic.apm.agent.springwebflux.testapp; import co.elastic.apm.agent.impl.ElasticApmTracer; +import co.elastic.apm.agent.impl.transaction.IdImpl; import co.elastic.apm.agent.tracer.AbstractSpan; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Id; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.sdk.logging.Logger; import co.elastic.apm.agent.sdk.logging.LoggerFactory; -import co.elastic.apm.agent.tracer.GlobalTracer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -171,13 +170,13 @@ public Mono customTransactionName() { log.debug("enter customTransactionName"); try { - Id transactionId = null; + IdImpl transactionId = null; if (!GlobalTracer.isNoop()) { // Transaction should be active, even if we are outside of Mono/Flux execution // In practice, it's called after onSubscribe and before onNext, thus the active context is not provided // by reactor plugin, but only by the webflux plugin that keeps the transaction active. ElasticApmTracer tracer = GlobalTracer.get().require(ElasticApmTracer.class); - Transaction transaction = Objects.requireNonNull(tracer.currentTransaction(), "active transaction is required"); + TransactionImpl transaction = Objects.requireNonNull(tracer.currentTransaction(), "active transaction is required"); // This mimics setting the name through the public API. We cannot use the public API if we want to test span recycling transaction.withName("user-provided-name", AbstractSpan.PRIORITY_USER_SUPPLIED); transactionId = transaction.getTraceContext().getId(); diff --git a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingFunctional.java b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingFunctional.java index 2ade37aa58..d58e116347 100644 --- a/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingFunctional.java +++ b/apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-testapp/src/main/java/co/elastic/apm/agent/springwebflux/testapp/GreetingFunctional.java @@ -21,9 +21,8 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.tracer.AbstractSpan; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.Id; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.tracer.GlobalTracer; +import co.elastic.apm.agent.impl.transaction.IdImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; @@ -83,10 +82,10 @@ public RouterFunction route(GreetingHandler greetingHandler) { .GET("/functional/duration", accept(MediaType.TEXT_PLAIN), request -> response(greetingHandler.duration(getDuration(request)))) // custom transaction name set through API .GET("/functional/custom-transaction-name", accept(MediaType.TEXT_PLAIN), request -> { - Id transactionId = null; + IdImpl transactionId = null; if (!GlobalTracer.isNoop()) { ElasticApmTracer tracer = GlobalTracer.get().require(ElasticApmTracer.class); - Transaction transaction = Objects.requireNonNull(tracer.currentTransaction(), "active transaction is required"); + TransactionImpl transaction = Objects.requireNonNull(tracer.currentTransaction(), "active transaction is required"); // This mimics setting the name through the public API. We cannot use the public API if we want to test span recycling transaction.withName("user-provided-name", AbstractSpan.PRIORITY_USER_SUPPLIED); transactionId = transaction.getTraceContext().getId(); diff --git a/apm-agent-plugins/apm-spring-webflux/pom.xml b/apm-agent-plugins/apm-spring-webflux/pom.xml index 2eecccba34..1adb5c4be6 100644 --- a/apm-agent-plugins/apm-spring-webflux/pom.xml +++ b/apm-agent-plugins/apm-spring-webflux/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-agent-plugins - 1.50.0 + 1.51.0 apm-spring-webflux @@ -18,7 +18,7 @@ 2.7.16 - 3.2.5 + 3.3.2 @@ -31,12 +31,6 @@ - - ${project.groupId} - apm-agent-core - ${project.version} - - co.elastic.apm diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/pom.xml b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/pom.xml index 4c60ded776..60b3f76d98 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/pom.xml +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-plugin/pom.xml @@ -5,7 +5,7 @@ apm-spring-webmvc co.elastic.apm - 1.50.0 + 1.51.0 apm-spring-webmvc-plugin @@ -22,7 +22,7 @@ org.springframework.boot spring-boot-dependencies - 3.2.5 + 3.3.2 pom import diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/pom.xml b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/pom.xml index 02ef8122d9..222383f9bc 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/pom.xml +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/pom.xml @@ -5,7 +5,7 @@ apm-spring-webmvc co.elastic.apm - 1.50.0 + 1.51.0 apm-spring-webmvc-spring5 diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/main/java/co/elastic/apm/agent/springwebmvc/AbstractSpringServiceNameInstrumentation.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/main/java/co/elastic/apm/agent/springwebmvc/AbstractSpringServiceNameInstrumentation.java index e38a5491f1..649047e62c 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/main/java/co/elastic/apm/agent/springwebmvc/AbstractSpringServiceNameInstrumentation.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/main/java/co/elastic/apm/agent/springwebmvc/AbstractSpringServiceNameInstrumentation.java @@ -18,7 +18,6 @@ */ package co.elastic.apm.agent.springwebmvc; -import co.elastic.apm.agent.tracer.service.ServiceAwareTracer; import co.elastic.apm.agent.tracer.service.ServiceInfo; import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; import co.elastic.apm.agent.servlet.Constants; @@ -76,14 +75,9 @@ public static class Helper { public static void detectSpringServiceName(ServletContextAdapter adapter, WebApplicationContext applicationContext, @Nullable ServletContext servletContext) { - ServiceAwareTracer serviceAwareTracer = tracer.probe(ServiceAwareTracer.class); - if (serviceAwareTracer == null) { - return; - } - // avoid having two service names for a standalone jar // one based on Implementation-Title and one based on spring.application.name - if (!serviceAwareTracer.autoDetectedServiceInfo().isMultiServiceContainer()) { + if (!tracer.autoDetectedServiceInfo().isMultiServiceContainer()) { return; } @@ -105,7 +99,7 @@ public static void detectSpringServiceName(ServletContextAdapte ServiceInfo fromSpringApplicationNameProperty = ServiceInfo.of(applicationContext.getEnvironment().getProperty("spring.application.name", "")); ServiceInfo fromApplicationContextApplicationName = ServiceInfo.of(removeLeadingSlash(applicationContext.getApplicationName())); - serviceAwareTracer.setServiceInfoForClassLoader(classLoader, fromSpringApplicationNameProperty + tracer.setServiceInfoForClassLoader(classLoader, fromSpringApplicationNameProperty .withFallback(fromServletContext) .withFallback(fromApplicationContextApplicationName)); } diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/AbstractSpringTransactionNameInstrumentationTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/AbstractSpringTransactionNameInstrumentationTest.java index b2d167a248..b94f52300c 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/AbstractSpringTransactionNameInstrumentationTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/AbstractSpringTransactionNameInstrumentationTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.springwebmvc; import co.elastic.apm.agent.AbstractInstrumentationTest; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -192,7 +192,7 @@ public static class TestController { @GetMapping("/test") public CharSequence test() { - Transaction currentTransaction = tracer.currentTransaction(); + TransactionImpl currentTransaction = tracer.currentTransaction(); assertThat(currentTransaction).isNotNull(); return currentTransaction.getNameAsString(); } diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationTest.java index 4ddb38e1bd..bd11adf470 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.springwebmvc.exception; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -56,7 +56,7 @@ protected void assertExceptionCapture(Class exceptionClazz, MockHttpServletRespo protected void assertExceptionCapture(Class exceptionClazz, MockHttpServletResponse response, int statusCode, String responseContent, String exceptionMessageContains, String childSpanNameContains) throws UnsupportedEncodingException { assertThat(reporter.getTransactions()).hasSize(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); if (childSpanNameContains == null) { assertThat(reporter.getSpans()).isEmpty(); } else { diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationWithExceptionResolverTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationWithExceptionResolverTest.java index b3774107ed..57f3d4b2d6 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationWithExceptionResolverTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/AbstractExceptionHandlerInstrumentationWithExceptionResolverTest.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.springwebmvc.exception; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.springwebmvc.exception.testapp.exception_resolver.ExceptionResolverController; import co.elastic.apm.agent.springwebmvc.exception.testapp.exception_resolver.ExceptionResolverRuntimeException; import org.junit.jupiter.params.ParameterizedTest; @@ -48,7 +48,7 @@ public abstract class AbstractExceptionHandlerInstrumentationWithExceptionResolv @ParameterizedTest @ValueSource(booleans = {true,false}) public void testCallApiWithExceptionThrown(boolean useAttributeBasedPropagation) throws Exception { - CoreConfiguration coreConfig = config.getConfig(CoreConfiguration.class); + CoreConfigurationImpl coreConfig = config.getConfig(CoreConfigurationImpl.class); doReturn(useAttributeBasedPropagation).when(coreConfig).isUseServletAttributesForExceptionPropagation(); ResultActions resultActions = this.mockMvc.perform(get("/exception-resolver/throw-exception")); diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring5ExceptionHandlerInstrumentationWithExceptionHandlerTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring5ExceptionHandlerInstrumentationWithExceptionHandlerTest.java index 3773281f2f..cc9f10c51a 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring5ExceptionHandlerInstrumentationWithExceptionHandlerTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring5ExceptionHandlerInstrumentationWithExceptionHandlerTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.springwebmvc.exception; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.springwebmvc.exception.testapp.exception_handler.ExceptionHandlerController; import co.elastic.apm.agent.springwebmvc.exception.testapp.exception_handler.ExceptionHandlerRuntimeException; import co.elastic.apm.agent.springwebmvc.exception.testapp.exception_handler.ExceptionHandlerRuntimeException200; @@ -51,7 +51,7 @@ public void testExceptionCapture() throws Exception { @Test public void testExceptionCapture_IgnoreException() throws Exception { doReturn(List.of(WildcardMatcher.valueOf("co.elastic.apm.agent.springwebmvc.exception.testapp.exception_handler.ExceptionHandlerRuntimeException"))) - .when(config.getConfig(CoreConfiguration.class)).getIgnoreExceptions(); + .when(config.getConfig(CoreConfigurationImpl.class)).getIgnoreExceptions(); this.mockMvc.perform(get("/exception-handler/throw-exception")); diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring5ExceptionHandlerInstrumentationWithGlobalAdviceTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring5ExceptionHandlerInstrumentationWithGlobalAdviceTest.java index bb8172a14e..9c7f482683 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring5ExceptionHandlerInstrumentationWithGlobalAdviceTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/exception/Spring5ExceptionHandlerInstrumentationWithGlobalAdviceTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.springwebmvc.exception; import co.elastic.apm.agent.common.util.WildcardMatcher; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.springwebmvc.exception.testapp.controller_advice.ControllerAdviceController; import co.elastic.apm.agent.springwebmvc.exception.testapp.controller_advice.ControllerAdviceRuntimeException; import co.elastic.apm.agent.springwebmvc.exception.testapp.controller_advice.ControllerAdviceRuntimeException200; @@ -56,7 +56,7 @@ public void testExceptionCaptureWithGlobalControllerAdvice() throws Exception { public void testExceptionCaptureWithGlobalControllerAdvice_IgnoreExceptions() throws Exception { doReturn(List.of(WildcardMatcher.valueOf("co.elastic.apm.agent.springwebmvc.exception.testapp.controller_advice.ControllerAdviceRuntimeException"))) - .when(config.getConfig(CoreConfiguration.class)).getIgnoreExceptions(); + .when(config.getConfig(CoreConfigurationImpl.class)).getIgnoreExceptions(); this.mockMvc.perform(get("/controller-advice/throw-exception")); diff --git a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/template/AbstractViewRenderingInstrumentationTest.java b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/template/AbstractViewRenderingInstrumentationTest.java index e59d3f362b..2262ca30cf 100644 --- a/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/template/AbstractViewRenderingInstrumentationTest.java +++ b/apm-agent-plugins/apm-spring-webmvc/apm-spring-webmvc-spring5/src/test/java/co/elastic/apm/agent/springwebmvc/template/AbstractViewRenderingInstrumentationTest.java @@ -19,7 +19,7 @@ package co.elastic.apm.agent.springwebmvc.template; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; @@ -57,7 +57,7 @@ void verifySpanCapture(String spanSubType, String spanSuffix, MockHttpServletRes String responseString = response.getContentAsString(); assertEquals(messageContent, responseString.trim().replaceAll("\r\n", "\n")); assertEquals(1, reporter.getSpans().size()); - Span firstSpan = reporter.getSpans().get(0); + SpanImpl firstSpan = reporter.getSpans().get(0); assertEquals("template", firstSpan.getType()); assertEquals(spanSubType, firstSpan.getSubtype()); assertEquals("render", firstSpan.getAction()); diff --git a/apm-agent-plugins/apm-spring-webmvc/pom.xml b/apm-agent-plugins/apm-spring-webmvc/pom.xml index 66f4c6e4eb..f9e77d6ec7 100644 --- a/apm-agent-plugins/apm-spring-webmvc/pom.xml +++ b/apm-agent-plugins/apm-spring-webmvc/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 @@ -29,7 +29,7 @@ org.springframework.boot spring-boot-dependencies - 3.2.5 + 3.3.2 pom import diff --git a/apm-agent-plugins/apm-struts-plugin/pom.xml b/apm-agent-plugins/apm-struts-plugin/pom.xml index 8b4017498c..980c347b79 100644 --- a/apm-agent-plugins/apm-struts-plugin/pom.xml +++ b/apm-agent-plugins/apm-struts-plugin/pom.xml @@ -3,7 +3,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ActionProxyAdvice.java b/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ActionProxyAdvice.java index 7de8cfbc8d..9f2ca4390b 100644 --- a/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ActionProxyAdvice.java +++ b/apm-agent-plugins/apm-struts-plugin/src/main/java/co/elastic/apm/agent/struts/ActionProxyAdvice.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.struts; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; @@ -38,7 +38,7 @@ public class ActionProxyAdvice { @Nullable public static Object onEnterExecute(@Advice.This ActionProxy actionProxy) { - ElasticContext activeContext = GlobalTracer.get().currentContext(); + TraceState activeContext = GlobalTracer.get().currentContext(); Transaction transaction = activeContext.getTransaction(); if (transaction == null) { return null; diff --git a/apm-agent-plugins/apm-struts-plugin/src/test/java/co/elastic/apm/agent/struts/ActionProxyAdviceTest.java b/apm-agent-plugins/apm-struts-plugin/src/test/java/co/elastic/apm/agent/struts/ActionProxyAdviceTest.java index 625aeebf14..4d1a655880 100644 --- a/apm-agent-plugins/apm-struts-plugin/src/test/java/co/elastic/apm/agent/struts/ActionProxyAdviceTest.java +++ b/apm-agent-plugins/apm-struts-plugin/src/test/java/co/elastic/apm/agent/struts/ActionProxyAdviceTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.struts; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import com.opensymphony.xwork2.ActionSupport; import org.apache.struts2.StrutsTestCase; @@ -55,7 +55,7 @@ public synchronized void tearDown() throws Exception { } public void testExecuteAction() throws ServletException, UnsupportedEncodingException { - Transaction transaction = AbstractInstrumentationTest.getTracer().startRootTransaction(null).withName("struts-test").activate(); + TransactionImpl transaction = AbstractInstrumentationTest.getTracer().startRootTransaction(null).withName("struts-test").activate(); executeAction("/test1"); transaction.end(); @@ -63,7 +63,7 @@ public void testExecuteAction() throws ServletException, UnsupportedEncodingExce } public void testExecuteCustomMethodAction() throws ServletException, UnsupportedEncodingException { - Transaction transaction = AbstractInstrumentationTest.getTracer().startRootTransaction(null).withName("struts-test").activate(); + TransactionImpl transaction = AbstractInstrumentationTest.getTracer().startRootTransaction(null).withName("struts-test").activate(); executeAction("/test2"); transaction.end(); @@ -71,12 +71,12 @@ public void testExecuteCustomMethodAction() throws ServletException, Unsupported } public void testChainedAction() throws ServletException, UnsupportedEncodingException { - Transaction transaction = AbstractInstrumentationTest.getTracer().startRootTransaction(null).withName("struts-test").activate(); + TransactionImpl transaction = AbstractInstrumentationTest.getTracer().startRootTransaction(null).withName("struts-test").activate(); executeAction("/test3"); transaction.end(); assertThat(AbstractInstrumentationTest.getReporter().getFirstTransaction().getNameAsString()).isEqualTo("TestAction#chainedAction"); - Span span = AbstractInstrumentationTest.getReporter().getFirstSpan(); + SpanImpl span = AbstractInstrumentationTest.getReporter().getFirstSpan(); assertThat(span.getNameAsString()).isEqualTo("TestAction#execute"); assertThat(span.getType()).isEqualTo("app"); assertThat(span.getSubtype()).isEqualTo("internal"); diff --git a/apm-agent-plugins/apm-urlconnection-plugin/pom.xml b/apm-agent-plugins/apm-urlconnection-plugin/pom.xml index 275a1f0e90..94ddfc5991 100644 --- a/apm-agent-plugins/apm-urlconnection-plugin/pom.xml +++ b/apm-agent-plugins/apm-urlconnection-plugin/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-urlconnection-plugin diff --git a/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentation.java b/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentation.java index 85155b989f..a7ff424f58 100644 --- a/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentation.java +++ b/apm-agent-plugins/apm-urlconnection-plugin/src/main/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentation.java @@ -24,11 +24,10 @@ import co.elastic.apm.agent.sdk.state.GlobalState; import co.elastic.apm.agent.tracer.AbstractSpan; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; import co.elastic.apm.agent.tracer.Tracer; -import co.elastic.apm.agent.tracer.dispatch.HeaderUtils; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.NamedElement; @@ -86,7 +85,7 @@ public static Object enter(@Advice.This HttpURLConnection thiz, boolean actuallyConnected = connected || responseCode != -1; boolean isNestedCall = callDepth.isNestedCallAndIncrement(); - ElasticContext activeContext = tracer.currentContext(); + TraceState activeContext = tracer.currentContext(); AbstractSpan parentSpan = activeContext.getSpan(); Span span = null; if (parentSpan != null) { diff --git a/apm-agent-plugins/apm-urlconnection-plugin/src/test/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentationTest.java b/apm-agent-plugins/apm-urlconnection-plugin/src/test/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentationTest.java index 1200f0ad9a..467838f64d 100644 --- a/apm-agent-plugins/apm-urlconnection-plugin/src/test/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentationTest.java +++ b/apm-agent-plugins/apm-urlconnection-plugin/src/test/java/co/elastic/apm/agent/urlconnection/HttpUrlConnectionInstrumentationTest.java @@ -19,9 +19,9 @@ package co.elastic.apm.agent.urlconnection; import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; -import co.elastic.apm.agent.impl.context.Http; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.context.HttpImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import co.elastic.apm.agent.tracer.Scope; import org.junit.Ignore; import org.junit.Test; @@ -48,7 +48,7 @@ protected void performGet(String path) throws Exception { public void testEndInDifferentThread() throws Exception { final HttpURLConnection urlConnection = (HttpURLConnection) new URL(getBaseUrl() + "/").openConnection(); urlConnection.connect(); - AbstractSpan active = tracer.getActive(); + AbstractSpanImpl active = tracer.getActive(); final Thread thread = new Thread(() -> { try (Scope scope = active.activateInScope()) { urlConnection.getInputStream(); @@ -148,10 +148,10 @@ public void testGetResponseCodeWithUnhandledException() { assertThat(reporter.getFirstSpan(500)).isNotNull(); assertThat(reporter.getSpans()).hasSize(1); - Span span = reporter.getSpans().get(0); + SpanImpl span = reporter.getSpans().get(0); assertThat(span.getNameAsString()).isEqualTo("GET unknown"); - Http http = span.getContext().getHttp(); + HttpImpl http = span.getContext().getHttp(); assertThat(http.getStatusCode()).isEqualTo(0); assertThat(http.getUrl().toString()).isEqualTo("http://unknown"); } diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/pom.xml b/apm-agent-plugins/apm-vertx/apm-vertx-common/pom.xml index 8ced802e8c..22a47b31e2 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/pom.xml +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/pom.xml @@ -5,7 +5,7 @@ apm-vertx co.elastic.apm - 1.50.0 + 1.51.0 apm-vertx-common diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebClientHelper.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebClientHelper.java index ab306a28fb..f24537b77d 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebClientHelper.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/AbstractVertxWebClientHelper.java @@ -20,7 +20,7 @@ import co.elastic.apm.agent.httpclient.HttpClientHelper; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.Span; @@ -51,8 +51,8 @@ public void setHeader(String headerName, String headerValue, HttpClientRequest c } } - public void startSpanOrFollowRedirect(ElasticContext activeContext, HttpContext httpContext, HttpClientRequest httpRequest) { - ElasticContext existingPropagationCtx = httpContext.get(PROPAGATION_CONTEXT_KEY); + public void startSpanOrFollowRedirect(TraceState activeContext, HttpContext httpContext, HttpClientRequest httpRequest) { + TraceState existingPropagationCtx = httpContext.get(PROPAGATION_CONTEXT_KEY); if (existingPropagationCtx != null) { // Repropagate headers in case of redirects @@ -65,7 +65,7 @@ public void startSpanOrFollowRedirect(ElasticContext activeContext, HttpConte URI requestUri = URI.create(httpRequest.absoluteURI()); Span span = HttpClientHelper.startHttpClientSpan(activeContext, getMethod(httpRequest), requestUri, null); - ElasticContext toPropagate = activeContext; + TraceState toPropagate = activeContext; if (span != null) { //no need to increment references of the span, the span will be kept alive by the incrementReferences() on the context below httpContext.set(WEB_CLIENT_SPAN_KEY, span); @@ -80,7 +80,7 @@ public void startSpanOrFollowRedirect(ElasticContext activeContext, HttpConte } public void followRedirect(HttpContext httpContext, HttpClientRequest httpRequest) { - ElasticContext existingPropagationCtx = httpContext.get(PROPAGATION_CONTEXT_KEY); + TraceState existingPropagationCtx = httpContext.get(PROPAGATION_CONTEXT_KEY); if (existingPropagationCtx != null) { existingPropagationCtx.propagateContext(httpRequest, HeaderSetter.INSTANCE, null); } @@ -96,7 +96,7 @@ public void failSpan(HttpContext httpContext, Throwable thrown, @Nullable Abs private void finalizeSpan(HttpContext httpContext, int statusCode, @Nullable Throwable thrown, @Nullable AbstractSpan parent) { Span span = httpContext.get(WEB_CLIENT_SPAN_KEY); - ElasticContext propagationCtx = httpContext.get(PROPAGATION_CONTEXT_KEY); + TraceState propagationCtx = httpContext.get(PROPAGATION_CONTEXT_KEY); if (propagationCtx != null) { // Setting to null removes from the attributes map httpContext.set(WEB_CLIENT_SPAN_KEY, null); diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/GenericHandlerWrapper.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/GenericHandlerWrapper.java index 9463669629..5fc975f7fc 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/GenericHandlerWrapper.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/GenericHandlerWrapper.java @@ -19,16 +19,16 @@ package co.elastic.apm.agent.vertx; import co.elastic.apm.agent.tracer.AbstractSpan; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import io.vertx.core.Handler; public class GenericHandlerWrapper implements Handler { protected final Handler actualHandler; - private final ElasticContext parentContext; + private final TraceState parentContext; - public GenericHandlerWrapper(ElasticContext parentContext, Handler actualHandler) { + public GenericHandlerWrapper(TraceState parentContext, Handler actualHandler) { this.parentContext = parentContext; this.actualHandler = actualHandler; parentContext.incrementReferences(); @@ -52,7 +52,7 @@ public void handle(T event) { } public static Handler wrapIfNonEmptyContext(Handler handler) { - ElasticContext currentContext = GlobalTracer.get().currentContext(); + TraceState currentContext = GlobalTracer.get().currentContext(); if (!currentContext.isEmpty()) { handler = new GenericHandlerWrapper<>(currentContext, handler); diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/SetTimerWrapper.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/SetTimerWrapper.java index be3b30492c..72b827c46b 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/SetTimerWrapper.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/main/java/co/elastic/apm/agent/vertx/SetTimerWrapper.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.vertx; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.GlobalTracer; import io.vertx.core.Handler; @@ -39,12 +39,12 @@ public void handle(Long event) { } } - public SetTimerWrapper(ElasticContext parentContext, Handler actualHandler) { + public SetTimerWrapper(TraceState parentContext, Handler actualHandler) { super(parentContext, actualHandler); } public static Handler wrapTimerIfNonEmptyContext(Handler handler) { - ElasticContext current = GlobalTracer.get().currentContext(); + TraceState current = GlobalTracer.get().currentContext(); // do not wrap if there is no parent span or if we are in the recursive context of the same type of timer if (!current.isEmpty() && !handler.getClass().getName().equals(activeTimerHandlerPerThread.get())) { diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/AbstractVertxWebTest.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/AbstractVertxWebTest.java index b666302773..b18ef160a0 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/AbstractVertxWebTest.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/AbstractVertxWebTest.java @@ -19,10 +19,10 @@ package co.elastic.apm.agent.vertx.helper; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.configuration.CoreConfiguration; -import co.elastic.apm.agent.impl.context.TransactionContext; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import io.vertx.ext.web.Router; import io.vertx.junit5.VertxTestContext; import okhttp3.Response; @@ -49,7 +49,7 @@ public abstract class AbstractVertxWebTest extends AbstractInstrumentationTest { protected static final String CALL_ON_CONTEXT = "on-context"; protected WebConfiguration webConfiguration; - protected CoreConfiguration coreConfiguration; + protected CoreConfigurationImpl coreConfiguration; @BeforeAll static void setCache() throws IOException { @@ -60,7 +60,7 @@ static void setCache() throws IOException { @BeforeEach void setUp() { webConfiguration = tracer.getConfig(WebConfiguration.class); - coreConfiguration = tracer.getConfig(CoreConfiguration.class); + coreConfiguration = tracer.getConfig(CoreConfigurationImpl.class); } @Nullable @@ -124,11 +124,11 @@ protected void expectTransaction(Response response, String path, String expected reporter.getFirstTransaction(500); assertThat(reporter.getTransactions() .stream() - .map(AbstractSpan::getNameAsString) + .map(AbstractSpanImpl::getNameAsString) .distinct()) .describedAs("transaction service name should be inherited from test class name") .containsExactly(expectedTransactionName); - TransactionContext context = reporter.getFirstTransaction().getContext(); + TransactionContextImpl context = reporter.getFirstTransaction().getContext(); assertThat(context.getResponse().getStatusCode()).isEqualTo(expectedStatusCode); assertThat(context.getRequest().getUrl().getPathname()).isEqualTo(path); } diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/CommonVertxServerClientTest.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/CommonVertxServerClientTest.java index 21023b60bf..03e23aa05d 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/CommonVertxServerClientTest.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/CommonVertxServerClientTest.java @@ -18,8 +18,8 @@ */ package co.elastic.apm.agent.vertx.helper; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import io.vertx.core.Handler; import io.vertx.core.Vertx; import io.vertx.ext.web.Router; @@ -51,13 +51,13 @@ void testBasicDownstreamCall(String targetPath) throws Exception { reporter.awaitTransactionCount(2); reporter.awaitSpanCount(1); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions.stream().map(t -> t.getNameAsString())).containsAll(Set.of("GET /downstream", "GET /" + targetPath)); - Transaction firstTransaction = transactions.stream().filter(t -> t.getNameAsString().contains(targetPath)).findFirst().get(); - Transaction secondTransaction = transactions.stream().filter(t -> t.getNameAsString().contains("downstream")).findFirst().get(); + TransactionImpl firstTransaction = transactions.stream().filter(t -> t.getNameAsString().contains(targetPath)).findFirst().get(); + TransactionImpl secondTransaction = transactions.stream().filter(t -> t.getNameAsString().contains("downstream")).findFirst().get(); - Span exitSpan = reporter.getFirstSpan(); + SpanImpl exitSpan = reporter.getFirstSpan(); assertThat(exitSpan.isChildOf(firstTransaction)).isTrue(); assertThat(secondTransaction.isChildOf(exitSpan)).isTrue(); @@ -73,16 +73,16 @@ void testDownstreamCallWithExtraSpan(String targetPath) throws Exception { reporter.awaitTransactionCount(2); reporter.awaitSpanCount(2); - List transactions = reporter.getTransactions(); + List transactions = reporter.getTransactions(); assertThat(transactions.stream().map(t -> t.getNameAsString())).containsAll(Set.of("GET /downstream", "GET /with-extra-span/" + targetPath)); - Transaction firstTransaction = transactions.stream().filter(t -> t.getNameAsString().contains(targetPath)).findFirst().get(); - Transaction secondTransaction = transactions.stream().filter(t -> t.getNameAsString().contains("downstream")).findFirst().get(); + TransactionImpl firstTransaction = transactions.stream().filter(t -> t.getNameAsString().contains(targetPath)).findFirst().get(); + TransactionImpl secondTransaction = transactions.stream().filter(t -> t.getNameAsString().contains("downstream")).findFirst().get(); - List spans = reporter.getSpans(); - Span exitSpan = spans.stream().filter(s -> s.getNameAsString().contains("GET")).findFirst().get(); - Span customSpan = spans.stream().filter(s -> s.getNameAsString().equals("custom-child-span")).findFirst().get(); + List spans = reporter.getSpans(); + SpanImpl exitSpan = spans.stream().filter(s -> s.getNameAsString().contains("GET")).findFirst().get(); + SpanImpl customSpan = spans.stream().filter(s -> s.getNameAsString().equals("custom-child-span")).findFirst().get(); assertThat(customSpan.isChildOf(firstTransaction)).isTrue(); assertThat(exitSpan.isChildOf(customSpan)).isTrue(); diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/CommonVertxWebTest.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/CommonVertxWebTest.java index 3dab442a7e..4f050613b5 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/CommonVertxWebTest.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/CommonVertxWebTest.java @@ -18,13 +18,13 @@ */ package co.elastic.apm.agent.vertx.helper; -import co.elastic.apm.agent.configuration.CoreConfiguration; +import co.elastic.apm.agent.configuration.CoreConfigurationImpl; import co.elastic.apm.agent.impl.TracerInternalApiUtils; -import co.elastic.apm.agent.impl.context.Request; -import co.elastic.apm.agent.impl.context.TransactionContext; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.RequestImpl; +import co.elastic.apm.agent.impl.context.TransactionContextImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.common.util.WildcardMatcher; import co.elastic.apm.agent.sdk.internal.util.VersionUtils; import co.elastic.apm.agent.tracer.metadata.PotentiallyMultiValuedMap; @@ -60,7 +60,7 @@ public abstract class CommonVertxWebTest extends AbstractVertxWebTest { void testBasicVertxWebCall() throws Exception { Response response = http().get("/test"); expectTransaction(response, "/test", DEFAULT_RESPONSE_BODY, "GET /test", 200); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getFrameworkName()).isEqualTo(AbstractVertxWebHelper.FRAMEWORK_NAME); String vertxVersion = VersionUtils.getVersion(RoutingContext.class, "io.vertx", "vertx-web"); @@ -98,7 +98,7 @@ void testCallWithoutHeaders() throws Exception { Response response = http().get("/test", headers); expectTransaction(response, "/test", DEFAULT_RESPONSE_BODY, "GET /test", 200); - TransactionContext context = reporter.getFirstTransaction().getContext(); + TransactionContextImpl context = reporter.getFirstTransaction().getContext(); assertThat(context.getRequest().getHeaders().size()).isEqualTo(0); assertThat(context.getResponse().getHeaders().size()).isEqualTo(0); assertThat(context.getRequest().getFormUrlEncodedParameters().size()).isEqualTo(0); @@ -136,13 +136,13 @@ void testCallWithPathGroupAsTransactionName() throws Exception { @Test void testCallWithQueryParameters() throws Exception { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); doReturn(List.of(WildcardMatcher.valueOf("application/x-www-form-urlencoded*"))).when(webConfiguration).getCaptureContentTypes(); Response response = http().post("/post?par1=abc&par2=xyz", "Some Body", MediaType.get("application/x-www-form-urlencoded")); expectTransaction(response, "/post", DEFAULT_RESPONSE_BODY, "POST /post", 200); - Request request = reporter.getFirstTransaction().getContext().getRequest(); + RequestImpl request = reporter.getFirstTransaction().getContext().getRequest(); assertThat(request.getMethod()).isEqualTo("POST"); assertThat(request.getFormUrlEncodedParameters().size()).isEqualTo(2); assertThat(request.getFormUrlEncodedParameters().containsIgnoreCase("par1")).isEqualTo(true); @@ -155,7 +155,7 @@ void testCallWithQueryParameters() throws Exception { @Test void testCallWithBodyCapturing() throws Exception { - doReturn(CoreConfiguration.EventType.ALL).when(coreConfiguration).getCaptureBody(); + doReturn(CoreConfigurationImpl.EventType.ALL).when(coreConfiguration).getCaptureBody(); doReturn(List.of(WildcardMatcher.valueOf("application/json*"))).when(webConfiguration).getCaptureContentTypes(); String jsonBody = "{\"key\":\"Some JSON\"}"; @@ -163,7 +163,7 @@ void testCallWithBodyCapturing() throws Exception { Response response = http().post("/post?par1=abc&par2=xyz", jsonBody, MediaType.get("application/json")); expectTransaction(response, "/post", DEFAULT_RESPONSE_BODY, "POST /post", 200); - Request request = reporter.getFirstTransaction().getContext().getRequest(); + RequestImpl request = reporter.getFirstTransaction().getContext().getRequest(); assertThat(request.getFormUrlEncodedParameters().size()).isEqualTo(0); assertThat(request.getUrl().getSearch()).isEqualTo("par1=abc&par2=xyz"); assertThat(request.getBody()).isInstanceOf(CharBuffer.class); @@ -201,7 +201,7 @@ void testContextPropagationToVertxEngine(String callType) throws Exception { expectTransaction(response, path, DEFAULT_RESPONSE_BODY, "GET " + path, 200); reporter.awaitSpanCount(1); assertThat(reporter.getSpans()).hasSize(1); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span.getNameAsString()).isEqualTo(callType + "-child-span"); assertThat(span.getParent()).isEqualTo(reporter.getFirstTransaction()); } @@ -214,7 +214,7 @@ void testContextPropagationToVertxContext(String callType) throws Exception { expectTransaction(response, path, DEFAULT_RESPONSE_BODY, "GET " + path, 200); reporter.awaitSpanCount(1); assertThat(reporter.getSpans()).hasSize(1); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span.getNameAsString()).isEqualTo(callType + "-child-span"); assertThat(span.getParent()).isEqualTo(reporter.getFirstTransaction()); } @@ -224,7 +224,7 @@ void testTransactionRecyclingWithAsyncSpan() throws Exception { String path = "/" + CALL_SCHEDULED_SHIFTED; Response response = http().get(path); expectTransaction(response, path, DEFAULT_RESPONSE_BODY, "GET " + path, 200); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); // Mock reporter expects the reference count to be at 1 at test end, // so we decrement it here to emulate real reporter behaviour which would recycle ended transactions directly. @@ -261,26 +261,26 @@ void testParallel() { assertThat(reporter.getTransactions().stream().map(transaction -> transaction.getContext().getRequest().getUrl().getPathname())) .containsExactlyInAnyOrder("/parallel/1", "/parallel/2", "/parallel/3", "/parallel/4", "/parallel/5"); - assertThat(reporter.getTransactions().stream().map(AbstractSpan::getNameAsString).distinct()).containsExactlyInAnyOrder("GET /parallel/:param"); + assertThat(reporter.getTransactions().stream().map(AbstractSpanImpl::getNameAsString).distinct()).containsExactlyInAnyOrder("GET /parallel/:param"); assertThat(reporter.getFirstTransaction().getSpanCount().getTotal().get()).isEqualTo(3); - AbstractSpan t1 = transaction("/parallel/1"); - AbstractSpan t2 = transaction("/parallel/2"); - AbstractSpan t3 = transaction("/parallel/3"); - AbstractSpan t4 = transaction("/parallel/4"); - AbstractSpan t5 = transaction("/parallel/5"); + AbstractSpanImpl t1 = transaction("/parallel/1"); + AbstractSpanImpl t2 = transaction("/parallel/2"); + AbstractSpanImpl t3 = transaction("/parallel/3"); + AbstractSpanImpl t4 = transaction("/parallel/4"); + AbstractSpanImpl t5 = transaction("/parallel/5"); assertThat(spansContaining("-1").size()).isEqualTo(3); - assertThat(spansContaining("-1").stream().map(Span::getParent).distinct()).containsExactly(t1); + assertThat(spansContaining("-1").stream().map(SpanImpl::getParent).distinct()).containsExactly(t1); assertThat(spansContaining("-2").size()).isEqualTo(3); - assertThat(spansContaining("-2").stream().map(Span::getParent).distinct()).containsExactly(t2); + assertThat(spansContaining("-2").stream().map(SpanImpl::getParent).distinct()).containsExactly(t2); assertThat(spansContaining("-3").size()).isEqualTo(3); - assertThat(spansContaining("-3").stream().map(Span::getParent).distinct()).containsExactly(t3); + assertThat(spansContaining("-3").stream().map(SpanImpl::getParent).distinct()).containsExactly(t3); assertThat(spansContaining("-4").size()).isEqualTo(3); - assertThat(spansContaining("-4").stream().map(Span::getParent).distinct()).containsExactly(t4); + assertThat(spansContaining("-4").stream().map(SpanImpl::getParent).distinct()).containsExactly(t4); assertThat(spansContaining("-5").size()).isEqualTo(3); - assertThat(spansContaining("-5").stream().map(Span::getParent).distinct()).containsExactly(t5); + assertThat(spansContaining("-5").stream().map(SpanImpl::getParent).distinct()).containsExactly(t5); executorService.shutdown(); } @@ -300,11 +300,11 @@ void testWrongMethod() throws Exception { expectTransaction(response, "/post", "", "GET unknown route", 405); } - private List spansContaining(String name) { + private List spansContaining(String name) { return reporter.getSpans().stream().filter(span -> span.getNameAsString().contains(name)).collect(Collectors.toList()); } - private Transaction transaction(String path) { + private TransactionImpl transaction(String path) { return reporter.getTransactions().stream().filter(t -> t.getContext().getRequest().getUrl().getPathname().equals(path)).findAny().get(); } @@ -332,7 +332,7 @@ protected void initRoutes(Router router) { router.get("/" + CALL_SCHEDULED_SHIFTED).handler(routingContext -> { routingContext.vertx() .setTimer(500, tid -> { - Span child = Objects.requireNonNull(tracer.getActive()).createSpan(); + SpanImpl child = Objects.requireNonNull(tracer.getActive()).createSpan(); child.withName(CALL_SCHEDULED_SHIFTED + "-child-span"); child.end(); }); @@ -345,11 +345,11 @@ protected void initRoutes(Router router) { .runOnContext(new HandlerWithCustomNamedSpan(getDefaultHandlerImpl(), routingContext, CALL_ON_CONTEXT))); router.get("/parallel/:param").handler(routingContext -> routingContext.vertx().setTimer(1, tid_1 -> { - Span asyncChild = Objects.requireNonNull(tracer.getActive()).createSpan(); + SpanImpl asyncChild = Objects.requireNonNull(tracer.getActive()).createSpan(); asyncChild.withName("first-child-" + routingContext.pathParam("param")); routingContext.vertx().executeBlocking(p -> { - Span blockingChild = Objects.requireNonNull(tracer.getActive()).createSpan(); + SpanImpl blockingChild = Objects.requireNonNull(tracer.getActive()).createSpan(); blockingChild.withName("second-child-" + routingContext.pathParam("param")); try { @@ -359,7 +359,7 @@ protected void initRoutes(Router router) { } routingContext.vertx().setTimer(1, tid_2 -> { - Span thirdChild = Objects.requireNonNull(tracer.getActive()).createSpan(); + SpanImpl thirdChild = Objects.requireNonNull(tracer.getActive()).createSpan(); thirdChild.withName("third-child-" + routingContext.pathParam("param")); getDefaultHandlerImpl().handle(routingContext); thirdChild.end(); diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/HandlerWithCustomNamedSpan.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/HandlerWithCustomNamedSpan.java index 846158c9ca..3209a3f819 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/HandlerWithCustomNamedSpan.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/helper/HandlerWithCustomNamedSpan.java @@ -20,8 +20,8 @@ import co.elastic.apm.agent.impl.ElasticApmTracer; import co.elastic.apm.agent.tracer.GlobalTracer; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; -import co.elastic.apm.agent.impl.transaction.Span; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; import io.vertx.core.Handler; import io.vertx.ext.web.RoutingContext; @@ -39,11 +39,11 @@ public HandlerWithCustomNamedSpan(Handler handler, RoutingContex @Override public void handle(Void v) { - AbstractSpan active = GlobalTracer.get().require(ElasticApmTracer.class).getActive(); + AbstractSpanImpl active = GlobalTracer.get().require(ElasticApmTracer.class).getActive(); if (active == null) { return; } - Span child = active.createSpan(); + SpanImpl child = active.createSpan(); child.withName(spanName + "-child-span"); child.activate(); handler.handle(routingContext); diff --git a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/webclient/AbstractVertxWebClientTest.java b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/webclient/AbstractVertxWebClientTest.java index 202a8a60e2..3eb6e8349f 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/webclient/AbstractVertxWebClientTest.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx-common/src/test/java/co/elastic/apm/agent/vertx/webclient/AbstractVertxWebClientTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.vertx.webclient; import co.elastic.apm.agent.httpclient.AbstractHttpClientInstrumentationTest; -import co.elastic.apm.agent.impl.error.ErrorCapture; -import co.elastic.apm.agent.impl.transaction.AbstractSpan; +import co.elastic.apm.agent.impl.error.ErrorCaptureImpl; +import co.elastic.apm.agent.impl.transaction.AbstractSpanImpl; import io.vertx.core.Vertx; import io.vertx.core.buffer.Buffer; import io.vertx.ext.web.client.HttpRequest; @@ -48,7 +48,7 @@ public void setUp() { // This property is needed as otherwise Vert.x event loop threads won't have a context class loader (null) // which leads to NullPointerExceptions when spans are JSON validated in Unit tests System.setProperty("vertx.disableTCCL", "true"); - AbstractSpan activeSpan = tracer.getActive(); + AbstractSpanImpl activeSpan = tracer.getActive(); // deactivate current span to avoid tracing web client creation for JUnit test activeSpan.deactivate(); @@ -88,7 +88,7 @@ public void testFailedRequest() { // expected } - ErrorCapture error = reporter.getFirstError(500); + ErrorCaptureImpl error = reporter.getFirstError(500); assertThat(error.getException()).isNotNull(); assertThat(error.getException().getClass()).isNotNull(); assertThat(error.getException().getMessage()).contains("not-existing.com"); diff --git a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/pom.xml b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/pom.xml index e0c9233b40..e9db76719b 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/pom.xml +++ b/apm-agent-plugins/apm-vertx/apm-vertx3-plugin/pom.xml @@ -5,7 +5,7 @@ apm-vertx co.elastic.apm - 1.50.0 + 1.51.0 apm-vertx3-plugin diff --git a/apm-agent-plugins/apm-vertx/apm-vertx3-test-latest/pom.xml b/apm-agent-plugins/apm-vertx/apm-vertx3-test-latest/pom.xml index 6c756fa5fc..1792484614 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx3-test-latest/pom.xml +++ b/apm-agent-plugins/apm-vertx/apm-vertx3-test-latest/pom.xml @@ -5,7 +5,7 @@ apm-vertx co.elastic.apm - 1.50.0 + 1.51.0 apm-vertx3-test-latest diff --git a/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/pom.xml b/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/pom.xml index 6ca1d354e9..05e2c35acd 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/pom.xml +++ b/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/pom.xml @@ -5,7 +5,7 @@ apm-vertx co.elastic.apm - 1.50.0 + 1.51.0 apm-vertx4-plugin diff --git a/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/webclient/HttpContextInstrumentation.java b/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/webclient/HttpContextInstrumentation.java index 47b8fa5325..773de3dfa3 100644 --- a/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/webclient/HttpContextInstrumentation.java +++ b/apm-agent-plugins/apm-vertx/apm-vertx4-plugin/src/main/java/co/elastic/apm/agent/vertx/v4/webclient/HttpContextInstrumentation.java @@ -18,7 +18,7 @@ */ package co.elastic.apm.agent.vertx.v4.webclient; -import co.elastic.apm.agent.tracer.ElasticContext; +import co.elastic.apm.agent.tracer.TraceState; import co.elastic.apm.agent.tracer.Transaction; import co.elastic.apm.agent.vertx.AbstractVertxWebClientHelper; import co.elastic.apm.agent.vertx.AbstractVertxWebHelper; @@ -81,7 +81,7 @@ public static class HttpContextPrepareRequestAdvice extends AdviceBase { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void prepareRequest(@Advice.This HttpContext httpContext) { - ElasticContext currentContext = tracer.currentContext(); + TraceState currentContext = tracer.currentContext(); if (!currentContext.isEmpty()) { currentContext.incrementReferences(); httpContext.set(WEB_CLIENT_PARENT_CONTEXT_KEY, currentContext); @@ -110,7 +110,7 @@ public static class HttpContextSendRequestAdvice extends AdviceBase { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void sendRequest(@Advice.This HttpContext httpContext, @Advice.Argument(value = 0) HttpClientRequest request, @Advice.FieldValue(value = "context") Context vertxContext) { - ElasticContext parent = httpContext.get(WEB_CLIENT_PARENT_CONTEXT_KEY); + TraceState parent = httpContext.get(WEB_CLIENT_PARENT_CONTEXT_KEY); if (parent != null) { // Setting to null removes from the context attributes map @@ -181,7 +181,7 @@ public static class HttpContextFailAdvice extends AdviceBase { @Advice.OnMethodEnter(suppress = Throwable.class, inline = false) public static void fail(@Advice.This HttpContext httpContext, @Advice.Argument(value = 0) Throwable thrown) { - ElasticContext parent = httpContext.get(WEB_CLIENT_PARENT_CONTEXT_KEY); + TraceState parent = httpContext.get(WEB_CLIENT_PARENT_CONTEXT_KEY); if (parent != null) { httpContext.set(WEB_CLIENT_PARENT_CONTEXT_KEY, null); try { diff --git a/apm-agent-plugins/apm-vertx/pom.xml b/apm-agent-plugins/apm-vertx/pom.xml index 3f2a77fb82..b448af06bd 100644 --- a/apm-agent-plugins/apm-vertx/pom.xml +++ b/apm-agent-plugins/apm-vertx/pom.xml @@ -5,7 +5,7 @@ apm-agent-plugins co.elastic.apm - 1.50.0 + 1.51.0 apm-vertx diff --git a/apm-agent-plugins/pom.xml b/apm-agent-plugins/pom.xml index 5c8cb9276d..a1e1c95e9a 100644 --- a/apm-agent-plugins/pom.xml +++ b/apm-agent-plugins/pom.xml @@ -5,7 +5,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 apm-agent-plugins diff --git a/apm-agent-tracer/pom.xml b/apm-agent-tracer/pom.xml index c1b1249218..dd1249acf9 100644 --- a/apm-agent-tracer/pom.xml +++ b/apm-agent-tracer/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm apm-agent-parent - 1.50.0 + 1.51.0 apm-agent-tracer diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/BaggageContextBuilder.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/BaggageContextBuilder.java index e8e36f4c65..fa6563581c 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/BaggageContextBuilder.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/BaggageContextBuilder.java @@ -41,5 +41,5 @@ public interface BaggageContextBuilder { /** * @return the created context with the baggage updates applied. */ - ElasticContext buildContext(); + TraceState buildContext(); } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/GlobalTracer.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/GlobalTracer.java index 692ffdca5e..ab5b8d7607 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/GlobalTracer.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/GlobalTracer.java @@ -25,6 +25,7 @@ import co.elastic.apm.agent.tracer.reference.ReferenceCounted; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; import co.elastic.apm.agent.tracer.service.Service; +import co.elastic.apm.agent.tracer.service.ServiceInfo; import com.dslplatform.json.JsonWriter; import javax.annotation.Nullable; @@ -99,7 +100,7 @@ public Set getTraceHeaderNames() { } @Override - public ElasticContext currentContext() { + public TraceState currentContext() { return tracer.currentContext(); } @@ -129,8 +130,8 @@ public Transaction startRootTransaction(@Nullable ClassLoader initiatingClass @Nullable @Override - public Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { - return tracer.startChildTransaction(headerCarrier, textHeadersGetter, initiatingClassLoader); + public Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter headerGetter, @Nullable ClassLoader initiatingClassLoader) { + return tracer.startChildTransaction(headerCarrier, headerGetter, initiatingClassLoader); } @Nullable @@ -201,4 +202,19 @@ public void reportMetric(JsonWriter metrics) { tracer.reportMetric(metrics); } + @Nullable + @Override + public ServiceInfo getServiceInfoForClassLoader(@Nullable ClassLoader initiatingClassLoader) { + return tracer.getServiceInfoForClassLoader(initiatingClassLoader); + } + + @Override + public void setServiceInfoForClassLoader(@Nullable ClassLoader classLoader, ServiceInfo serviceInfo) { + tracer.setServiceInfoForClassLoader(classLoader, serviceInfo); + } + + @Override + public ServiceInfo autoDetectedServiceInfo() { + return tracer.autoDetectedServiceInfo(); + } } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopElasticContext.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopTraceState.java similarity index 91% rename from apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopElasticContext.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopTraceState.java index 1f662c7328..34520f7b51 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopElasticContext.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopTraceState.java @@ -23,17 +23,17 @@ import javax.annotation.Nullable; -public class NoopElasticContext implements ElasticContext { +public class NoopTraceState implements TraceState { - static final NoopElasticContext INSTANCE = new NoopElasticContext(); + static final NoopTraceState INSTANCE = new NoopTraceState(); @Override - public NoopElasticContext activate() { + public NoopTraceState activate() { return this; } @Override - public NoopElasticContext deactivate() { + public NoopTraceState deactivate() { return this; } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopTracer.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopTracer.java index 85fab5a76a..c7f00a616e 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopTracer.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/NoopTracer.java @@ -25,6 +25,7 @@ import co.elastic.apm.agent.tracer.reference.ReferenceCounted; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; import co.elastic.apm.agent.tracer.service.Service; +import co.elastic.apm.agent.tracer.service.ServiceInfo; import com.dslplatform.json.JsonWriter; import javax.annotation.Nullable; @@ -76,8 +77,8 @@ public Set getTraceHeaderNames() { } @Override - public ElasticContext currentContext() { - return NoopElasticContext.INSTANCE; + public TraceState currentContext() { + return NoopTraceState.INSTANCE; } @Nullable @@ -106,7 +107,7 @@ public Transaction startRootTransaction(@Nullable ClassLoader initiatingClass @Nullable @Override - public Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader) { + public Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter headerGetter, @Nullable ClassLoader initiatingClassLoader) { return null; } @@ -167,4 +168,18 @@ public void addShutdownHook(AutoCloseable hook) { @Override public void reportMetric(JsonWriter metrics) { } + @Nullable + @Override + public ServiceInfo getServiceInfoForClassLoader(@Nullable ClassLoader initiatingClassLoader) { + return null; + } + + @Override + public void setServiceInfoForClassLoader(@Nullable ClassLoader classLoader, ServiceInfo serviceInfo) { + } + + @Override + public ServiceInfo autoDetectedServiceInfo() { + return ServiceInfo.empty(); + } } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/ElasticContext.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/TraceState.java similarity index 97% rename from apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/ElasticContext.java rename to apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/TraceState.java index 4f86c8bd6a..1cd5287036 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/ElasticContext.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/TraceState.java @@ -24,7 +24,7 @@ import javax.annotation.Nullable; -public interface ElasticContext> extends ActivateableInScope, ReferenceCounted { +public interface TraceState> extends ActivateableInScope, ReferenceCounted { /** * @return the span/transaction that is associated to this context, {@literal null} if there is none @@ -113,7 +113,7 @@ public interface ElasticContext> extends Activateabl * @return {@literal true} when span limit is reached and the caller can optimize and not create a span. The caller * is expected to call this method before every span creation operation for proper dropped spans accounting. If not * called before attempting span creation, a span will be created and dropped before reporting. - *
+ *
* Expected caller behavior depends on the returned value: *

    *
  • {@literal true} returned means the caller is expected to NOT call {@link #createSpan()} or {@link #createExitSpan()}
  • diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java index 4f1d6efc2e..192e014321 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/Tracer.java @@ -25,6 +25,7 @@ import co.elastic.apm.agent.tracer.reference.ReferenceCounted; import co.elastic.apm.agent.tracer.reference.ReferenceCountedMap; import co.elastic.apm.agent.tracer.service.Service; +import co.elastic.apm.agent.tracer.service.ServiceInfo; import com.dslplatform.json.JsonWriter; import javax.annotation.Nullable; @@ -48,7 +49,7 @@ public interface Tracer { Set getTraceHeaderNames(); - ElasticContext currentContext(); + TraceState currentContext(); @Nullable AbstractSpan getActive(); @@ -75,13 +76,13 @@ public interface Tracer { * available), then it will be started as the root transaction of the trace. * * @param headerCarrier the Object from which context headers can be obtained, typically a request or a message - * @param textHeadersGetter provides the trace context headers required in order to create a child transaction + * @param headerGetter provides the trace context headers required in order to create a child transaction * @param initiatingClassLoader the class loader corresponding to the service which initiated the creation of the transaction. * Used to determine the service name. * @return a transaction which is a child of the provided parent if the agent is currently RUNNING; null otherwise */ @Nullable - Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter textHeadersGetter, @Nullable ClassLoader initiatingClassLoader); + Transaction startChildTransaction(@Nullable C headerCarrier, HeaderGetter headerGetter, @Nullable ClassLoader initiatingClassLoader); @Nullable ErrorCapture captureException(@Nullable Throwable e, @Nullable ClassLoader initiatingClassLoader); @@ -111,4 +112,21 @@ public interface Tracer { void flush(); void completeMetaData(String name, String version, String id, String region); + @Nullable + ServiceInfo getServiceInfoForClassLoader(@Nullable ClassLoader initiatingClassLoader); + + /** + * Sets the service name and version for all {@link co.elastic.apm.agent.tracer.Transaction}s, + * {@link co.elastic.apm.agent.tracer.Span}s and {@link co.elastic.apm.agent.tracer.ErrorCapture}s which are created + * by the service which corresponds to the provided {@link ClassLoader}. + *

    + * The main use case is being able to differentiate between multiple services deployed to the same application server. + *

    + * + * @param classLoader the class loader which corresponds to a particular service + * @param serviceInfo the service name and version for this class loader + */ + void setServiceInfoForClassLoader(@Nullable ClassLoader classLoader, ServiceInfo serviceInfo); + + ServiceInfo autoDetectedServiceInfo(); } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/MessagingConfiguration.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/MessagingConfiguration.java index 85420bc1b2..ab8c28322a 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/MessagingConfiguration.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/MessagingConfiguration.java @@ -111,8 +111,8 @@ public class MessagingConfiguration extends ConfigurationOptionProvider { private final ConfigurationOption rabbitMQNamingMode = ConfigurationOption.enumOption(RabbitMQNamingMode.class) .key("rabbitmq_naming_mode") .configurationCategory(MESSAGING_CATEGORY) - .description("Defines whether the agent should use the exchanges or the queue for the naming of RabbitMQ Transactions. Valid options are `QUEUE` and `EXCHANGE`.\n" + - "Note that `QUEUE` only works when using RabbitMQ via spring-amqp." + .description("Defines whether the agent should use the exchanges, the routing key or the queue for the naming of RabbitMQ Transactions. Valid options are `QUEUE`, `ROUTING_KEY` and `EXCHANGE`.\n" + + "Note that `QUEUE` only works when using RabbitMQ via spring-amqp and `ROUTING_KEY` only works for the non spring-client." ) .dynamic(true) .tags("added[1.46.0]") @@ -187,5 +187,9 @@ public enum RabbitMQNamingMode { * Use queue in transaction names */ QUEUE, + /** + * Use routing key in transaction names + */ + ROUTING_KEY } } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/StacktraceConfiguration.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/StacktraceConfiguration.java index 7090a0108c..21ab9562fb 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/StacktraceConfiguration.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/StacktraceConfiguration.java @@ -21,5 +21,6 @@ import java.util.Collection; public interface StacktraceConfiguration { + Collection getApplicationPackages(); } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/WebConfiguration.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/WebConfiguration.java index d7fdb00f91..2a35facaf5 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/WebConfiguration.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/configuration/WebConfiguration.java @@ -27,8 +27,12 @@ import java.util.Collections; import java.util.List; +import static co.elastic.apm.agent.tracer.configuration.RangeValidator.isInRange; + public class WebConfiguration extends ConfigurationOptionProvider { + public static final int MAX_BODY_CAPTURE_BYTES = 1024; + private static final String HTTP_CATEGORY = "HTTP"; private final ConfigurationOption> captureContentTypes = ConfigurationOption @@ -121,6 +125,17 @@ public class WebConfiguration extends ConfigurationOptionProvider { .dynamic(true) .buildWithDefault(Collections.emptyList()); + private final ConfigurationOption captureClientRequestBytes = ConfigurationOption.integerOption() + .addValidator(isInRange(0, MAX_BODY_CAPTURE_BYTES)) + .key("capture_http_client_request_body_size") + .configurationCategory(HTTP_CATEGORY) + .tags("added[1.50.0]", "internal") + .description("Configures how many bytes of http-client request bodies shall be captured. " + + "Note that only request bodies will be captured for content types matching the capture_body_content_types configuration. " + + " The maximum allowed value is " + MAX_BODY_CAPTURE_BYTES + " , a value of 0 disables body capturing") + .dynamic(true) + .buildWithDefault(0); + public List getIgnoreUrls() { return ignoreUrls.get(); } @@ -141,4 +156,8 @@ public List getCaptureContentTypes() { return captureContentTypes.get(); } + public int getCaptureClientRequestBytes() { + return captureClientRequestBytes.get(); + } + } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/BodyCapture.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/BodyCapture.java new file mode 100644 index 0000000000..0d005a126f --- /dev/null +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/BodyCapture.java @@ -0,0 +1,65 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package co.elastic.apm.agent.tracer.metadata; + +import javax.annotation.Nullable; + +public interface BodyCapture { + + /** + * Requests that the body for this span may be captured. + * Whether it is actually captured may depend on further details not known yet when this method is called + * (e.g. the Content-Type header). + */ + void markEligibleForCapturing(); + + /** + * @return true, if {@link #markEligibleForCapturing()} was called for this span. + */ + boolean isEligibleForCapturing(); + + /** + * This method acts as a protection mechanism so that only one instrumentation tries to capture the body. + * It returns true, if the calling instrumentation shall start adding body byte via {@link #append(byte)}. + *

    + * For this to happen, {@link #markEligibleForCapturing()} must have been called first. + *

    + * After {@link #startCapture(String, int)} has returned true once, subsequent calls will return false. + * So for example if instrumentation A and B are active for the same span, only the first one will actually be capturing the body, + * because {@link #startCapture(String, int)} only returns true once. + * + * @param charset the charset (if available) with which the request-body is encoded. + * @param numBytesToCapture the number of bytes to capture, to configure the limit of the internal buffer + * + * @return true, if the calling instrumentation should be capturing the body (by calling {@link #append(byte)} + */ + boolean startCapture(@Nullable String charset, int numBytesToCapture); + + void append(byte b); + + void append(byte[] b, int offset, int len); + + /** + * Checks if the limit number of bytes to capture has been reached. In this case future append calls would be a no-op. + * If this is the case, the caller can consider releasing the reference to the span to prevent potential memory leaks. + * + * @return true, if the maximum number of bytes supported has already been captured + */ + boolean isFull(); +} diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Http.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Http.java index d4d614c039..aad5ad3d85 100644 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Http.java +++ b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/metadata/Http.java @@ -39,4 +39,6 @@ public interface Http { @Nullable String getMethod(); + + BodyCapture getRequestBody(); } diff --git a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/service/ServiceAwareTracer.java b/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/service/ServiceAwareTracer.java deleted file mode 100644 index 30634926fe..0000000000 --- a/apm-agent-tracer/src/main/java/co/elastic/apm/agent/tracer/service/ServiceAwareTracer.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package co.elastic.apm.agent.tracer.service; - -import co.elastic.apm.agent.tracer.Tracer; - -import javax.annotation.Nullable; - -public interface ServiceAwareTracer extends Tracer { - - @Nullable - ServiceInfo getServiceInfoForClassLoader(@Nullable ClassLoader initiatingClassLoader); - - void setServiceInfoForClassLoader(@Nullable ClassLoader classLoader, ServiceInfo serviceInfo); - - ServiceInfo autoDetectedServiceInfo(); -} diff --git a/apm-opentracing/pom.xml b/apm-opentracing/pom.xml index 34de83a8f0..f40310b6d5 100644 --- a/apm-opentracing/pom.xml +++ b/apm-opentracing/pom.xml @@ -5,7 +5,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 apm-opentracing diff --git a/apm-opentracing/src/test/java/co/elastic/apm/opentracing/OpenTracingBridgeTest.java b/apm-opentracing/src/test/java/co/elastic/apm/opentracing/OpenTracingBridgeTest.java index 23d5831870..cdecbb5e94 100644 --- a/apm-opentracing/src/test/java/co/elastic/apm/opentracing/OpenTracingBridgeTest.java +++ b/apm-opentracing/src/test/java/co/elastic/apm/opentracing/OpenTracingBridgeTest.java @@ -21,10 +21,11 @@ import co.elastic.apm.agent.AbstractInstrumentationTest; import co.elastic.apm.agent.impl.TextHeaderMapAccessor; import co.elastic.apm.agent.impl.TracerInternalApiUtils; -import co.elastic.apm.agent.impl.context.Http; -import co.elastic.apm.agent.impl.transaction.Id; -import co.elastic.apm.agent.impl.transaction.TraceContext; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.context.HttpImpl; +import co.elastic.apm.agent.impl.transaction.IdImpl; +import co.elastic.apm.agent.impl.transaction.TraceContextImpl; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.agent.tracer.util.ResultUtil; import io.opentracing.Scope; @@ -83,7 +84,7 @@ void testCreateNonActiveTransaction() { span.finish(TimeUnit.MILLISECONDS.toMicros(1)); assertThat(reporter.getTransactions()).hasSize(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getDuration()).isEqualTo(1000); assertThat(transaction.getNameAsString()).isEqualTo("test"); assertThat(transaction.getFrameworkName()).isEqualTo("OpenTracing"); @@ -142,7 +143,7 @@ void testContextAvailableAfterFinish() { final Span span = apmTracer.buildSpan("transaction").start(); span.finish(); assertThat(reporter.getTransactions()).hasSize(1); - final Transaction transaction = reporter.getFirstTransaction(); + final TransactionImpl transaction = reporter.getFirstTransaction(); String transactionId = transaction.getTraceContext().getId().toString(); assertThat(transaction.getOutcome()).isEqualTo(Outcome.SUCCESS); @@ -152,7 +153,7 @@ void testContextAvailableAfterFinish() { childSpan.finish(); assertThat(reporter.getSpans()).hasSize(1); - co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan(); + SpanImpl internalSpan = reporter.getFirstSpan(); assertThat(internalSpan.getTraceContext().getParentId().toString()).isEqualTo(transactionId); assertThat(internalSpan.getOutcome()).isEqualTo(Outcome.SUCCESS); } @@ -162,7 +163,7 @@ void testScopeAfterFinish() { final Span span = apmTracer.buildSpan("transaction").start(); span.finish(); assertThat(reporter.getTransactions()).hasSize(1); - final Transaction transaction = reporter.getFirstTransaction(); + final TransactionImpl transaction = reporter.getFirstTransaction(); String transactionId = transaction.getTraceContext().getId().toString(); assertThat(transaction.getOutcome()).isEqualTo(Outcome.SUCCESS); @@ -173,7 +174,7 @@ void testScopeAfterFinish() { } assertThat(reporter.getSpans()).hasSize(1); - co.elastic.apm.agent.impl.transaction.Span internalSpan = reporter.getFirstSpan(); + SpanImpl internalSpan = reporter.getFirstSpan(); assertThat(internalSpan.getTraceContext().getParentId().toString()).isEqualTo(transactionId); assertThat(internalSpan.getOutcome()).isEqualTo(Outcome.SUCCESS); } @@ -231,9 +232,9 @@ void testLegacyCreateActiveTransactionAndSpans() { } assertThat(reporter.getTransactions()).hasSize(1); - final Transaction transaction = reporter.getFirstTransaction(); - final co.elastic.apm.agent.impl.transaction.Span span = reporter.getSpans().get(1); - final co.elastic.apm.agent.impl.transaction.Span nestedSpan = reporter.getSpans().get(0); + final TransactionImpl transaction = reporter.getFirstTransaction(); + final SpanImpl span = reporter.getSpans().get(1); + final SpanImpl nestedSpan = reporter.getSpans().get(0); assertThat(transaction.getDuration()).isGreaterThan(0); assertThat(transaction.getNameAsString()).isEqualTo("transaction"); assertThat(transaction.getFrameworkName()).isEqualTo("OpenTracing"); @@ -262,9 +263,9 @@ void testCreateActiveTransactionAndSpans() { otTransaction.finish(); assertThat(reporter.getTransactions()).hasSize(1); - final Transaction transaction = reporter.getFirstTransaction(); - final co.elastic.apm.agent.impl.transaction.Span span = reporter.getSpans().get(1); - final co.elastic.apm.agent.impl.transaction.Span nestedSpan = reporter.getSpans().get(0); + final TransactionImpl transaction = reporter.getFirstTransaction(); + final SpanImpl span = reporter.getSpans().get(1); + final SpanImpl nestedSpan = reporter.getSpans().get(0); assertThat(transaction.getDuration()).isGreaterThan(0); assertThat(transaction.getNameAsString()).isEqualTo("transaction"); assertThat(transaction.getFrameworkName()).isEqualTo("OpenTracing"); @@ -319,7 +320,7 @@ void testResolveClientType() { @Test void testTypeTags() { // New span model with type, subtype and action - co.elastic.apm.agent.impl.transaction.Span span = createSpanFromOtTags(Map.of( + SpanImpl span = createSpanFromOtTags(Map.of( "type", "template", "subtype", "jsf", "action", "render")); @@ -350,16 +351,16 @@ void testHttpMappingResultAndOutcome(int status) { String method = "GET"; String url = "http://localhost:8080"; - Transaction transaction = createTransactionFromOtTags(httpRequestMap("server", status)); + TransactionImpl transaction = createTransactionFromOtTags(httpRequestMap("server", status)); assertThat(transaction.getOutcome()).isEqualTo(ResultUtil.getOutcomeByHttpServerStatus(status)); assertThat(transaction.getResult()).isEqualTo(ResultUtil.getResultByHttpStatus(status)); assertThat(transaction.getContext().getResponse().getStatusCode()).isEqualTo(status); assertThat(transaction.getContext().getRequest().getMethod()).isEqualTo(method); assertThat(transaction.getContext().getRequest().getUrl().getFull().toString()).isEqualTo(url); - co.elastic.apm.agent.impl.transaction.Span span = createSpanFromOtTags(httpRequestMap("client", status)); + SpanImpl span = createSpanFromOtTags(httpRequestMap("client", status)); assertThat(span.getOutcome()).isEqualTo(ResultUtil.getOutcomeByHttpClientStatus(status)); - Http spanHttp = span.getContext().getHttp(); + HttpImpl spanHttp = span.getContext().getHttp(); assertThat(spanHttp.getStatusCode()).isEqualTo(status); assertThat(spanHttp.getUrl().toString()).isEqualTo(url); assertThat(spanHttp.getMethod()).isEqualTo(method); @@ -411,7 +412,7 @@ void testErrorLogging() { span.finish(); } assertThat(reporter.getTransactions()).hasSize(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getResult()).isEqualTo("error"); assertThat(transaction.getOutcome()).isEqualTo(Outcome.FAILURE); assertThat(reporter.getErrors()).hasSize(1); @@ -432,7 +433,7 @@ void testErrorLoggingWithTimestamp() { span.finish(); } assertThat(reporter.getTransactions()).hasSize(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getResult()).isEqualTo("error"); assertThat(transaction.getOutcome()).isEqualTo(Outcome.FAILURE); assertThat(reporter.getErrors()).hasSize(1); @@ -515,11 +516,11 @@ void testToId() { otSpan.finish(); } otTransaction.finish(); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction).isNotNull(); assertThat(otTransaction.context().toSpanId()).isEqualTo(transaction.getTraceContext().getId().toString()); assertThat(otTransaction.context().toTraceId()).isEqualTo(transaction.getTraceContext().getTraceId().toString()); - co.elastic.apm.agent.impl.transaction.Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span).isNotNull(); assertThat(otSpan.context().toSpanId()).isEqualTo(span.getTraceContext().getId().toString()); assertThat(otSpan.context().toTraceId()).isEqualTo(span.getTraceContext().getTraceId().toString()); @@ -531,17 +532,17 @@ void testToIdOfExtractedContext() { final String parentIdString = "b9c7c989f97918e1"; // -------------------------------------------------------- - final Id traceId = Id.new128BitId(); + final IdImpl traceId = IdImpl.new128BitId(); traceId.fromHexString(traceIdString, 0); assertThat(traceId.toString()).isEqualTo(traceIdString); // -------------------------------------------------------- - final Id spanId = Id.new64BitId(); + final IdImpl spanId = IdImpl.new64BitId(); spanId.fromHexString(parentIdString, 0); assertThat(spanId.toString()).isEqualTo(parentIdString); // -------------------------------------------------------- TextMap textMapExtractAdapter = new TextMapAdapter(Map.of( - TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, + TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-" + traceIdString + "-" + parentIdString + "-01", "User-Agent", "curl")); //ExternalProcessSpanContext @@ -560,11 +561,11 @@ void testInjectExtract() { Span otSpan = apmTracer.buildSpan("span") .asChildOf(apmTracer.extract(Format.Builtin.TEXT_MAP, new TextMapAdapter(Map.of( - TraceContext.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-" + traceId + "-" + parentId + "-01", + TraceContextImpl.W3C_TRACE_PARENT_TEXTUAL_HEADER_NAME, "00-" + traceId + "-" + parentId + "-01", "User-Agent", "curl")))) .start(); final Scope scope = apmTracer.activateSpan(otSpan); - Transaction transaction = tracer.currentTransaction(); + TransactionImpl transaction = tracer.currentTransaction(); assertThat(transaction).isNotNull(); assertThat(transaction.isSampled()).isTrue(); assertThat(transaction.getTraceContext().getTraceId().toString()).isEqualTo(traceId); @@ -575,7 +576,7 @@ void testInjectExtract() { final HashMap map = new HashMap<>(); apmTracer.inject(otSpan.context(), Format.Builtin.TEXT_MAP, new TextMapAdapter(map)); - final TraceContext injectedContext = TraceContext.with64BitId(tracer); + final TraceContextImpl injectedContext = TraceContextImpl.with64BitId(tracer); assertThat(injectedContext.asChildOf(map, TextHeaderMapAccessor.INSTANCE)).isTrue(); assertThat(injectedContext.getTraceId().toString()).isEqualTo(traceId); assertThat(injectedContext.getParentId()).isEqualTo(transaction.getTraceContext().getId()); @@ -632,12 +633,12 @@ void testSpanTags() { assertThat(reporter.getFirstSpan().getContext().getLabel("bar")).isEqualTo("baz"); } - private Transaction createTransactionFromOtTags(Map tags) { + private TransactionImpl createTransactionFromOtTags(Map tags) { final Tracer.SpanBuilder spanBuilder = apmTracer.buildSpan("transaction"); applyTags(tags, spanBuilder); spanBuilder.start().finish(); assertThat(reporter.getTransactions()).hasSize(1); - final Transaction transaction = reporter.getFirstTransaction(); + final TransactionImpl transaction = reporter.getFirstTransaction(); reporter.resetWithoutRecycling(); return transaction; } @@ -654,7 +655,7 @@ private void applyTags(Map tags, Tracer.SpanBuilder spanBuilder) { }); } - private co.elastic.apm.agent.impl.transaction.Span createSpanFromOtTags(Map tags) { + private SpanImpl createSpanFromOtTags(Map tags) { final Span transaction = apmTracer.buildSpan("transaction").start(); try (Scope transactionScope = apmTracer.activateSpan(transaction)) { final Tracer.SpanBuilder spanBuilder = apmTracer.buildSpan("transaction"); @@ -664,7 +665,7 @@ private co.elastic.apm.agent.impl.transaction.Span createSpanFromOtTags(Map> -Valid options: `EXCHANGE`, `QUEUE` +Valid options: `EXCHANGE`, `QUEUE`, `ROUTING_KEY` [options="header"] |============ @@ -4703,10 +4703,10 @@ Example: `5ms`. # # jms_listener_packages= -# Defines whether the agent should use the exchanges or the queue for the naming of RabbitMQ Transactions. Valid options are `QUEUE` and `EXCHANGE`. -# Note that `QUEUE` only works when using RabbitMQ via spring-amqp. +# Defines whether the agent should use the exchanges, the routing key or the queue for the naming of RabbitMQ Transactions. Valid options are `QUEUE`, `ROUTING_KEY` and `EXCHANGE`. +# Note that `QUEUE` only works when using RabbitMQ via spring-amqp and `ROUTING_KEY` only works for the non spring-client. # -# Valid options: EXCHANGE, QUEUE +# Valid options: EXCHANGE, QUEUE, ROUTING_KEY # This setting can be changed at runtime # Type: RabbitMQNamingMode # Default value: EXCHANGE diff --git a/docs/logs.asciidoc b/docs/logs.asciidoc index 53c5564525..f0abf66468 100644 --- a/docs/logs.asciidoc +++ b/docs/logs.asciidoc @@ -77,6 +77,10 @@ As a result, when an exception is reported to the logger: - An `error.id` is generated and injected into logger MDC for the duration of the logger invocation - Logger output will contain the `error.id` if the log format allows it (plaintext still requires some configuration) +Please note we capture the exception, not the message passed to the `logger.error`. + +To collect the message passed to the `logger.error`, you would need to ingest the logs of the application (see {apm-guide-ref}/log-correlation.html[Log correlation]). + [float] [[log-sending]] === Log sending (experimental) diff --git a/docs/troubleshooting.asciidoc b/docs/troubleshooting.asciidoc index 331219b2ad..fad18447c4 100644 --- a/docs/troubleshooting.asciidoc +++ b/docs/troubleshooting.asciidoc @@ -75,16 +75,16 @@ Each request should at least add some lines similar to these in the logs: ---- [http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.ElasticApmTracer - startTransaction '' 00-2a82cbe3df7a0208f7be6da65be260d1-05e72d045206587a-01 { [http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.ElasticApmTracer - Activating '' 00-2a82cbe3df7a0208f7be6da65be260d1-05e72d045206587a-01 on thread 66 -[http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.transaction.Span - startSpan '' 00-2a82cbe3df7a0208f7be6da65be260d1-b2ffa0401105e3d8-01 { +[http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.transaction.SpanImpl - startSpan '' 00-2a82cbe3df7a0208f7be6da65be260d1-b2ffa0401105e3d8-01 { [http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.ElasticApmTracer - Activating 'APIRestController#products' 00-2a82cbe3df7a0208f7be6da65be260d1-b2ffa0401105e3d8-01 on thread 66 -[http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.transaction.Span - startSpan '' 00-2a82cbe3df7a0208f7be6da65be260d1-49b9d805eca42ec6-01 { +[http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.transaction.SpanImpl - startSpan '' 00-2a82cbe3df7a0208f7be6da65be260d1-49b9d805eca42ec6-01 { [http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.ElasticApmTracer - Activating '' 00-2a82cbe3df7a0208f7be6da65be260d1-49b9d805eca42ec6-01 on thread 66 [http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.ElasticApmTracer - Deactivating 'SELECT' 00-2a82cbe3df7a0208f7be6da65be260d1-49b9d805eca42ec6-01 on thread 66 -[http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.transaction.Span - endSpan 'SELECT' 00-2a82cbe3df7a0208f7be6da65be260d1-49b9d805eca42ec6-01 +[http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.transaction.SpanImpl - endSpan 'SELECT' 00-2a82cbe3df7a0208f7be6da65be260d1-49b9d805eca42ec6-01 [apm-reporter] DEBUG co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Receiving SPAN event (sequence 23) [apm-reporter] DEBUG co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Starting new request to http://127.0.0.1:8200/intake/v2/events [http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.ElasticApmTracer - Deactivating 'APIRestController#products' 00-2a82cbe3df7a0208f7be6da65be260d1-b2ffa0401105e3d8-01 on thread 66 -[http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.transaction.Span - endSpan 'APIRestController#products' 00-2a82cbe3df7a0208f7be6da65be260d1-b2ffa0401105e3d8-01 +[http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.transaction.SpanImpl - endSpan 'APIRestController#products' 00-2a82cbe3df7a0208f7be6da65be260d1-b2ffa0401105e3d8-01 [apm-reporter] DEBUG co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Scheduling request timeout in 10s [apm-reporter] DEBUG co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Receiving SPAN event (sequence 24) [http-nio-8080-exec-10] DEBUG co.elastic.apm.agent.impl.ElasticApmTracer - Deactivating 'APIRestController#products' 00-2a82cbe3df7a0208f7be6da65be260d1-05e72d045206587a-01 on thread 66 diff --git a/elastic-apm-agent-java8/pom.xml b/elastic-apm-agent-java8/pom.xml index aef6d04e03..83da3b41c0 100644 --- a/elastic-apm-agent-java8/pom.xml +++ b/elastic-apm-agent-java8/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-agent-parent - 1.50.0 + 1.51.0 elastic-apm-agent-java8 diff --git a/elastic-apm-agent-premain/pom.xml b/elastic-apm-agent-premain/pom.xml index 1999c15145..c6c8572bbe 100644 --- a/elastic-apm-agent-premain/pom.xml +++ b/elastic-apm-agent-premain/pom.xml @@ -3,7 +3,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/elastic-apm-agent/pom.xml b/elastic-apm-agent/pom.xml index 68aa016355..134ee08197 100644 --- a/elastic-apm-agent/pom.xml +++ b/elastic-apm-agent/pom.xml @@ -5,7 +5,7 @@ co.elastic.apm apm-agent-parent - 1.50.0 + 1.51.0 elastic-apm-agent diff --git a/integration-tests/application-server-integration-tests/pom.xml b/integration-tests/application-server-integration-tests/pom.xml index 82820a2d88..70bbb32a9e 100644 --- a/integration-tests/application-server-integration-tests/pom.xml +++ b/integration-tests/application-server-integration-tests/pom.xml @@ -5,7 +5,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 application-server-integration-tests diff --git a/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/AbstractServletContainerIntegrationTest.java b/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/AbstractServletContainerIntegrationTest.java index 07a9b2540b..935a33ab44 100644 --- a/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/AbstractServletContainerIntegrationTest.java +++ b/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/AbstractServletContainerIntegrationTest.java @@ -28,12 +28,11 @@ import co.elastic.apm.servlet.tests.TestApp; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dockerjava.api.command.StopContainerCmd; import okhttp3.Headers; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.RequestBody; import okhttp3.Response; -import okhttp3.ResponseBody; import okhttp3.logging.HttpLoggingInterceptor; import org.junit.After; import org.junit.Test; @@ -49,7 +48,13 @@ import java.io.IOException; import java.nio.file.Paths; import java.time.Duration; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -176,23 +181,10 @@ protected AbstractServletContainerIntegrationTest(AgentTestContainer.AppServer c container.start(); if (runtimeAttachSupported()) { - if (AGENT_VERSION_TO_DOWNLOAD_FROM_MAVEN != null) { - container.startCliRuntimeAttach(AGENT_VERSION_TO_DOWNLOAD_FROM_MAVEN); - } else { - container.startCliRuntimeAttach(AGENT_VERSION_TO_DOWNLOAD_FROM_MAVEN); - } + container.startCliRuntimeAttach(AGENT_VERSION_TO_DOWNLOAD_FROM_MAVEN); } } - private static OkHttpClient setupHttpClient(boolean isDebug) { - final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(logger::info); - loggingInterceptor.setLevel(isDebug ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.BASIC); - return new OkHttpClient.Builder() - .addInterceptor(loggingInterceptor) - .readTimeout(isDebug ? 0 : 10, TimeUnit.SECONDS) - .build(); - } - protected void beforeContainerStart(AgentTestContainer.AppServer container) { } @@ -216,9 +208,13 @@ protected boolean runtimeAttachSupported() { @After public final void stopServer() { - container.getDockerClient() - .stopContainerCmd(container.getContainerId()) - .exec(); + if (!container.isRunning()) { + return; // prevent NPE on container.getContainerId() + } + // allow graceful shutdown before killing and removing the container + try (StopContainerCmd stopContainerCmd = container.getDockerClient().stopContainerCmd(container.getContainerId())) { + stopContainerCmd.exec(); + } container.stop(); } @@ -271,29 +267,29 @@ public JsonNode assertTransactionReported(String pathToTest, int expectedRespons return transaction; } - public String executeAndValidateRequest(String pathToTest, String expectedContent, Integer expectedResponseCode, + public void executeAndValidateRequest(String pathToTest, String expectedContent, Integer expectedResponseCode, Map headersMap) throws IOException, InterruptedException { - Response response = executeRequest(pathToTest, headersMap); - if (expectedResponseCode != null) { - assertThat(response.code()) - .withFailMessage(response.toString() + getServerLogs()) - .isEqualTo(expectedResponseCode); + final String responseString; + try (Response response = executeRequest(pathToTest, headersMap)) { + if (expectedResponseCode != null) { + assertThat(response.code()) + .withFailMessage(response + getServerLogs()) + .isEqualTo(expectedResponseCode); + } + responseString = response.body().string(); } - final ResponseBody responseBody = response.body(); - assertThat(responseBody).isNotNull(); - String responseString = responseBody.string(); if (expectedContent != null) { assertThat(responseString) .describedAs("unexpected response content") .contains(expectedContent); } - return responseString; } private void executeStatusRequestAndCheckIgnored(String statusEndpoint) throws IOException { Map headers = Collections.emptyMap(); - Response response = executeRequest(statusEndpoint, headers); - assertThat(response.code()).isEqualTo(200); + try (Response response = executeRequest(statusEndpoint, headers)) { + assertThat(response.code()).isEqualTo(200); + } try { Thread.sleep(200); @@ -308,33 +304,6 @@ private void executeStatusRequestAndCheckIgnored(String statusEndpoint) throws I } - public String executeAndValidatePostRequest(String pathToTest, RequestBody postBody, String expectedContent, Integer expectedResponseCode) throws IOException, InterruptedException { - Response response = executePostRequest(pathToTest, postBody); - if (expectedResponseCode != null) { - assertThat(response.code()) - .withFailMessage(response.toString() + getServerLogs()) - .isEqualTo(expectedResponseCode); - } - final ResponseBody responseBody = response.body(); - assertThat(responseBody).isNotNull(); - String responseString = responseBody.string(); - if (expectedContent != null) { - assertThat(responseString).contains(expectedContent); - } - return responseString; - } - - public Response executePostRequest(String pathToTest, RequestBody postBody) throws IOException { - if (!pathToTest.startsWith("/")) { - pathToTest = "/" + pathToTest; - } - return httpClient.newCall(new Request.Builder() - .post(postBody) - .url(getBaseUrl() + pathToTest) - .build()) - .execute(); - } - public Response executeRequest(String pathToTest, Map headersMap) throws IOException { Headers headers = Headers.of((headersMap != null) ? headersMap : new HashMap<>()); if (!pathToTest.startsWith("/")) { @@ -368,7 +337,7 @@ public List assertSpansTransactionId(Supplier> supplier List reportedSpans; do { reportedSpans = supplier.get(); - } while (reportedSpans.size() == 0 && System.currentTimeMillis() - start < timeout); + } while (reportedSpans.isEmpty() && System.currentTimeMillis() - start < timeout); assertThat(reportedSpans) .describedAs("at least one span is expected") .isNotEmpty(); @@ -386,7 +355,7 @@ public List assertErrorContent(int timeoutMs, Supplier> List reportedErrors; do { reportedErrors = supplier.get(); - } while (reportedErrors.size() == 0 && System.currentTimeMillis() - start < timeoutMs); + } while (reportedErrors.isEmpty() && System.currentTimeMillis() - start < timeoutMs); assertThat(reportedErrors.size()).isEqualTo(1); for (JsonNode error : reportedErrors) { assertThat(error.get("transaction_id").textValue()).isEqualTo(transactionId); @@ -529,16 +498,6 @@ private void validateMetadataEvent(JsonNode metadata) { assertThat(jsonContainer.get("id").textValue()).isEqualTo(container.getContainerId()); } - private void addSpans(List spans, JsonNode payload) { - final JsonNode jsonSpans = payload.get("spans"); - if (jsonSpans != null) { - for (JsonNode jsonSpan : jsonSpans) { - mockReporter.verifyTransactionSchema(jsonSpan); - spans.add(jsonSpan); - } - } - } - private void waitFor(String path) { Wait.forHttp(path) .forPort(webPort) @@ -550,8 +509,4 @@ private void waitFor(String path) { public OkHttpClient getHttpClient() { return httpClient; } - - public boolean isHotSpotBased() { - return true; - } } diff --git a/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/WebSphereIT.java b/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/WebSphereIT.java index aab9cb0e74..58583b2312 100644 --- a/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/WebSphereIT.java +++ b/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/WebSphereIT.java @@ -52,11 +52,6 @@ public boolean isExpectedStacktrace(String path) { return true; } - @Override - public boolean isHotSpotBased() { - return false; - } - @Override protected Iterable> getTestClasses() { return Arrays.asList( diff --git a/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/tests/ExternalPluginTestApp.java b/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/tests/ExternalPluginTestApp.java index d6c895d66e..aa63be7b87 100644 --- a/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/tests/ExternalPluginTestApp.java +++ b/integration-tests/application-server-integration-tests/src/test/java/co/elastic/apm/servlet/tests/ExternalPluginTestApp.java @@ -19,7 +19,6 @@ package co.elastic.apm.servlet.tests; import co.elastic.apm.agent.tracer.service.ServiceInfo; -import co.elastic.apm.agent.impl.Tracer; import co.elastic.apm.agent.tracer.Outcome; import co.elastic.apm.servlet.AbstractServletContainerIntegrationTest; import com.fasterxml.jackson.databind.JsonNode; @@ -91,7 +90,7 @@ private void executeTest(final AbstractServletContainerIntegrationTest container /** * Since we test custom transaction creation through the external plugin, the service name for this transaction cannot be - * captured through the {@link Tracer#setServiceInfoForClassLoader(ClassLoader, ServiceInfo)} mechanism. + * captured through the {@link co.elastic.apm.agent.impl.ElasticApmTracer#setServiceInfoForClassLoader(ClassLoader, ServiceInfo)} mechanism. */ @Nullable @Override diff --git a/integration-tests/aws-lambda-test/pom.xml b/integration-tests/aws-lambda-test/pom.xml index fdf85cf0b3..b1728f2948 100644 --- a/integration-tests/aws-lambda-test/pom.xml +++ b/integration-tests/aws-lambda-test/pom.xml @@ -3,7 +3,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/aws-lambda-test/src/test/java/co/elastic/apm/awslambda/AwsLambdaIT.java b/integration-tests/aws-lambda-test/src/test/java/co/elastic/apm/awslambda/AwsLambdaIT.java index 15f41099ed..53a72c7a02 100644 --- a/integration-tests/aws-lambda-test/src/test/java/co/elastic/apm/awslambda/AwsLambdaIT.java +++ b/integration-tests/aws-lambda-test/src/test/java/co/elastic/apm/awslambda/AwsLambdaIT.java @@ -187,7 +187,7 @@ private static String createLambdaImage() throws IOException { ImageFromDockerfile imageBuilder = new ImageFromDockerfile().withDockerfileFromBuilder(builder -> { builder - .withStatement(raw("FROM docker.elastic.co/observability/apm-lambda-extension-x86_64:latest AS lambda-extension")) + .withStatement(raw("FROM docker.elastic.co/observability/apm-lambda-extension-x86_64:1.5.5 AS lambda-extension")) .withStatement(raw("FROM --platform=linux/amd64 public.ecr.aws/lambda/java:11")) .withStatement(raw("COPY --from=lambda-extension /opt/elastic-apm-extension /opt/extensions/elastic-apm-extension")) .copy("aws-lambda-test.jar", "${LAMBDA_TASK_ROOT}/lib/aws-lambda-test.jar") diff --git a/integration-tests/cdi-app/cdi-app-dependent/pom.xml b/integration-tests/cdi-app/cdi-app-dependent/pom.xml index 44f7de312f..4842df8962 100644 --- a/integration-tests/cdi-app/cdi-app-dependent/pom.xml +++ b/integration-tests/cdi-app/cdi-app-dependent/pom.xml @@ -4,7 +4,7 @@ cdi-app co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/cdi-app/cdi-app-standalone/pom.xml b/integration-tests/cdi-app/cdi-app-standalone/pom.xml index 898613e7d5..2f415ee34d 100644 --- a/integration-tests/cdi-app/cdi-app-standalone/pom.xml +++ b/integration-tests/cdi-app/cdi-app-standalone/pom.xml @@ -4,7 +4,7 @@ cdi-app co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/cdi-app/pom.xml b/integration-tests/cdi-app/pom.xml index e8901415ec..c245dbf868 100644 --- a/integration-tests/cdi-app/pom.xml +++ b/integration-tests/cdi-app/pom.xml @@ -4,7 +4,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/cdi-jakartaee-app/cdi-jakartaee-app-dependent/pom.xml b/integration-tests/cdi-jakartaee-app/cdi-jakartaee-app-dependent/pom.xml index 1d1fd49f6b..b790110f6f 100644 --- a/integration-tests/cdi-jakartaee-app/cdi-jakartaee-app-dependent/pom.xml +++ b/integration-tests/cdi-jakartaee-app/cdi-jakartaee-app-dependent/pom.xml @@ -4,7 +4,7 @@ cdi-jakartaee-app co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/cdi-jakartaee-app/cdi-jakartaee-app-standalone/pom.xml b/integration-tests/cdi-jakartaee-app/cdi-jakartaee-app-standalone/pom.xml index 1acf274a05..b1baffd663 100644 --- a/integration-tests/cdi-jakartaee-app/cdi-jakartaee-app-standalone/pom.xml +++ b/integration-tests/cdi-jakartaee-app/cdi-jakartaee-app-standalone/pom.xml @@ -4,7 +4,7 @@ cdi-jakartaee-app co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/cdi-jakartaee-app/pom.xml b/integration-tests/cdi-jakartaee-app/pom.xml index 443a36bcc3..695b9b2b01 100644 --- a/integration-tests/cdi-jakartaee-app/pom.xml +++ b/integration-tests/cdi-jakartaee-app/pom.xml @@ -4,7 +4,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/external-plugin-otel-test/external-plugin-otel-test-app/pom.xml b/integration-tests/external-plugin-otel-test/external-plugin-otel-test-app/pom.xml index 339af4c9a0..b1fac537a6 100644 --- a/integration-tests/external-plugin-otel-test/external-plugin-otel-test-app/pom.xml +++ b/integration-tests/external-plugin-otel-test/external-plugin-otel-test-app/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm external-plugin-otel-test - 1.50.0 + 1.51.0 external-plugin-otel-test-app diff --git a/integration-tests/external-plugin-otel-test/external-plugin-otel-test-plugin1/pom.xml b/integration-tests/external-plugin-otel-test/external-plugin-otel-test-plugin1/pom.xml index a8be113b93..4fc925fe5a 100644 --- a/integration-tests/external-plugin-otel-test/external-plugin-otel-test-plugin1/pom.xml +++ b/integration-tests/external-plugin-otel-test/external-plugin-otel-test-plugin1/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm external-plugin-otel-test - 1.50.0 + 1.51.0 external-plugin-otel-test-plugin1 diff --git a/integration-tests/external-plugin-otel-test/external-plugin-otel-test-plugin2/pom.xml b/integration-tests/external-plugin-otel-test/external-plugin-otel-test-plugin2/pom.xml index 132c1aecbe..c5177b8175 100644 --- a/integration-tests/external-plugin-otel-test/external-plugin-otel-test-plugin2/pom.xml +++ b/integration-tests/external-plugin-otel-test/external-plugin-otel-test-plugin2/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm external-plugin-otel-test - 1.50.0 + 1.51.0 external-plugin-otel-test-plugin2 diff --git a/integration-tests/external-plugin-otel-test/pom.xml b/integration-tests/external-plugin-otel-test/pom.xml index 7fd42deda7..de48233231 100644 --- a/integration-tests/external-plugin-otel-test/pom.xml +++ b/integration-tests/external-plugin-otel-test/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm integration-tests - 1.50.0 + 1.51.0 external-plugin-otel-test diff --git a/integration-tests/external-plugin-test/external-plugin-app/pom.xml b/integration-tests/external-plugin-test/external-plugin-app/pom.xml index b4811ec052..ccc7bcc592 100644 --- a/integration-tests/external-plugin-test/external-plugin-app/pom.xml +++ b/integration-tests/external-plugin-test/external-plugin-app/pom.xml @@ -6,7 +6,7 @@ external-plugin-test co.elastic.apm - 1.50.0 + 1.51.0 external-plugin-app diff --git a/integration-tests/external-plugin-test/external-plugin-jakarta-app/pom.xml b/integration-tests/external-plugin-test/external-plugin-jakarta-app/pom.xml index 25964284a9..e950b44bf6 100644 --- a/integration-tests/external-plugin-test/external-plugin-jakarta-app/pom.xml +++ b/integration-tests/external-plugin-test/external-plugin-jakarta-app/pom.xml @@ -6,7 +6,7 @@ external-plugin-test co.elastic.apm - 1.50.0 + 1.51.0 external-plugin-jakarta-app diff --git a/integration-tests/external-plugin-test/external-plugin/pom.xml b/integration-tests/external-plugin-test/external-plugin/pom.xml index 36cf72cb41..dd8b212dfb 100644 --- a/integration-tests/external-plugin-test/external-plugin/pom.xml +++ b/integration-tests/external-plugin-test/external-plugin/pom.xml @@ -6,7 +6,7 @@ external-plugin-test co.elastic.apm - 1.50.0 + 1.51.0 external-plugin diff --git a/integration-tests/external-plugin-test/external-plugin/src/test/java/co/elastic/apm/agent/plugin/PluginInstrumentationTest.java b/integration-tests/external-plugin-test/external-plugin/src/test/java/co/elastic/apm/agent/plugin/PluginInstrumentationTest.java index 45b6078850..1a4b0fc98a 100644 --- a/integration-tests/external-plugin-test/external-plugin/src/test/java/co/elastic/apm/agent/plugin/PluginInstrumentationTest.java +++ b/integration-tests/external-plugin-test/external-plugin/src/test/java/co/elastic/apm/agent/plugin/PluginInstrumentationTest.java @@ -19,8 +19,8 @@ package co.elastic.apm.agent.plugin; import co.elastic.apm.agent.AbstractInstrumentationTest; -import co.elastic.apm.agent.impl.transaction.Span; -import co.elastic.apm.agent.impl.transaction.Transaction; +import co.elastic.apm.agent.impl.transaction.SpanImpl; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.plugin.test.TestClass; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -61,7 +61,7 @@ void testSpanCreation() { // using custom span type/sub-type not part of shared spec reporter.disableCheckStrictSpanType(); - Transaction transaction = tracer.startRootTransaction(null); + TransactionImpl transaction = tracer.startRootTransaction(null); Objects.requireNonNull(transaction).activate() .withName("Plugin test transaction") .withType("request"); @@ -69,7 +69,7 @@ void testSpanCreation() { transaction.deactivate().end(); assertThat(reporter.getTransactions()).hasSize(1); assertThat(reporter.getSpans()).hasSize(1); - Span span = reporter.getFirstSpan(); + SpanImpl span = reporter.getFirstSpan(); assertThat(span.getNameAsString()).isEqualTo("traceMe"); assertThat(span.getType()).isEqualTo("plugin"); assertThat(span.getSubtype()).isEqualTo("external"); @@ -85,7 +85,7 @@ void testErrorCreation() { // do nothing - expected } assertThat(reporter.getTransactions()).hasSize(1); - Transaction transaction = reporter.getFirstTransaction(); + TransactionImpl transaction = reporter.getFirstTransaction(); assertThat(transaction.getNameAsString()).isEqualTo("TestClass#traceMe"); assertThat(reporter.getErrors()).hasSize(1); assertThat(reporter.getFirstError().getTraceContext().getTransactionId()).isEqualTo(transaction.getTraceContext().getId()); diff --git a/integration-tests/external-plugin-test/plugin-instrumentation-target/pom.xml b/integration-tests/external-plugin-test/plugin-instrumentation-target/pom.xml index 3df71f6747..9d55c90014 100644 --- a/integration-tests/external-plugin-test/plugin-instrumentation-target/pom.xml +++ b/integration-tests/external-plugin-test/plugin-instrumentation-target/pom.xml @@ -6,7 +6,7 @@ external-plugin-test co.elastic.apm - 1.50.0 + 1.51.0 plugin-instrumentation-target diff --git a/integration-tests/external-plugin-test/pom.xml b/integration-tests/external-plugin-test/pom.xml index 4fb222afad..9e581dc055 100644 --- a/integration-tests/external-plugin-test/pom.xml +++ b/integration-tests/external-plugin-test/pom.xml @@ -3,7 +3,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/jakartaee-jsf-app/jakartaee-jsf-app-dependent/pom.xml b/integration-tests/jakartaee-jsf-app/jakartaee-jsf-app-dependent/pom.xml index 705842408a..b5d834c068 100644 --- a/integration-tests/jakartaee-jsf-app/jakartaee-jsf-app-dependent/pom.xml +++ b/integration-tests/jakartaee-jsf-app/jakartaee-jsf-app-dependent/pom.xml @@ -3,7 +3,7 @@ jakartaee-jsf-app co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/jakartaee-jsf-app/jakartaee-jsf-app-standalone/pom.xml b/integration-tests/jakartaee-jsf-app/jakartaee-jsf-app-standalone/pom.xml index b5868ae9a9..f29235947f 100644 --- a/integration-tests/jakartaee-jsf-app/jakartaee-jsf-app-standalone/pom.xml +++ b/integration-tests/jakartaee-jsf-app/jakartaee-jsf-app-standalone/pom.xml @@ -3,7 +3,7 @@ jakartaee-jsf-app co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/jakartaee-jsf-app/pom.xml b/integration-tests/jakartaee-jsf-app/pom.xml index cbef6dc370..62c48fa9d4 100644 --- a/integration-tests/jakartaee-jsf-app/pom.xml +++ b/integration-tests/jakartaee-jsf-app/pom.xml @@ -3,7 +3,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 pom diff --git a/integration-tests/jakartaee-simple-webapp/pom.xml b/integration-tests/jakartaee-simple-webapp/pom.xml index 1378d58577..6ccd877da9 100644 --- a/integration-tests/jakartaee-simple-webapp/pom.xml +++ b/integration-tests/jakartaee-simple-webapp/pom.xml @@ -5,7 +5,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 jakartaee-simple-webapp diff --git a/integration-tests/jsf-app/jsf-app-dependent/pom.xml b/integration-tests/jsf-app/jsf-app-dependent/pom.xml index 470499a693..32ce0be4c5 100644 --- a/integration-tests/jsf-app/jsf-app-dependent/pom.xml +++ b/integration-tests/jsf-app/jsf-app-dependent/pom.xml @@ -4,7 +4,7 @@ jsf-app co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/jsf-app/jsf-app-standalone/pom.xml b/integration-tests/jsf-app/jsf-app-standalone/pom.xml index 4741b6bdff..4a7d0b9d5b 100644 --- a/integration-tests/jsf-app/jsf-app-standalone/pom.xml +++ b/integration-tests/jsf-app/jsf-app-standalone/pom.xml @@ -6,7 +6,7 @@ jsf-app co.elastic.apm - 1.50.0 + 1.51.0 jsf-app-standalone diff --git a/integration-tests/jsf-app/pom.xml b/integration-tests/jsf-app/pom.xml index 2c1df05851..d1f0f11220 100644 --- a/integration-tests/jsf-app/pom.xml +++ b/integration-tests/jsf-app/pom.xml @@ -6,7 +6,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 jsf-app diff --git a/integration-tests/main-app-test/pom.xml b/integration-tests/main-app-test/pom.xml index e0cf9ea29b..8963bd8dc7 100644 --- a/integration-tests/main-app-test/pom.xml +++ b/integration-tests/main-app-test/pom.xml @@ -5,7 +5,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 main-app-test diff --git a/integration-tests/main-app-test/src/test/java/co/elastic/apm/test/AgentSetupIT.java b/integration-tests/main-app-test/src/test/java/co/elastic/apm/test/AgentSetupIT.java index 28924ada91..fac320dffe 100644 --- a/integration-tests/main-app-test/src/test/java/co/elastic/apm/test/AgentSetupIT.java +++ b/integration-tests/main-app-test/src/test/java/co/elastic/apm/test/AgentSetupIT.java @@ -41,6 +41,7 @@ class AgentSetupIT { @ParameterizedTest @CsvSource({ + "openjdk:7,STANDARD", "openjdk:8,STANDARD", "openjdk:8,JAVA8_BUILD", "openjdk:11,STANDARD", diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 7014733ac5..82becf7ec0 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -5,7 +5,7 @@ apm-agent-parent co.elastic.apm - 1.50.0 + 1.51.0 integration-tests diff --git a/integration-tests/quarkus/pom.xml b/integration-tests/quarkus/pom.xml index 5324b86fd8..f99d81e2a4 100644 --- a/integration-tests/quarkus/pom.xml +++ b/integration-tests/quarkus/pom.xml @@ -5,7 +5,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 quarkus diff --git a/integration-tests/quarkus/quarkus-jaxrs-base/pom.xml b/integration-tests/quarkus/quarkus-jaxrs-base/pom.xml index 36718d89a3..fb85b6e8b3 100644 --- a/integration-tests/quarkus/quarkus-jaxrs-base/pom.xml +++ b/integration-tests/quarkus/quarkus-jaxrs-base/pom.xml @@ -5,7 +5,7 @@ quarkus co.elastic.apm - 1.50.0 + 1.51.0 quarkus-jaxrs-base diff --git a/integration-tests/quarkus/quarkus-jaxrs-undertow/pom.xml b/integration-tests/quarkus/quarkus-jaxrs-undertow/pom.xml index dc369dde3c..b8b1e84594 100644 --- a/integration-tests/quarkus/quarkus-jaxrs-undertow/pom.xml +++ b/integration-tests/quarkus/quarkus-jaxrs-undertow/pom.xml @@ -5,7 +5,7 @@ quarkus co.elastic.apm - 1.50.0 + 1.51.0 quarkus-jaxrs-undertow diff --git a/integration-tests/quarkus/quarkus-jaxrs-vertx/pom.xml b/integration-tests/quarkus/quarkus-jaxrs-vertx/pom.xml index 4c0633bdd3..84a96c200e 100644 --- a/integration-tests/quarkus/quarkus-jaxrs-vertx/pom.xml +++ b/integration-tests/quarkus/quarkus-jaxrs-vertx/pom.xml @@ -5,7 +5,7 @@ quarkus co.elastic.apm - 1.50.0 + 1.51.0 quarkus-jaxrs-vertx diff --git a/integration-tests/runtime-attach/pom.xml b/integration-tests/runtime-attach/pom.xml index 16e1cbdce3..500df790f8 100644 --- a/integration-tests/runtime-attach/pom.xml +++ b/integration-tests/runtime-attach/pom.xml @@ -6,7 +6,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 runtime-attach diff --git a/integration-tests/runtime-attach/runtime-attach-app/pom.xml b/integration-tests/runtime-attach/runtime-attach-app/pom.xml index a057cf4640..936f4738c5 100644 --- a/integration-tests/runtime-attach/runtime-attach-app/pom.xml +++ b/integration-tests/runtime-attach/runtime-attach-app/pom.xml @@ -3,7 +3,7 @@ runtime-attach co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/runtime-attach/runtime-attach-app/src/main/java/co/elastic/apm/testapp/AppMain.java b/integration-tests/runtime-attach/runtime-attach-app/src/main/java/co/elastic/apm/testapp/AppMain.java index 2e43ef010a..d02f1c776a 100644 --- a/integration-tests/runtime-attach/runtime-attach-app/src/main/java/co/elastic/apm/testapp/AppMain.java +++ b/integration-tests/runtime-attach/runtime-attach-app/src/main/java/co/elastic/apm/testapp/AppMain.java @@ -79,6 +79,10 @@ public static void main(String[] args) { Map config = new HashMap<>(); config.put("service_name", "self-attach-external-config"); config.put("config_file", agentConfig.getAbsolutePath()); + + // user-provided map might have null values and be un-modifiable + // thus we must test it to ensure it's working as expected + config.put("null_config_entry", null); ElasticApmAttacher.attach(Collections.unmodifiableMap(config)); } } diff --git a/integration-tests/runtime-attach/runtime-attach-test/pom.xml b/integration-tests/runtime-attach/runtime-attach-test/pom.xml index 42f97c9930..e14cd7b2ef 100644 --- a/integration-tests/runtime-attach/runtime-attach-test/pom.xml +++ b/integration-tests/runtime-attach/runtime-attach-test/pom.xml @@ -3,7 +3,7 @@ runtime-attach co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/simple-webapp/pom.xml b/integration-tests/simple-webapp/pom.xml index b89a4e3079..99490c2647 100644 --- a/integration-tests/simple-webapp/pom.xml +++ b/integration-tests/simple-webapp/pom.xml @@ -6,7 +6,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 simple-webapp diff --git a/integration-tests/soap-test/pom.xml b/integration-tests/soap-test/pom.xml index e8d92aede0..a87746df9a 100644 --- a/integration-tests/soap-test/pom.xml +++ b/integration-tests/soap-test/pom.xml @@ -5,7 +5,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 soap-test diff --git a/integration-tests/spring-boot-1-5/pom.xml b/integration-tests/spring-boot-1-5/pom.xml index 01ec861069..ead5000301 100644 --- a/integration-tests/spring-boot-1-5/pom.xml +++ b/integration-tests/spring-boot-1-5/pom.xml @@ -5,7 +5,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 spring-boot-1-5 diff --git a/integration-tests/spring-boot-1-5/src/test/java/co/elastic/apm/spring/boot/SpringBoot1_5IT.java b/integration-tests/spring-boot-1-5/src/test/java/co/elastic/apm/spring/boot/SpringBoot1_5IT.java index d30bf03dc8..8450d52e52 100644 --- a/integration-tests/spring-boot-1-5/src/test/java/co/elastic/apm/spring/boot/SpringBoot1_5IT.java +++ b/integration-tests/spring-boot-1-5/src/test/java/co/elastic/apm/spring/boot/SpringBoot1_5IT.java @@ -21,8 +21,8 @@ import co.elastic.apm.agent.MockReporter; import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; import net.bytebuddy.agent.ByteBuddyAgent; import org.junit.After; import org.junit.Before; @@ -76,7 +76,7 @@ public void greetingShouldReturnDefaultMessage() throws Exception { // the transaction might not have been reported yet, as the http call returns when the ServletOutputStream has been closed, // which is before the transaction has ended - Transaction firstTransaction = reporter.getFirstTransaction(500); + TransactionImpl firstTransaction = reporter.getFirstTransaction(500); assertThat(firstTransaction.getNameAsString()).isEqualTo("TestApp#greeting"); assertThat(firstTransaction.getFrameworkName()).isEqualTo("Spring Web MVC"); assertThat(firstTransaction.getFrameworkVersion()).isEqualTo("4.3.25.RELEASE"); @@ -88,7 +88,7 @@ public void testStaticFile() throws Exception { assertThat(restTemplate.getForObject("http://localhost:" + port + "/script.js", String.class)) .contains("// empty test script"); - Transaction firstTransaction = reporter.getFirstTransaction(500); + TransactionImpl firstTransaction = reporter.getFirstTransaction(500); assertThat(firstTransaction.getNameAsString()).isEqualTo("ResourceHttpRequestHandler"); assertThat(firstTransaction.getFrameworkName()).isEqualTo("Spring Web MVC"); assertThat(firstTransaction.getFrameworkVersion()).isEqualTo("4.3.25.RELEASE"); diff --git a/integration-tests/spring-boot-2/pom.xml b/integration-tests/spring-boot-2/pom.xml index 11d638ecdf..d2359485cf 100644 --- a/integration-tests/spring-boot-2/pom.xml +++ b/integration-tests/spring-boot-2/pom.xml @@ -5,7 +5,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 spring-boot-2 diff --git a/integration-tests/spring-boot-2/spring-boot-2-base/pom.xml b/integration-tests/spring-boot-2/spring-boot-2-base/pom.xml index 5482fb6465..986614268d 100644 --- a/integration-tests/spring-boot-2/spring-boot-2-base/pom.xml +++ b/integration-tests/spring-boot-2/spring-boot-2-base/pom.xml @@ -5,7 +5,7 @@ spring-boot-2 co.elastic.apm - 1.50.0 + 1.51.0 spring-boot-2-base diff --git a/integration-tests/spring-boot-2/spring-boot-2-base/src/test/java/co/elastic/apm/spring/boot/AbstractSpringBootTest.java b/integration-tests/spring-boot-2/spring-boot-2-base/src/test/java/co/elastic/apm/spring/boot/AbstractSpringBootTest.java index f2a8ba116b..7c816b8b72 100644 --- a/integration-tests/spring-boot-2/spring-boot-2-base/src/test/java/co/elastic/apm/spring/boot/AbstractSpringBootTest.java +++ b/integration-tests/spring-boot-2/spring-boot-2-base/src/test/java/co/elastic/apm/spring/boot/AbstractSpringBootTest.java @@ -22,8 +22,8 @@ import co.elastic.apm.agent.MockTracer; import co.elastic.apm.agent.bci.ElasticApmAgent; import co.elastic.apm.agent.tracer.configuration.WebConfiguration; -import co.elastic.apm.agent.impl.transaction.Transaction; -import co.elastic.apm.agent.report.ReporterConfiguration; +import co.elastic.apm.agent.impl.transaction.TransactionImpl; +import co.elastic.apm.agent.report.ReporterConfigurationImpl; import co.elastic.apm.api.ElasticApm; import net.bytebuddy.agent.ByteBuddyAgent; import org.junit.AfterClass; @@ -76,7 +76,7 @@ public static void beforeClass() { @Before public void setUp() { - doReturn(true).when(config.getConfig(ReporterConfiguration.class)).isReportSynchronously(); + doReturn(true).when(config.getConfig(ReporterConfigurationImpl.class)).isReportSynchronously(); restTemplate = new TestRestTemplate(new RestTemplateBuilder() .setConnectTimeout(Duration.ofSeconds(10)) .setReadTimeout(Duration.ofSeconds(10)) @@ -96,7 +96,7 @@ public void greetingShouldReturnDefaultMessage() throws Exception { // the transaction might not have been reported yet, as the http call returns when the ServletOutputStream has been closed, // which is before the transaction has ended - final Transaction transaction = reporter.getFirstTransaction(500); + final TransactionImpl transaction = reporter.getFirstTransaction(500); assertThat(transaction.getNameAsString()).isEqualTo("TestApp#greeting"); assertThat(transaction.getContext().getUser().getDomain()).isEqualTo("domain"); assertThat(transaction.getContext().getUser().getId()).isEqualTo("id"); diff --git a/integration-tests/spring-boot-2/spring-boot-2-jetty/pom.xml b/integration-tests/spring-boot-2/spring-boot-2-jetty/pom.xml index 1bb93331ff..b74c5aed23 100644 --- a/integration-tests/spring-boot-2/spring-boot-2-jetty/pom.xml +++ b/integration-tests/spring-boot-2/spring-boot-2-jetty/pom.xml @@ -5,7 +5,7 @@ spring-boot-2 co.elastic.apm - 1.50.0 + 1.51.0 spring-boot-2-jetty diff --git a/integration-tests/spring-boot-2/spring-boot-2-tomcat/pom.xml b/integration-tests/spring-boot-2/spring-boot-2-tomcat/pom.xml index 5266069473..256f073736 100644 --- a/integration-tests/spring-boot-2/spring-boot-2-tomcat/pom.xml +++ b/integration-tests/spring-boot-2/spring-boot-2-tomcat/pom.xml @@ -5,7 +5,7 @@ spring-boot-2 co.elastic.apm - 1.50.0 + 1.51.0 spring-boot-2-tomcat diff --git a/integration-tests/spring-boot-2/spring-boot-2-undertow/pom.xml b/integration-tests/spring-boot-2/spring-boot-2-undertow/pom.xml index 4095e0de77..954641719b 100644 --- a/integration-tests/spring-boot-2/spring-boot-2-undertow/pom.xml +++ b/integration-tests/spring-boot-2/spring-boot-2-undertow/pom.xml @@ -5,7 +5,7 @@ spring-boot-2 co.elastic.apm - 1.50.0 + 1.51.0 spring-boot-2-undertow diff --git a/integration-tests/spring-boot-3/pom.xml b/integration-tests/spring-boot-3/pom.xml index 03b106e517..273fbb2f71 100644 --- a/integration-tests/spring-boot-3/pom.xml +++ b/integration-tests/spring-boot-3/pom.xml @@ -5,7 +5,7 @@ integration-tests co.elastic.apm - 1.50.0 + 1.51.0 spring-boot-3 @@ -30,7 +30,7 @@ org.springframework.boot spring-boot-dependencies - 3.2.5 + 3.3.2 pom import diff --git a/integration-tests/spring-boot-3/spring-boot-3-jetty/pom.xml b/integration-tests/spring-boot-3/spring-boot-3-jetty/pom.xml index 4d478cb8df..757a5a2761 100644 --- a/integration-tests/spring-boot-3/spring-boot-3-jetty/pom.xml +++ b/integration-tests/spring-boot-3/spring-boot-3-jetty/pom.xml @@ -3,7 +3,7 @@ spring-boot-3 co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/spring-boot-3/spring-boot-3-tomcat/pom.xml b/integration-tests/spring-boot-3/spring-boot-3-tomcat/pom.xml index 28a0181665..d54d220f5d 100644 --- a/integration-tests/spring-boot-3/spring-boot-3-tomcat/pom.xml +++ b/integration-tests/spring-boot-3/spring-boot-3-tomcat/pom.xml @@ -3,7 +3,7 @@ spring-boot-3 co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/integration-tests/spring-boot-3/spring-boot-3-undertow/pom.xml b/integration-tests/spring-boot-3/spring-boot-3-undertow/pom.xml index b681351d62..db37828256 100644 --- a/integration-tests/spring-boot-3/spring-boot-3-undertow/pom.xml +++ b/integration-tests/spring-boot-3/spring-boot-3-undertow/pom.xml @@ -3,7 +3,7 @@ spring-boot-3 co.elastic.apm - 1.50.0 + 1.51.0 4.0.0 diff --git a/pom.xml b/pom.xml index c38b5c189d..8d039d00c3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ co.elastic.apm apm-agent-parent - 1.50.0 + 1.51.0 pom ${project.groupId}:${project.artifactId} @@ -116,7 +116,6 @@ 2.2.0 1.4.196 - 2.14.2 5.9.1 4.13.2 4.12.0 @@ -129,10 +128,10 @@ 1.6.0 5.0.15.RELEASE 9.4.11.v20180605 - 1.4.0 + 1.5.0 - 1.14.14 - 9.6 + 1.14.18 + 9.7 5.4.0 5.12.0 @@ -665,6 +664,13 @@ pom import + + com.fasterxml.jackson + jackson-bom + 2.17.1 + import + pom + org.apache.ivy ivy @@ -748,7 +754,7 @@ org.assertj assertj-core - 3.25.3 + 3.26.3 test @@ -791,7 +797,6 @@ com.fasterxml.jackson.core jackson-databind - ${version.jackson} test diff --git a/scripts/docker-release/build_docker.sh b/scripts/docker-release/build_docker.sh index 39dcab2391..accc366ee2 100755 --- a/scripts/docker-release/build_docker.sh +++ b/scripts/docker-release/build_docker.sh @@ -18,7 +18,9 @@ readonly SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )" readonly PROJECT_ROOT=$SCRIPT_PATH/../../ readonly NAMESPACE="observability" +set +e FILE=$(ls -A ${PROJECT_ROOT}elastic-apm-agent/target/*.jar | grep -E "elastic-apm-agent-[0-9]+.[0-9]+.[0-9]+(-SNAPSHOT)?.jar" ) +set -e if [ -n "${FILE}" ] then diff --git a/update-compose.yaml b/update-compose.yaml new file mode 100644 index 0000000000..372d29ed58 --- /dev/null +++ b/update-compose.yaml @@ -0,0 +1,23 @@ +# Config file for `updatecli compose ...`. +# https://www.updatecli.io/docs/core/compose/ +policies: + - name: Handle apm-data server specs + policy: ghcr.io/elastic/oblt-updatecli-policies/apm/apm-data-spec:0.3.0@sha256:e7cdc38653afecaf9fad748356f545da6eb48bb9262665ff563cda974defb6f5 + values: + - .ci/updatecli/values.d/scm.yml + - .ci/updatecli/values.d/apm-data-spec.yml + - name: Handle apm gherkin specs + policy: ghcr.io/elastic/oblt-updatecli-policies/apm/apm-gherkin:0.3.0@sha256:b8fae37245a5fa99482b3700a53681196c4b42685153d93452f7103bbaf4a5f3 + values: + - .ci/updatecli/values.d/scm.yml + - .ci/updatecli/values.d/apm-gherkin.yml + - name: Handle apm json specs + policy: ghcr.io/elastic/oblt-updatecli-policies/apm/apm-json-specs:0.3.0@sha256:f01667138f2a3a52aa23c556a174d6cdba1209f475d67a73e2aec2d3189b0bb9 + values: + - .ci/updatecli/values.d/scm.yml + - .ci/updatecli/values.d/apm-json-specs.yml + - name: Update Updatecli policies + policy: ghcr.io/updatecli/policies/autodiscovery/updatecli:0.4.0@sha256:254367f5b1454fd6032b88b314450cd3b6d5e8d5b6c953eb242a6464105eb869 + values: + - .ci/updatecli/values.d/scm.yml + - .ci/updatecli/values.d/update-compose.yml