Skip to content
betterstack-alchemyUnofficial

Telemetry.Source

Kind ResourceType id BetterStack.Telemetry.SourceSource src/Telemetry/Source.tsLive test available A live lifecycle test exists: it runs against the offline mock by default and against the real API under bun run test:live. This records that the test exists, not a dated live run (see Compatibility). Test file: test/Telemetry/Source.test.ts.

A telemetry source: a stream of logs, metrics or traces ingested into Better Stack. Create one per application or platform, then hand its token (a Redacted secret) and ingestingHost / ingestUrl to whatever sends the data: an application’s environment, a Cloudflare Worker’s vars, a Cloud.Service’s env, or a Vector / OpenTelemetry Collector configuration. Everything is sent to https://<ingestingHost> with Authorization: Bearer <token>.

platform decides which integration the source is set up for (its default VRL transformation, Live tail format and setup guide). Values: apache2, aws, aws_cloudwatch, aws_ecs, aws_elb, aws_fargate, azure, azure_logs, claude_platform, cloudflare_logpush, cloudflare_prometheus_exporter, cloudflare_worker, datadog_agent, digitalocean, docker, dokku, dotnet, elasticsearch, erlang, fastly, filebeat, flights, fluentbit, fluentd, fly_io, gcp, go, google_cloud_pubsub, haproxy, heroku, http, java, javascript, kubernetes, logstash, minio, mongodb, mysql, nginx, open_telemetry, oracle_cloud, php, postgresql, prometheus, prometheus_scrape, python, rabbitmq, redis, render, rsyslog, ruby, syslog-ng, traefik, ubuntu, vector, vercel_integration, winlogbeat. For a host or cluster agent, use a Collector, which creates its own source.

Lifecycle:

  • platform, dataRegion and teamId can’t change: changing one replaces the source, which deletes its data and issues a new token.
  • connectedSourceIds is compared against the previous deploy, not the live list (the API also lists sources connected from the other side). A change sends the whole list: an id you drop is disconnected, and so is a connection only the other source declared. Leave it out to leave the connections alone; [] disconnects every one. A connection needs an OpenTelemetry source (platform: "open_telemetry") on at least one side: connecting it with an http, vector or another OpenTelemetry source works, while vector↔vector or http↔http is refused with a 422 (connected_source_ids[0]: is not a source this source can be connected to; observed live, the API description does not say so). Ids are strings.
  • Deleting sends force=true, so a source that has received data is deleted with its data (Terraform’s deletion_protection is a Terraform-state-only guard; use Alchemy’s RemovalPolicy to retain a source instead).
  • scrapeRequestBasicAuthPassword is never returned: changes are detected against the previous deploy. Removing it, scrapeRequestBasicAuthUser or sourceGroupId from the config clears it.
  • customBucket is set on create; afterwards only its key pair can be rotated (any other change, null included, fails with CustomBucketImmutable). Leaving it out of the config sends nothing: the bucket stays.
  • Connecting an AWS account or a GCP project is done by SourceAwsAccount / SourceGcpProject.

An HTTP source kept for 30 days

const logs = yield* BetterStack.Telemetry.Source("api-logs", {
platform: "http",
logsRetention: 30,
});

The token is a Redacted secret: pass it as a secret environment value, never interpolate it into a string that ends up in state.

Environment for an application (a Cloud.Service’s env, a Worker’s vars)

const otel = yield* BetterStack.Telemetry.Source("otel", { platform: "open_telemetry" });
const env = {
OTEL_EXPORTER_OTLP_ENDPOINT: otel.ingestUrl,
BETTERSTACK_SOURCE_TOKEN: otel.token,
};

A Vector sink that reads the token from its environment

const vector = yield* BetterStack.Telemetry.Source("vector", { platform: "vector" });
const sink = Output.interpolate`[sinks.better_stack]
type = "http"
inputs = ["app_logs"]
uri = "${vector.ingestUrl}"
encoding.codec = "json"
auth.strategy = "bearer"
auth.token = "\${BETTERSTACK_SOURCE_TOKEN}"
`;

An OpenTelemetry Collector exporter

const traces = yield* BetterStack.Telemetry.Source("traces", { platform: "open_telemetry" });
const exporter = Output.interpolate`exporters:
otlphttp/betterstack:
endpoint: "${traces.ingestUrl}"
headers:
Authorization: "Bearer \${env:BETTERSTACK_SOURCE_TOKEN}"
`;

A new source’s ingesting host refuses its token for its first seconds (401 {"error": "Unauthorized"}; 1-4 s measured). So that a host deployed in the same stack — a Cloud.Service exporting with Telemetry.Export, a Worker using Telemetry.IngestLogs — never sends into that window, a create only returns once the host accepts the token: it sends EMPTY batches ([], which carry no event and write nothing) until one is accepted, for at most 60 seconds (then it logs a warning and continues). Anything that binds the source is created after it, so it starts with an accepted token. A sender outside the stack that uses a source the moment it is created should retry a 401 for a few seconds.

