Skip to content

Instantly share code, notes, and snippets.

@Depechie
Created June 5, 2024 18:00
Show Gist options
  • Select an option

  • Save Depechie/dba61994057d18557db9cb4a50dee57d to your computer and use it in GitHub Desktop.

Select an option

Save Depechie/dba61994057d18557db9cb4a50dee57d to your computer and use it in GitHub Desktop.
Example bicep module to setup azure container apps with OTEL managed agent
@allowed([
'dev', 'tst', 'acc', 'prd'
])
param env string = 'dev'
param projectName string
param resourceLocationLong string = resourceGroup().location
param resourceLocationShort string
param containerRegistryName string = 'yourawesomecontaineregistry'
param imageNameApi string = 'acaobservability.api'
param imageNameWeb string = 'acaobservability.web'
param azureContainerRegistryUsername string = containerRegistryName
@secure()
param azureContainerRegistryPassword string
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' = {
name: 'log-${env}-${resourceLocationShort}-${projectName}'
location: resourceLocationLong
properties: {
sku: {
name: 'PerGB2018'
}
}
}
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
name: 'ai-${env}-${resourceLocationShort}-${projectName}'
location: resourceLocationLong
kind: 'web'
properties: {
Application_Type: 'web'
Flow_Type: 'Bluefield'
WorkspaceResourceId: logAnalyticsWorkspace.id
}
}
resource environment 'Microsoft.App/managedEnvironments@2023-11-02-preview' = {
name: 'cae-${env}-${resourceLocationShort}-${projectName}'
location: resourceLocationLong
properties: {
appInsightsConfiguration: {
connectionString: applicationInsights.properties.ConnectionString
}
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
openTelemetryConfiguration: {
tracesConfiguration:{
destinations: ['appInsights']
}
logsConfiguration: {
destinations: ['appInsights']
}
}
}
}
resource containerAppApi 'Microsoft.App/containerApps@2023-05-01' = {
name: 'ca-${env}-${resourceLocationShort}-api'
location: resourceLocationLong
properties: {
managedEnvironmentId: environment.id
configuration: {
secrets: [
{
name: 'containerregistrypasswordref'
value: azureContainerRegistryPassword
}
]
ingress: {
external: false
targetPort: 8080
transport: 'http'
allowInsecure: true
}
registries: [
{
server: '${containerRegistryName}.azurecr.io'
username: azureContainerRegistryUsername
passwordSecretRef: 'containerregistrypasswordref'
}
]
}
template: {
containers: [
{
image: '${containerRegistryName}.azurecr.io/${imageNameApi}:latest'
name: 'ca-${env}-${resourceLocationShort}-api'
resources: {
cpu: json('0.5')
memory: '1.0Gi'
}
env: [
{
name: 'ASPNETCORE_FORWARDEDHEADERS_ENABLED'
value: 'true'
}
{
name: 'OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES'
value: 'true'
}
{
name: 'OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES'
value: 'true'
}
{
name: 'OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY'
value: 'in_memory'
}
]
}
]
scale: {
minReplicas: 1
maxReplicas: 1
}
}
}
}
resource containerAppWeb 'Microsoft.App/containerApps@2023-05-01' = {
name: 'ca-${env}-${resourceLocationShort}-web'
location: resourceLocationLong
properties: {
managedEnvironmentId: environment.id
configuration: {
secrets: [
{
name: 'containerregistrypasswordref'
value: azureContainerRegistryPassword
}
]
ingress: {
external: true
targetPort: 8080
transport: 'http'
allowInsecure: false
}
registries: [
{
server: '${containerRegistryName}.azurecr.io'
username: azureContainerRegistryUsername
passwordSecretRef: 'containerregistrypasswordref'
}
]
}
template: {
containers: [
{
image: '${containerRegistryName}.azurecr.io/${imageNameWeb}:latest'
name: 'ca-${env}-${resourceLocationShort}-api'
resources: {
cpu: json('0.5')
memory: '1.0Gi'
}
env: [
{
name: 'services__apiservice__http__0'
value: 'http://ca-${env}-${resourceLocationShort}-api'
}
{
name: 'ASPNETCORE_FORWARDEDHEADERS_ENABLED'
value: 'true'
}
{
name: 'OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES'
value: 'true'
}
{
name: 'OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES'
value: 'true'
}
{
name: 'OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY'
value: 'in_memory'
}
]
}
]
scale: {
minReplicas: 1
maxReplicas: 1
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment