integration
Azure Functions Logging with App Insights
How Azure Functions logging works: Application Insights, host.json levels, sampling, cold starts and flushing, costs, and how to send logs to LogTide.
- How Functions logs reach Application Insights
- host.json levels and sampling
- OpenTelemetry (OTLP) export to LogTide
- Works alongside Azure Monitor
Azure Functions comes with logging already wired up: create a function app, and its logs flow to Application Insights. That is a good default, until the volume grows, the sampling hides what you need, or you want logs from Functions next to everything else. This guide explains how Functions logging works, what controls it, and how the options compare, with LogTide as one option.
How Azure Functions logging works
Azure Functions has built-in integration with Application Insights, a feature of Azure Monitor. Telemetry is generated by both the Functions host process and the language worker process where your code runs. With the integration enabled, the connected Application Insights instance receives host logs, traces written from your code, and performance data.
The connection is an app setting. Use APPLICATIONINSIGHTS_CONNECTION_STRING; the older APPINSIGHTS_INSTRUMENTATIONKEY is deprecated. When you create the app in the portal, with Core Tools or with Visual Studio Code, integration is enabled by default.
For custom logs in most stacks (including Node.js), the default pipeline is worker -> Functions host -> Application Insights, and the host applies the log levels from host.json. The Function.<name>.User category holds logs written by your own code.
Writing logs in Node.js
In the v4 programming model, log through the invocation context:
import { app, HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions';
app.http('processOrder', {
methods: ['POST'],
authLevel: 'function',
handler: async (request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> => {
context.info(`order received, invocationId=${context.invocationId}`);
try {
const order = await request.json();
// business logic
return { status: 200, jsonBody: { ok: true } };
} catch (err) {
context.error(`order failed, invocationId=${context.invocationId}`, err);
return { status: 500, jsonBody: { error: 'Internal server error' } };
}
},
});
The v4 methods are context.trace, debug, info, warn and error, plus context.log for the default information level. Microsoft’s guidance: use context rather than console, because console output is tracked at app level but is not tied to a specific function. Including context.invocationId in your messages lets you correlate them.
Log levels and categories
Every log has a level (Trace, Debug, Information, Warning, Error, Critical, None) and a category. You set the minimum level per category in host.json:
{
"version": "2.0",
"logging": {
"logLevel": {
"default": "Warning",
"Host.Results": "Information",
"Function": "Information"
}
}
}
These levels apply to every destination of the .NET logging pipeline, including Application Insights and Azure Monitor diagnostic settings (the FunctionAppLogs table). A log filtered here appears nowhere.
Microsoft’s caution matters in practice: Application Insights stores the runtime’s own events in tables at the Information level. If you raise Host.Results or Function above Information, you lose request, dependency and custom metric data in those tables and in the portal Monitor views, and only higher-severity traces remain. For high-volume apps Microsoft’s suggestion is a Warning default, then explicit Information entries for the functions that matter, and Function.<name>.User set to Warning or Error to avoid collecting user logs at Information.
Sampling
Application Insights sampling is on by default and protects you from too much telemetry at peak load. The default is 20 telemetry items per second, applied per host running your app. You can tune it and exclude types from sampling:
{
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"maxTelemetryItemsPerSecond": 20,
"excludedTypes": "Request;Exception"
}
}
}
}
If logs appear to be missing, sampling is the first thing to check.
Cold starts, recycling and flushing
Microsoft defines a cold start as the first time a function app starts after a period of inactivity, taking longer to start. The Node.js guide also warns that you can cache data in global variables for reuse, but should not rely on it persisting, because the runtime can recycle your worker at any time.
For logging, this means:
- Logs that go through
contextare handled by the runtime. Nothing for you to flush. - Anything you buffer yourself is at risk. A logging SDK or exporter that batches in memory and sends on a timer can lose its last batch when the worker is recycled. Flush before returning, or use a processor that exports immediately.
- To log cold starts yourself, use a module-level flag, as you would on any serverless platform. There is no built-in cold start field to query in your own logs.
Costs and retention
Application Insights data is stored in a Log Analytics workspace and billed by ingestion volume. Azure Functions includes a free daily limit for trying Application Insights, and Microsoft warns that if you hit it during testing, new logs stop appearing in queries.
From the Azure Monitor pricing page (checked November 2026): the first 5 GB per month per billing account on the pay-as-you-go tier are free, Analytics Logs keep data at no charge for 31 days (90 days with Microsoft Sentinel on the workspace), and Application Insights data is retained at no charge for 90 days. The page loads its per-GB prices dynamically, so check Azure Monitor pricing for the current rate in your Region instead of relying on a number copied here.
Microsoft’s own guidance for high-volume function apps, from Configure monitoring for Azure Functions:
- Use the Basic table plan where you do not need the Analytics plan features.
- Use sampling and lower
maxTelemetryItemsPerSecond. - Set a
WarningorErrordefault log level, and raise it back per function. - Turn off scale controller logging when you are done investigating it.
You can also override host.json values without redeploying, through app settings named AzureFunctionsJobHost__logging__logLevel__default, with double underscores for the JSON path. Changing app settings restarts the function app.
Your options
| Option | Good for | Trade-offs |
|---|---|---|
| Built-in Application Insights integration | Default monitoring, Azure portal views, Live Metrics, application map | Volume and sampling need tuning; analysis in KQL and Azure tooling |
| OpenTelemetry to Application Insights | Standards-based telemetry, trace and log correlation. Microsoft recommends it for new and existing apps | Needs host.json and code changes; the classic SDKs are legacy |
| OpenTelemetry to any OTLP endpoint | Sending the same telemetry to another backend, or to two at once | Some portal features need Azure Monitor (see below) |
| Diagnostic settings to Log Analytics | Platform logs in the FunctionAppLogs table, central Azure governance | Same ingestion-based billing model |
| A logging SDK called from the function | Structured events straight to a backend | You own batching and flushing |
Application Insights is the best fit if you want Azure-native APM: automatic dependency tracking, application map, Live Metrics and portal views. LogTide does not replace those. It fits when you want your function logs searchable together with logs from other clouds, containers and servers, or when you want to control retention and cost outside Azure Monitor.
Sending Azure Functions logs to LogTide
Option 1: OpenTelemetry (OTLP)
LogTide accepts OTLP logs over HTTP at /v1/otlp/logs, with JSON or Protobuf and an X-API-Key header (see the OpenTelemetry integration). Azure Functions can export to any OTLP-compliant endpoint, so no vendor SDK is needed.
First enable OpenTelemetry in the Functions host, in host.json:
{
"version": "2.0",
"telemetryMode": "OpenTelemetry"
}
Then install the packages. Microsoft’s OTLP sample uses these:
npm install @opentelemetry/api @opentelemetry/auto-instrumentations-node \
@opentelemetry/exporter-logs-otlp-http @azure/functions-opentelemetry-instrumentation
Create src/index.ts, adapted from Microsoft’s OTLP sample to export logs only (the trace exporter and tracer provider are left out to keep this focused on logs):
import { AzureFunctionsInstrumentation } from '@azure/functions-opentelemetry-instrumentation';
import { getResourceDetectors } from '@opentelemetry/auto-instrumentations-node';
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { detectResourcesSync } from '@opentelemetry/resources';
import { LoggerProvider, SimpleLogRecordProcessor } from '@opentelemetry/sdk-logs';
const resource = detectResourcesSync({ detectors: getResourceDetectors() });
const loggerProvider = new LoggerProvider({ resource });
loggerProvider.addLogRecordProcessor(new SimpleLogRecordProcessor(new OTLPLogExporter()));
registerInstrumentations({
loggerProvider,
instrumentations: [new AzureFunctionsInstrumentation()],
});
Point main in package.json at the new file, for example "main": "dist/src/{index.js,functions/*.js}". Microsoft’s sample uses SimpleLogRecordProcessor, which exports each record as it is emitted, so there is no batch to lose when a worker is recycled; the price is one HTTP request per log record. Because of that, test the volume before using it on a busy function.
Configure the exporter with standard OpenTelemetry environment variables as app settings:
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://api.logtide.dev/v1/otlp/logs
OTEL_EXPORTER_OTLP_HEADERS=X-API-Key=lp_your_api_key
OTEL_SERVICE_NAME=order-processor
Use the logs-specific endpoint variable, because LogTide serves logs at /v1/otlp/logs rather than the default /v1/logs path. For self-hosted LogTide, use your own host, for example https://your-logtide-host/v1/otlp/logs. Per Microsoft, if you also keep APPLICATIONINSIGHTS_CONNECTION_STRING, data goes to both destinations. Remove it if you want LogTide only.
Limits to know before switching, all from Microsoft’s documentation:
- With
telemetryModeset toOpenTelemetry, thelogging.applicationInsightssection ofhost.json(including sampling) does not apply. - Filters in
host.jsonapply only to host logs. Worker logs are filtered with the OpenTelemetry settings of your language. - The portal does not support log streaming, and “Recent function invocation” traces appear only when telemetry goes to Azure Monitor.
- The host captures stdout and stderr. Do not add a console exporter in production, or you will see duplicates.
Validate the setup in a non-production function app before rolling it out.
Option 2: the LogTide SDK
If you prefer the SDK, initialize it at module scope so it survives warm invocations, and flush before the function returns:
npm install @logtide/core
// src/functions/processOrder.ts
import { app, HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions';
import { hub } from '@logtide/core';
hub.init({
dsn: process.env.LOGTIDE_DSN,
service: 'order-processor',
environment: process.env.AZURE_FUNCTIONS_ENVIRONMENT || 'production',
});
let coldStart = true;
app.http('processOrder', {
methods: ['POST'],
authLevel: 'function',
handler: async (request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> => {
const isCold = coldStart;
coldStart = false;
const base = {
invocationId: context.invocationId,
functionName: context.functionName,
coldStart: isCold,
};
const startedAt = Date.now();
try {
const order = await request.json();
// business logic
hub.captureLog('info', 'order processed', { ...base, duration: Date.now() - startedAt });
return { status: 200, jsonBody: { ok: true } };
} catch (error) {
hub.captureError(error as Error, base);
return { status: 500, jsonBody: { error: 'Internal server error' } };
} finally {
await hub.flush();
}
},
});
Set LOGTIDE_DSN in the function app settings (portal, Environment variables) or in local.settings.json for local development. Better, store it as a Key Vault reference. The SDK batches by default (100 events or 5 seconds), retries, and has a circuit breaker, see the JavaScript SDK reference. The explicit flush() adds one HTTP round trip per invocation. For latency-sensitive HTTP functions you can skip it and accept that the last batch may be lost if the worker is recycled.
The function app must be able to reach your LogTide host. For a private instance, check your hosting plan’s virtual network integration support in the Azure documentation.
Once logs are in LogTide, search them by field. See Query Syntax:
service:order-processor coldStart:true
service:order-processor level:error
invocationId:abc-123
Application Insights and LogTide together
A common split: keep Application Insights for what it does natively (requests, dependencies, application map, Live Metrics) with sampling and a Warning default level in host.json, and send verbose application logs to LogTide. If you use the SDK route, set the host.json default level so Application Insights stops capturing what the SDK already ships, otherwise you pay for the same logs twice.
EU data residency
For Application Insights, you choose the location of the resource when you create it, in an Azure geography (Microsoft’s documentation suggests the same region as the function app, or a nearby one). Pick an EU region for both the function app and the Application Insights resource if your data must stay in the EU.
For logs you send elsewhere, the location is wherever the receiver runs:
- LogTide Cloud: LogTide’s DPA and sub-processor list state that its infrastructure is hosted in Strasbourg, France (OVH), and that customer personal data is not transferred outside the EU/EEA. Billing data processed by Stripe is the documented exception. See the DPA and sub-processors.
- Self-hosted LogTide: logs stay in the region or data center where you deploy it, including an Azure region of your choice.
This describes where data is stored, not who may be compelled to disclose it. For compliance decisions, rely on your own legal review. The article on on-premise log management for EU compliance explains the difference.
Troubleshooting
- Missing logs and gaps in the portal: check sampling first, then the log level for
FunctionandHost.Results. - Missing logs with OpenTelemetry mode on:
host.jsonlogging.applicationInsightssettings no longer apply, and worker logs follow your language’s OpenTelemetry settings. - Last logs of an invocation are missing in LogTide: the SDK buffer was not flushed before the worker was recycled. Await
hub.flush()or use an exporter that exports immediately. - Nothing arrives in LogTide: check the API key, the endpoint path (
/v1/otlp/logsfor OTLP,/api/v1/ingestfor the HTTP API) and outbound network access from the function app. - Duplicate logs: do not combine a console exporter with the host’s stdout capture, and lower
host.jsonlevels if both Application Insights and LogTide receive the same logs. - New logs stop in Application Insights during testing: you may have hit the free daily limit.
Sources
- Monitor executions in Azure Functions
- Configure monitoring for Azure Functions
- Use OpenTelemetry with Azure Functions
- Node.js developer guide for Azure Functions
- Azure Monitor pricing (checked November 2026)
Next steps
- AWS Lambda logging: the same questions on AWS
- Azure Functions logging with dependency injection
- LogTide vs Azure Monitor: feature and cost comparison
- Cloud logging pricing breakdown
- Real-time alerting use case
Frequently Asked Questions
Where do Azure Functions logs go by default?
When Application Insights integration is enabled, which is the default when you create a function app in the portal or with Core Tools, telemetry goes to the connected Application Insights resource. That includes logs from the Functions host and traces written from your code. The connection is the APPLICATIONINSIGHTS_CONNECTION_STRING app setting.
How do I log from a Node.js function?
In the Node.js v4 programming model, use context.log, context.info, context.warn and context.error on the InvocationContext. Microsoft recommends context over console, because console output is tracked at app level but is not associated with a specific function.
How do I control how much an Azure function logs?
Use logging.logLevel in host.json to set a default level and per-category levels, and logging.applicationInsights.samplingSettings to limit telemetry. Be careful with levels above Information for the Function and Host categories: Microsoft documents that this stops some telemetry reaching the Application Insights tables and portal views.
Why are my Azure Functions logs missing the last lines of an invocation?
The Functions runtime can recycle a worker at any time, and in-memory state is not guaranteed to persist. If you buffer logs in your own exporter or SDK, flush before the handler returns. Telemetry that goes through the Functions host and Application Insights is handled by the runtime, so it needs no manual flush.
Can I send Azure Functions logs to LogTide?
Yes, two ways. Enable OpenTelemetry in host.json and export logs over OTLP to LogTide's OTLP endpoint, or call the LogTide JavaScript SDK from your functions and flush before returning. Both can run alongside Application Insights.
Can I keep Application Insights and use LogTide at the same time?
Yes. With OpenTelemetry mode, if you provide both an Application Insights connection string and an OTLP exporter configuration, data is sent to both. A common split keeps Application Insights for tracing and the Azure portal views, and sends verbose application logs to LogTide, with a higher default log level in host.json.