A source in a SourceGroup

const backend = yield* BetterStack.Telemetry.SourceGroup("backend", { name: "Backend" });
yield* BetterStack.Telemetry.Source("checkout", {
platform: "open_telemetry",
sourceGroupId: backend.id,
});

Reference a source by id

const existing = BetterStack.Telemetry.Source.lookup({ id: "123456" });

Reference a source by name, or by its table name (either fails with AmbiguousLookup when several sources match)

const production = BetterStack.Telemetry.Source.lookup({ name: "Production" });
const byTable = BetterStack.Telemetry.Source.lookup({ tableName: "production" });

platform "http" | "docker" | "kubernetes" | "mysql" | "redis" | "mongodb" | "elasticsearch" | "nginx" | "prometheus" | "traefik" | "apache2" | "aws" | "aws_cloudwatch" … required

The platform the source ingests from. For a collector, use Create a collector, which creates its own source. Can't be changed after the source is created.

blockedMetrics string[]

Metric names marked as spam, which are dropped when they're ingested. Read more about marking metrics as spam.

connectedSourceIds string[]

IDs of the sources connected to this one, so you can correlate their logs and traces. Connections go both ways. The source is connected to each listed source and to every source those are already connected to. An update removes no existing connection, and [] disconnects the source.

customBucket CreateCollectorRequestCustomBucket | null

Your own S3-compatible bucket to archive data in, or null when the source uses Better Stack storage. Read more about hosting data in your own bucket. The bucket can't be changed after the source is created. To rotate the key pair, update only access_key_id and secret_access_key. We check the new pair against the bucket first and refuse the whole request when it fails. A bucket that several sources share is rotated for all of them.

dataRegion string

The data region, europe, us, singapore or a dedicated cluster's name from List data regions. Can't be changed after the source is created. Defaults to the organization's default data region.

gcpMetricsFilters CreateSourceRequestGcpMetricsFiltersItem[]

Which Google Cloud metrics the source collects. Each rule has one key, include or exclude, holding a regular expression that must match the whole metric type, or * for every metric. All rules use the same key. An empty list collects no metrics, which is the default. Each GCP metric's collected says whether these rules collect it. Only for the gcp platform.

ingestingPaused boolean

Whether ingestion is paused for this source.

liveTailPattern string | null

The pattern Live tail shows each log line with. Columns are wrapped in braces, such as PID: {message_json.pid} {level} {message}. null when the source doesn't receive logs. See Formatting logs. Send null to restore the default format. Refused when the source doesn't receive logs.

liveTailPatternSpans string | null

The pattern Live tail shows each span with. Columns are wrapped in braces, such as {span.name} {duration}. null when the source doesn't receive spans. See Formatting logs. Send null to restore the default format. Refused when the source doesn't receive spans.

logsRetention number

Days logs are kept, one of the retention periods your plan offers.

metricsRetention number

Days metrics are kept, one of the retention periods your plan offers.

name string

Source name. Defaults to a unique name generated from the stack, stage and logical id.

scrapeFrequencySecs 15 | 30 | 60 | 120 | 300 | number

Seconds between scrapes. Only for the prometheus_scrape and cloudflare_prometheus_exporter platforms.

scrapeRequestBasicAuthPassword string | Redacted<string> | null

Password for basic authentication on scrape requests. Not returned after it's saved. Only for the prometheus_scrape and cloudflare_prometheus_exporter platforms.

scrapeRequestBasicAuthUser string | null

Username for basic authentication on scrape requests. Only for the prometheus_scrape and cloudflare_prometheus_exporter platforms.

scrapeRequestHeaders CreateSourceRequestScrapeRequestHeadersItem[]

Custom headers sent with each scrape request, each with a name and a value. Only for the prometheus_scrape and cloudflare_prometheus_exporter platforms.

scrapeUrls string[]

URLs to scrape metrics from. Only for the prometheus_scrape and cloudflare_prometheus_exporter platforms.

serviceFields CollectorServiceFieldsItem[]

Log fields that break data down by service. Each entry needs a name_key, and type_key can be null to skip it. An update replaces the existing list, and [] removes them all.

skipSslVerify boolean

Whether to skip TLS certificate verification when scraping. Only for the prometheus_scrape and cloudflare_prometheus_exporter platforms.

sourceGroupId string | null

Source group this source belongs to, or null when it's in no group. Get the IDs via List source groups.

teamId string

Team that owns the resource, such as t123. Defaults to the credentials' team (BETTERSTACK_TEAM_ID, or the profile's team). Changing it replaces the resource.

vrlTransformationLogs string

VRL program Better Stack runs on each log line as it's ingested. null restores the platform's default program, and "" is an empty program. Read more about VRL transformations.

vrlTransformationSpans string

VRL program Better Stack runs on each span as it's ingested. null restores the platform's default program, and "" is an empty program. Read more about VRL transformations.

id string always set

The source's id.

ingestUrl string | null always set

