Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
395 stars 190 forks source link

[Issue] Multiple log analytics workspaces created when using Azure App Insights and an Azure Container App #3497

Open christiannagel opened 6 months ago

christiannagel commented 6 months ago

Output from azd version Run azd version and copy and paste the output here: azd version 1.7.0-beta.1-pr.3518885 (commit d62cc4c16bda2eefabf48b7d7f8bd616cad1445a)

Describe the bug Having an Azure App Insights resource together with container apps, two Log Analytics workspaces are created. I think there should be only one:

Using azd up, two log analytics workspaces are created:

  (✓) Done: Resource group: rg-codebreaker-12p4
  (x) Failed: Key Vault: codebreakercosmoskvzehizmlsmqemc
  (✓) Done: Log Analytics workspace: law-zehizmlsmqemc
  (✓) Done: Log Analytics workspace: law-appinsights-zehizmlsmqemc
  (✓) Done: Container Registry: acrzehizmlsmqemc
  (✓) Done: Application Insights: appinsights-zehizmlsmqemc
  (✓) Done: Container Apps Environment: cae-zehizmlsmqemc
  (✓) Done: Container App: redis

Using this app model:

    var insights = builder.AddAzureApplicationInsights("AppInsights");
    var redis = builder.AddRedis("redis");

    var cosmos = builder.AddAzureCosmosDB("codebreakercosmos")
        .AddDatabase("codebreaker");

    var gameAPIs = builder.AddProject<Projects.Codebreaker_GameAPIs>("gameapis")
        .WithReference(cosmos)
        .WithReference(redis)
        .WithReference(insights)
        .WithEnvironment("DataStore", dataStore)
        .WithReplicas(1);

    builder.AddProject<Projects.CodeBreaker_Blazor_Host>("blazor")
        .WithReference(gameAPIs)
        .WithReference(insights);

    builder.AddProject<Projects.CodeBreaker_Bot>("bot")
        .WithReference(gameAPIs)
        .WithReference(insights);

This is the generated manifest:

{
  "resources": {
    "AppInsights": {
      "type": "azure.bicep.v0",
      "connectionString": "{AppInsights.outputs.appInsightsConnectionString}",
      "path": "aspire.hosting.azure.bicep.appinsights.bicep",
      "params": {
        "appInsightsName": "appinsights",
        "logAnalyticsWorkspaceId": ""
      }
    },
    "redis": {
      "type": "container.v0",
      "connectionString": "{redis.bindings.tcp.host}:{redis.bindings.tcp.port}",
      "image": "redis:7.2.4",
      "bindings": {
        "tcp": {
          "scheme": "tcp",
          "protocol": "tcp",
          "transport": "tcp",
          "containerPort": 6379
        }
      }
    },
    "codebreakercosmos": {
      "type": "azure.bicep.v0",
      "connectionString": "{codebreakercosmos.secretOutputs.connectionString}",
      "path": "aspire.hosting.azure.bicep.cosmosdb.bicep",
      "params": {
        "databaseAccountName": "codebreakercosmos",
        "databases": [
          "codebreaker"
        ],
        "keyVaultName": ""
      }
    },
    "gameapis": {
      "type": "project.v0",
      "path": "../Codebreaker.GameAPIs/Codebreaker.GameAPIs.csproj",
      "env": {
        "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
        "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true",
        "ConnectionStrings__codebreakercosmos": "{codebreakercosmos.connectionString}",
        "ConnectionStrings__redis": "{redis.connectionString}",
        "APPLICATIONINSIGHTS_CONNECTION_STRING": "{AppInsights.connectionString}",
        "DataStore": "Cosmos"
      },
      "bindings": {
        "http": {
          "scheme": "http",
          "protocol": "tcp",
          "transport": "http"
        },
        "https": {
          "scheme": "https",
          "protocol": "tcp",
          "transport": "http"
        }
      }
    },
    "blazor": {
      "type": "project.v0",
      "path": "../CodeBreaker.Blazor.Host/CodeBreaker.Blazor.Host.csproj",
      "env": {
        "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
        "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true",
        "APPLICATIONINSIGHTS_CONNECTION_STRING": "{AppInsights.connectionString}",
        "services__gameapis__0": "{gameapis.bindings.http.url}",
        "services__gameapis__1": "{gameapis.bindings.https.url}"
      },
      "bindings": {
        "http": {
          "scheme": "http",
          "protocol": "tcp",
          "transport": "http"
        },
        "https": {
          "scheme": "https",
          "protocol": "tcp",
          "transport": "http"
        }
      }
    },
    "bot": {
      "type": "project.v0",
      "path": "../CodeBreaker.Bot/CodeBreaker.Bot.csproj",
      "env": {
        "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
        "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true",
        "APPLICATIONINSIGHTS_CONNECTION_STRING": "{AppInsights.connectionString}",
        "services__gameapis__0": "{gameapis.bindings.http.url}",
        "services__gameapis__1": "{gameapis.bindings.https.url}"
      },
      "bindings": {
        "http": {
          "scheme": "http",
          "protocol": "tcp",
          "transport": "http"
        },
        "https": {
          "scheme": "https",
          "protocol": "tcp",
          "transport": "http"
        }
      }
    }
  }
}

Expected behavior

I expect to have one log analytics workspace created from the App Insights resource, and this workspace to be used with project resources referencing app insights.

Environment Information on your environment:

rajeshkamal5050 commented 6 months ago

This is the current behavior for Preview 4. Lets use this issue for any changes required for Preview 5.

cc @vhvb1989 @davidfowl

christiannagel commented 6 months ago

When using this azd version: azd version 1.7.0-beta.1-pr.3529927 (commit 3fd6b51198b3a530a35c4edfc4ade0c1e7c92c25)

I see a different behavior:

  (✓) Done: Resource group: rg-codeberaker-12p4b
  (✓) Done: Log Analytics workspace: law-x24r45v4bmrra
  (✓) Done: Key Vault: cosmoskvx24r45v4bmrra
  (✓) Done: Container Registry: acrx24r45v4bmrra
  (✓) Done: Container Apps Environment: cae-x24r45v4bmrra
  (✓) Done: Container App: redis
  (✓) Done: Azure Cosmos DB: cosmosx24r45v4bmrra
  (x) Failed: Application Insights: appinsights-x24r45v4bmrra

ERROR: deployment failed: failing invoking action 'provision', error deploying infrastructure: deploying to subscription:

Deployment Error Details:
BadRequest: WorkspaceResourceId is not in valid format

TraceID: 3f53cf0b74851e9d0186b57769dd0616

ERROR: error executing step command 'provision': deployment failed: failing invoking action 'provision', error deploying infrastructure: deploying to subscription:

Deployment Error Details:
BadRequest: WorkspaceResourceId is not in valid format
rajeshkamal5050 commented 5 months ago

Moving this to the Dilithium bucket. Feel free to pull this into a specific milestone if need be. cc @ellismg @vhvb1989 @davidfowl @mitchdenny

mitchdenny commented 5 months ago

This should be fixed now in P5. @christiannagel can you confirm from your end?

christiannagel commented 4 months ago

@mitchdenny I think I've seen this issue just recently using a daily build of .NET Aspire and azd. I'll verify it in the next few days.