Created
November 9, 2022 15:04
-
-
Save tukanuk/63a4f3a368dd953e2cdf3ce95c9099df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
# Dynatrace provide a "magic" file called "dt_metadata_e617c525669e072eebe3d0f08212e8f2.json" that | |
# contains additional metadata. The file always has this name. | |
# Magic metadata file explainer: https://www.dynatrace.com/support/help/shortlink/enrich-metrics | |
# Usage in OT: https://www.dynatrace.com/support/help/shortlink/opent-python#send | |
service_props = {"service.name": "FlaskApp"} | |
try: | |
with open("dt_metadata_e617c525669e072eebe3d0f08212e8f2.json") as fp: | |
metadata_file = fp.read() # Gets the file path that is in the file | |
print("%28.28s: %s" % ("Metadata file contents", metadata_file)) | |
# Open the file at the provided path | |
opened_metadata_file = open(metadata_file) | |
# Load the metadata | |
metadata = json.load(opened_metadata_file) | |
print("%28.28s: %s" % ("Metadata provided by the OneAgent: ", metadata)) | |
# Add to the existing service_prop | |
service_props.update(metadata) | |
# OR The direct way | |
# service_props = json.load(open(fp.read())) | |
except: | |
pass | |
print("%28.28s: %s" % ("Updated service_props", service_props)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output:
Metadata file contents: /var/lib/dynatrace/oneagent/agent/config/dt_metadata_e617c525669e072eebe3d0f08212e8f2_1668006286.json Metadata provided by the One: {'dt.entity.process_group_instance': 'PROCESS_GROUP_INSTANCE-A98DCABD5C142B7D', 'dt.entity.host': 'HOST-8A0AB9A27B0DDECA', 'dt.entity.host_group': 'HOST_GROUP-107FF7F86F5BACD'} Updated service_props: {'service.name': 'FlaskApp', 'dt.entity.process_group_instance': 'PROCESS_GROUP_INSTANCE-A98DCABD5C142B7D', 'dt.entity.host': 'HOST-8A0AB9A27B0DDECA', 'dt.entity.host_group': 'HOST_GROUP-107FF7F86F5BACD'}