Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[ TESTING ] Added new metrics to match java SDK metrics parity #60

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -22,7 +22,7 @@

# NOTE: (NathanielRN) Metrics is on hold.
# See https://github.com/open-telemetry/opentelemetry-python/issues/1835
# from setup_metrics import apiBytesSentCounter, apiLatencyRecorder
from setup_metrics import apiBytesSentCounter, apiLatencyRecorder, apiqueueSizeChangeMetric, apitotalApiBytesSentMetric, apilastLatencyMetric

# Constants

Expand Down Expand Up @@ -59,22 +59,22 @@ def mimicPayloadSize():

@app.after_request
def after_request_func(response):
# if request.path == "/outgoing-http-call":
# apiBytesSentCounter.add(
# response.calculate_content_length() + mimicPayloadSize(),
# {
# DIMENSION_API_NAME: request.path,
# DIMENSION_STATUS_CODE: response.status_code,
# },
# )

# apiLatencyRecorder.record(
# int(time.time() * 1_000) - session[REQUEST_START_TIME],
# {
# DIMENSION_API_NAME: request.path,
# DIMENSION_STATUS_CODE: response.status_code,
# },
# )
if request.path == "/outgoing-http-call":
apiBytesSentCounter.add(
response.calculate_content_length() + mimicPayloadSize(),
{
DIMENSION_API_NAME: request.path,
DIMENSION_STATUS_CODE: response.status_code,
},
)

apiLatencyRecorder.record(
int(time.time() * 1_000) - session[REQUEST_START_TIME],
{
DIMENSION_API_NAME: request.path,
DIMENSION_STATUS_CODE: response.status_code,
},
)

return response

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,46 @@

# Setup Metric Components

apiBytesSentMetricName = "apiBytesSent"
latencyMetricName = "latency"
apiBytesSentMetricName = "apiBytesSent"
totalApiBytesSentMetricName = "totalApiBytesSent"
lastLatencyMetricName = "lastLatency"
queueSizeChangeMetricName = "queueSizeChange"
actualQueueSizeMetricName = "actualQueueSize"

if "INSTANCE_ID" in os.environ:
instanceId = os.environ["INSTANCE_ID"]
if not instanceId.strip() == "":
latencyMetricName += "_" + instanceId
apiBytesSentMetricName += "_" + instanceId
totalApiBytesSentMetricName += "_" + instanceId
lastLatencyMetricName += "_" + instanceId
queueSizeChangeMetricName += "_" + instanceId
actualQueueSizeMetricName += "_" + instanceId

apiBytesSentCounter = meter.create_counter(
apiBytesSentMetricName, "API request load sent in bytes", "one", int
)

apiLatencyRecorder = meter.create_valuerecorder(
apiLatencyRecorder = meter.create_histogram(
latencyMetricName, "API latency time", "ms", int
)

apiqueueSizeChangeMetric = meter.create_up_down_counter(
queueSizeChangeMetricName, "Queue Size change", "one", int
)

apitotalApiBytesSentMetric = meter.create_observable_gauge(
totalApiBytesSentMetricName, "Total API request load sent in bytes", "one", int
)

apilastLatencyMetric = meter.create_observable_gauge(
lastLatencyMetricName, "The last API latency observed at collection interval", "ms", int
)

apiactualQueueSizeMetric = meter.create_observable_gauge(
actualQueueSizeMetricName, "The actual queue size observed at collection interval", "one", int
)
# Start Metric Pipeline

# Exporter to export metrics to the console
Expand Down