Skip to content

Commit

Permalink
Set metrics export interval to ten seconds
Browse files Browse the repository at this point in the history
Note that this is the export interval for metrics to be sent from
the OpenTelemetry application to the agent, not from the agent to
AppSignal's servers.

The default interval is set to sixty seconds -- when combined with
the agent's transmission interval, this introduces a delay of up to
two minutes in metrics being sent to AppSignal.

In addition, the histogram-to-distribution conversion that is
performed in the agent benefits from smaller batches of data for
greater accuracy.
  • Loading branch information
unflxw committed Mar 11, 2024
1 parent 65b0fc4 commit c4e5e5d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/appsignal/opentelemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.metrics import (
Counter,
Histogram,
MeterProvider,
ObservableCounter,
ObservableGauge,
ObservableUpDownCounter,
UpDownCounter,
Histogram,
)
from opentelemetry.sdk.metrics.export import (
AggregationTemporality,
Expand Down Expand Up @@ -112,9 +112,9 @@ def start_opentelemetry(config: Config) -> None:
# Configure OpenTelemetry request headers config
request_headers = list_to_env_str(config.option("request_headers"))
if request_headers:
os.environ["OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST"] = (
request_headers
)
os.environ[
"OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST"
] = request_headers

opentelemetry_port = config.option("opentelemetry_port")
_start_opentelemetry_tracer(opentelemetry_port)
Expand All @@ -139,7 +139,7 @@ def _start_opentelemetry_tracer(opentelemetry_port: str | int) -> None:
ObservableCounter: AggregationTemporality.DELTA,
ObservableGauge: AggregationTemporality.CUMULATIVE,
ObservableUpDownCounter: AggregationTemporality.DELTA,
Histogram: AggregationTemporality.DELTA
Histogram: AggregationTemporality.DELTA,
}


Expand All @@ -148,7 +148,9 @@ def _start_opentelemetry_metrics(opentelemetry_port: str | int) -> None:
endpoint=f"http://localhost:{opentelemetry_port}/v1/metrics",
preferred_temporality=METRICS_PREFERRED_TEMPORALITY,
)
metric_reader = PeriodicExportingMetricReader(metric_exporter)
metric_reader = PeriodicExportingMetricReader(
metric_exporter, export_interval_millis=10000
)

resource = Resource(attributes={"appsignal.service.process_id": os.getpid()})
provider = MeterProvider(resource=resource, metric_readers=[metric_reader])
Expand Down

0 comments on commit c4e5e5d

Please sign in to comment.