Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM eclipse-temurin:21.0.8_9-jre@sha256:66bb900643426ad01996d25bada7d56751913f9cec3b827fcb715d2ec9a0fbfc
FROM eclipse-temurin:25-jre@sha256:74d5c631e5db5a44e7f5a2dd49f93f0c6f7b8c22c1dc1b8e1caec7009872c5c3

COPY target/example-exporter-opentelemetry.jar ./app.jar
# check that the resource attributes from the agent are used, epsecially the service.instance.id should be the same
ADD --chmod=644 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.8.0/opentelemetry-javaagent.jar /usr/src/app/opentelemetry-javaagent.jar
ADD --chmod=644 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.21.0/opentelemetry-javaagent.jar /usr/src/app/opentelemetry-javaagent.jar
ENV JAVA_TOOL_OPTIONS=-javaagent:/usr/src/app/opentelemetry-javaagent.jar

#ENTRYPOINT [ "java", "-Dotel.javaagent.debug=true","-jar", "./app.jar" ] # for debugging
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
#!/usr/bin/env python3

"""This script is used to check if the service instance id is present in the exported data
The script will return 0 if the service instance id is present in the exported data"""

"""
Check if the service instance id is present in the exported data.
Returns 0 if the service instance id is present in the exported data.
"""
import json
import urllib.parse
from urllib.request import urlopen


def get(url):
global response, res
def get_json(url):
with urlopen(url) as response:
# read the response
res = response.read()
# decode the response
res = json.loads(res.decode("utf-8"))
return res
return json.loads(response.read().decode("utf-8"))


res = get(" http://localhost:9090/api/v1/query?query=target_info")
def main():
# Query Prometheus for target_info
res = get_json("http://localhost:9090/api/v1/query?query=target_info")

# uncomment the following line to use the local file instead of the url - for debugging
# with open('example_target_info.json') as f:
# res = json.load(f)
# Uncomment for local debugging
# with open('example_target_info.json') as f:
# res = json.load(f)

values = list(
{
instance_ids = {
r["metric"]["instance"]
for r in res["data"]["result"]
if not r["metric"]["service_name"] == "otelcol-contrib"
if r["metric"].get("service_name") != "otelcol-contrib"
}
)
print(values)
instance_ids = list(instance_ids)

print(f"Instance ids found:{instance_ids}")
if len(instance_ids) > 1:
print("More than one instance id found")
print(res)

# Both the agent and the exporter should report the same instance id
assert len(instance_ids) == 1, "Expected exactly one instance id"

query = f'target_info{{instance="{instance_ids[0]}"}}'
encoded_query = urllib.parse.quote_plus(query)
res = get_json(f"http://localhost:9090/api/v1/query?query={encoded_query}")

# both the agent and the exporter should report the same instance id
assert len(values) == 1
infos = res["data"]["result"]
print(infos)

path = f'target_info{{instance="{values[0]}"}}'
path = urllib.parse.quote_plus(path)
res = get(f"http://localhost:9090/api/v1/query?query={path}")
# They should not have the same target info (e.g. only the agent has telemetry_distro_name)
assert len(infos) == 2, "Expected two target info results"

infos = res["data"]["result"]
print(infos)

# they should not have the same target info
# e.g. only the agent has telemetry_distro_name
assert len(infos) == 2
if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:21.0.8_9-jre@sha256:66bb900643426ad01996d25bada7d56751913f9cec3b827fcb715d2ec9a0fbfc
FROM eclipse-temurin:25-jre@sha256:74d5c631e5db5a44e7f5a2dd49f93f0c6f7b8c22c1dc1b8e1caec7009872c5c3

COPY target/example-exporter-opentelemetry.jar ./app.jar

Expand Down
2 changes: 1 addition & 1 deletion examples/example-native-histogram/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
example-application:
image: eclipse-temurin:21.0.8_9-jre@sha256:66bb900643426ad01996d25bada7d56751913f9cec3b827fcb715d2ec9a0fbfc
image: eclipse-temurin:25-jre@sha256:74d5c631e5db5a44e7f5a2dd49f93f0c6f7b8c22c1dc1b8e1caec7009872c5c3
network_mode: host
volumes:
- ./target/example-native-histogram.jar:/example-native-histogram.jar
Expand Down