https://<ingestingHost>: where applications send data, with Authorization: Bearer <token> (HTTP and OTLP/HTTP alike). null for the prometheus_scrape and cloudflare_prometheus_exporter platforms, whose data Better Stack scrapes.

awsAutoSubLogGroups boolean

Whether to subscribe new CloudWatch log groups automatically when they're discovered. Only for the aws platform.

blockedMetrics string[]

Metric names marked as spam, which are dropped when they're ingested. Read more about marking metrics as spam.

cluster string

The cluster the source's data is stored on, by its name. To connect Grafana to this data, send it as the cluster of Create a connection.

connectedSourceIds string[]

IDs of the sources connected to this one, so you can correlate their logs and traces. Connections go both ways. The source is connected to each listed source and to every source those are already connected to.

createdAt string

When the source was created.

customBucket CollectorCustomBucket | null

Your own S3-compatible bucket to archive data in, or null when the source uses Better Stack storage. Read more about hosting data in your own bucket. The bucket can't be changed after the source is created. To rotate the key pair, update only access_key_id and secret_access_key. We check the new pair against the bucket first and refuse the whole request when it fails. A bucket that several sources share is rotated for all of them.

dataRegion string

The data region, europe, us, singapore or a dedicated cluster's name from List data regions.

gcpLogFilter string | null

Google Cloud Logging query that selects which logs the source receives. null forwards every log, which is the default. Google Cloud checks the query when it's saved and refuses an invalid one. Only for the gcp platform.

gcpMetricsFilters CreateSourceRequestGcpMetricsFiltersItem[]

Which Google Cloud metrics the source collects. Each rule has one key, include or exclude, holding a regular expression that must match the whole metric type, or * for every metric. All rules use the same key. An empty list collects no metrics, which is the default. Each GCP metric's collected says whether these rules collect it. Only for the gcp platform.

ingestingHost string | null

Host to send data to. null for the prometheus_scrape and cloudflare_prometheus_exporter platforms, whose data Better Stack scrapes.

ingestingPaused boolean

Whether ingestion is paused for this source.

lastDataOn string | null

The last day the source received data, in UTC, such as 2026-06-11. null when the source received no data in the last 30 days. The date can be up to about 15 minutes behind.

liveTailPattern string | null

The pattern Live tail shows each log line with. Columns are wrapped in braces, such as PID: {message_json.pid} {level} {message}. null when the source doesn't receive logs. See Formatting logs.

liveTailPatternSpans string | null

The pattern Live tail shows each span with. Columns are wrapped in braces, such as {span.name} {duration}. null when the source doesn't receive spans. See Formatting logs.

logsRetention number

Days logs are kept, one of the retention periods your plan offers.

metricsRetention number

Days metrics are kept, one of the retention periods your plan offers.

name string

Source name.

parentSourceId string | null

The source whose table this source shares, when it's connected to one. query_collections then names that source's collections. null otherwise.

platform string

The platform the source ingests from. For a collector, use Create a collector, which creates its own source.

queryCollections SourceQueryCollections

ClickHouse names to query the source's data by. A connected source's data is in its parent's collections, and app_filter and metrics_app_filter keep only its own rows.

scrapeFrequencySecs 15 | 30 | 60 | 120 | 300

Seconds between scrapes. Only for the prometheus_scrape and cloudflare_prometheus_exporter platforms.

scrapeRequestBasicAuthUser string | null

Username for basic authentication on scrape requests. Only for the prometheus_scrape and cloudflare_prometheus_exporter platforms.

scrapeRequestHeaders CreateSourceRequestScrapeRequestHeadersItem[]

Custom headers sent with each scrape request, each with a name and a value. Only for the prometheus_scrape and cloudflare_prometheus_exporter platforms.

scrapeUrls string[]

URLs to scrape metrics from. Only for the prometheus_scrape and cloudflare_prometheus_exporter platforms.

serviceFields CollectorServiceFieldsItem[]

Log fields that break data down by service. Each entry needs a name_key, and type_key can be null to skip it. An update replaces the existing list, and [] removes them all.

skipSslVerify boolean

Whether to skip TLS certificate verification when scraping. Only for the prometheus_scrape and cloudflare_prometheus_exporter platforms.

sourceGroupId string | null

Source group this source belongs to, or null when it's in no group. Get the IDs via List source groups.

sourceTypes string[]

Kinds of data the source holds, such as logs, spans, metrics, exceptions or web_events, sorted by name.

tableName string

The name you query the source's data by, such as prometheus.

teamId string

Team that owns the source, such as t123.

teamName string

Name of the team that owns the source.

token string | Redacted<string>

Ingestion token. Returned in every response.

updatedAt string

When the source was last updated.

vrlTransformationLogs string

VRL program Better Stack runs on each log line as it's ingested. null restores the platform's default program, and "" is an empty program. Read more about VRL transformations.

vrlTransformationSpans string

VRL program Better Stack runs on each span as it's ingested. null restores the platform's default program, and "" is an empty program. Read more about VRL transformations.

Source.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.

teamId string

Team that owns it, such as t123. Defaults to the credentials' team.