Azure Spring Apps에서 Application Insights Java In-Process 에이전트 사용

참고 항목

Azure Spring Apps는 Azure Spring Cloud 서비스의 새 이름입니다. 서비스에 새 이름이 지정되었지만, 자산을 업데이트하는 동안 스크린샷, 비디오, 다이어그램과 같은 일부 위치에서는 당분간 이전 이름이 표시됩니다.

Spring Boot 네이티브 이미지 애플리케이션에서는 Application Insights Java 에이전트 대신 Spring Boot 네이티브 이미지 Java 애플리케이션 프로젝트에서 Azure Monitor OpenTelemetry Distro/Application Insights를 사용합니다.

이 문서의 적용 대상: ✔️ 표준 사용량 및 전용(미리 보기) ✔️ 기본/표준 ✔️ 엔터프라이즈

이 문서에서는 Azure Spring Apps에서 Application Insights Java 에이전트를 사용하여 애플리케이션을 모니터링하는 방법에 대해 설명합니다.

이 기능을 사용하면 다음을 수행할 수 있습니다.

  • 다른 필터를 사용하여 추적 데이터를 검색합니다.
  • Spring 애플리케이션의 종속성 맵을 봅니다.
  • 요청 성능을 확인합니다.
  • 실시간 라이브 메트릭을 모니터링합니다.
  • 요청 실패를 확인합니다.
  • 애플리케이션 메트릭을 확인합니다.
  • 애플리케이션 로그를 확인합니다.

Application Insights에서 제공할 수 있는 관찰 가능한 많은 관점은 다음과 같습니다.

  • 애플리케이션 맵
  • 성능
  • 오류
  • 메트릭
  • 라이브 메트릭
  • 가용성
  • 로그

Application Insights 기능 사용

Application Insights 기능을 사용하도록 설정하면 다음을 수행할 수 있습니다.

  • 탐색 창에서 Application Insights를 선택하여 Application Insights개요 페이지를 봅니다. 개요 페이지에는 실행 중인 모든 애플리케이션에 대한 개요가 표시됩니다.

  • 애플리케이션 맵을 선택하여 애플리케이션 간의 호출 상태 확인합니다.

    Screenshot of the Azure portal that shows the Application Insights Application map page.

  • customers-service 간의 링크를 선택하고 SQL의 쿼리와 petclinic 같은 자세한 내용을 확인합니다.

  • 엔드포인트를 선택하여 엔드포인트에 요청하는 모든 애플리케이션을 확인합니다.

  • 탐색 창에서 성능을 선택하여 모든 애플리케이션의 작업, 종속성 및 역할의 성능 데이터를 확인합니다.

    Screenshot of the Azure portal that shows the Application Insights Performance page.

  • 탐색 창에서 실패를 선택하여 애플리케이션에서 예기치 않은 오류 또는 예외를 확인합니다.

    Screenshot of the Azure portal that shows the Application Insights Failures page.

  • 탐색 창에서 메트릭을 선택하고 네임스페이스를 선택하여 Spring Boot 메트릭과 사용자 지정 메트릭(있는 경우)을 모두 표시합니다.

    Screenshot of the Azure portal that shows the Application Insights Metrics page.

  • 탐색 창에서 라이브 메트릭을 선택하여 다양한 차원에 대한 실시간 메트릭을 확인합니다.

    Screenshot of the Azure portal that shows the Application Insights Live Metrics page.

  • 탐색 창에서 가용성을 선택하여 Application Insights에서 가용성 테스트를 만들어 웹앱의 가용성 및 응답성을 모니터링합니다.

    Screenshot of the Azure portal that shows the Application Insights Availability page.

  • 탐색 창에서 로그를 선택하여 모든 애플리케이션의 로그를 보거나 필터링할 때 하나의 애플리케이션 로그를 cloud_RoleName봅니다.

    Screenshot of the Azure portal that shows the Application Insights Logs page.

Azure Portal을 사용하여 Application Insights 관리

다음 절차를 사용하여 Java In-Process 에이전트를 사용하도록 설정합니다.

  1. 서비스로 이동 | 서비스 인스턴스의 개요 페이지를 선택한 다음 모니터링 섹션에서 Application Insights 선택합니다.

  2. Application Insights 사용을 선택하여 Azure Spring Apps에서 Application Insights를 사용하도록 설정합니다.

  3. Application Insights의 기존 인스턴스를 선택하거나 새 인스턴스를 만듭니다.

  4. Application Insights가 사용하도록 설정되면 하나의 선택적 샘플링 비율(기본값 10.0%)을 구성할 수 있습니다.

    Screenshot of the Azure portal that shows the Azure Spring Apps instance with Application Insights page and Enable Application Insights checkbox highlighted.

  5. 저장을 선택하여 변경 내용을 저장합니다.

참고 항목

다른 Azure Spring Apps 인스턴스에서 동일한 Application Insights 인스턴스를 사용하지 마세요. 그렇지 않으면 혼합 데이터가 표시됩니다.

포털을 사용하여 Application Insights의 현재 설정을 확인하거나 업데이트할 수 있습니다.

Azure Portal을 사용하여 Application Insights를 사용하도록 설정

  1. Application Insights를 선택합니다.

  2. 바인딩 편집 또는 언바운드 하이퍼링크를 선택하여 Application Insights를 사용하도록 설정합니다.

    Screenshot of the Azure portal Azure that shows the Azure Spring Apps instance with the Application Insights page and the 'Edit binding' option.

  3. Application Insights 또는 샘플링 비율을 편집한 다음, 저장을 선택합니다.

Application Insights를 사용하지 않도록 설정

  1. Application Insights를 선택합니다.

  2. 바인딩 해제를 선택하여 Application Insights를 사용하지 않도록 설정합니다.

    Screenshot of the Azure portal that shows the Azure Spring Apps instance with the Application Insights page and the Unbind binding option.

Application Insights 설정 변경

Application Insights 열 아래에서 이름을 선택하여 Application Insights 섹션을 엽니다.

Screenshot of the Azure portal that shows the Azure Spring Apps instance with the Application Insights page.

빌드 서비스에서 Application Insights 빌드팩 바인딩 편집

빌드 서비스에서 Application Insights 빌드팩 바인딩에 대한 현재 설정을 확인하고 업데이트하려면 다음 단계를 수행합니다.

  1. 빌드 서비스를 선택합니다.
  2. 작성기를 선택합니다.
  3. [바인딩] 열 아래에서 편집을 선택합니다.

Application Insights 설정은 바인딩 유형 열 아래에 나열된 ApplicationInsights 항목에 있습니다.

  1. 바운드 하이퍼링크를 선택하거나 줄임표 아래의 바인딩 편집을 선택하여 Application Insights 빌드팩 바인딩을 열고 편집합니다.

    Screenshot of the Azure portal that shows the Edit bindings for default builder pane.

  2. 바인딩 설정을 편집한 다음, 저장을 선택합니다.

    Screenshot of the Azure portal that shows the Edit binding pane.

Azure CLI를 사용하여 Application Insights 관리

Azure CLI 명령을 사용하여 Application Insights를 관리할 수 있습니다. 다음 명령에서 <자리 표시자> 텍스트를 설명된 값으로 바꿔야 합니다. <service-instance-name> 자리 표시자는 Azure Spring Apps 인스턴스의 이름을 참조합니다.

Application Insights 사용

Azure Spring Apps 인스턴스를 만들 때 Application Insights를 구성하려면 다음 명령을 사용합니다. app-insights 인수의 경우 Application Insights 이름 또는 리소스 ID를 지정할 수 있습니다.

az spring create \
    --resource-group <resource-group-name> \
    --name "service-instance-name" \
    --app-insights <name-or-resource-ID> \
    --sampling-rate <sampling-rate>
az spring create \
    --resource-group <resource-group-name> \
    --name "service-instance-name" \
    --app-insights <name-or-resource-ID> \
    --sampling-rate <sampling-rate> \
    --sku Enterprise

다음 예제와 같이 Application Insights 연결 문자열(기본 설정) 또는 계측 키를 사용할 수도 있습니다.

az spring create \
    --resource-group <resource-group-name> \
    --name <service-instance-name> \
    --app-insights-key <connection-string-or-instrumentation-key> \
    --sampling-rate <sampling-rate>
az spring create \
    --resource-group <resource-group-name> \
    --name <service-instance-name> \
    --app-insights-key <connection-string-or-instrumentation-key> \
    --sampling-rate <sampling-rate> \
    --sku Enterprise

Application Insights를 사용하지 않도록 설정

Azure Spring Apps 인스턴스를 만들 때 Application Insights를 사용하지 않도록 설정하려면 다음 명령을 사용합니다.

az spring create \
    --resource-group <resource-group-name> \
    --name <service-instance-name> \
    --disable-app-insights
az spring create \
    --resource-group <resource-group-name> \
    --name <service-instance-name> \
    --disable-app-insights \
    --sku Enterprise

Application Insights 설정 확인

기존 Azure Spring Apps 인스턴스의 Application Insights 설정을 확인하려면 다음 명령을 사용합니다.

az spring app-insights show \
    --resource-group <resource-group-name> \
    --name <service-instance-name>

Application Insights 업데이트

연결 문자열(기본 설정) 또는 계측 키를 사용하도록 Application Insights를 업데이트하려면 다음 명령을 사용합니다.

az spring app-insights update \
    --resource-group <resource-group-name> \
    --name <service-instance-name> \
    --app-insights-key <connection-string-or-instrumentation-key> \
    --sampling-rate <sampling-rate>

리소스 이름 또는 ID를 사용하도록 Application Insights를 업데이트하려면 다음 명령을 사용합니다.

az spring app-insights update \
    --resource-group <resource-group-name> \
    --name <service-instance-name> \
    --app-insights <name-or-resource-ID> \
    --sampling-rate <sampling-rate>

update 명령을 사용하여 Application Insights를 사용하지 않도록 설정

기존 Azure Spring Apps 인스턴스에서 Application Insights를 사용하지 않도록 설정하려면 다음 명령을 사용합니다.

az spring app-insights update \
    --resource-group <resource-group-name> \
    --name <service-instance-name> \
    --disable

Application Insights 빌드팩 바인딩 관리

이 섹션은 Enterprise 계획에만 적용되며 이전 섹션을 보완하는 지침을 제공합니다.

Azure Spring Apps Enterprise 계획은 buildpack 바인딩을 사용하여 Azure 애플리케이션 Insights를 형식ApplicationInsights과 통합합니다. 자세한 내용은 APM 통합 및 CA 인증서 구성 방법을 참조하세요.

Application Insights 빌드팩 바인딩을 만들려면 다음 명령을 사용합니다.

az spring build-service builder buildpack-binding create \
    --resource-group <your-resource-group-name> \
    --service <your-service-instance-name> \
    --name <your-binding-name> \
    --builder-name <your-builder-name> \
    --type ApplicationInsights \
    --properties sampling-percentage=<your-sampling-percentage> \
                 connection-string=<your-connection-string>

모든 빌드팩 바인딩을 나열하고 ApplicationInsights 형식의 Application Insights 바인딩을 찾으려면 다음 명령을 사용합니다.

az spring build-service builder buildpack-binding list \
    --resource-group <your-resource-group-name> \
    --service <your-service-resource-name> \
    --builder-name <your-builder-name>

Application Insights 빌드팩 바인딩을 바꾸려면 다음 명령을 사용합니다.

az spring build-service builder buildpack-binding set \
    --resource-group <your-resource-group-name> \
    --service <your-service-instance-name> \
    --name <your-binding-name> \
    --builder-name <your-builder-name> \
    --type ApplicationInsights \
    --properties sampling-percentage=<your-sampling-percentage> \
                 connection-string=<your-connection-string>

Application Insights 빌드팩 바인딩을 가져오려면 다음 명령을 사용합니다.

az spring build-service builder buildpack-binding show \
    --resource-group <your-resource-group-name> \
    --service <your-service-instance-name> \
    --name <your-binding-name> \
    --builder-name <your-builder-name>

Application Insights 빌드팩 바인딩을 삭제하려면 다음 명령을 사용합니다.

az spring build-service builder buildpack-binding delete \
    --resource-group <your-resource-group-name> \
    --service <your-service-instance-name> \
    --name <your-binding-name> \
    --builder-name <your-builder-name>

자동화

다음 섹션에서는 Bicep, ARM 템플릿(Azure Resource Manager 템플릿) 또는 Terraform을 사용하여 배포를 자동화하는 방법을 설명합니다.

Bicep

Bicep 파일을 사용하여 배포하려면 다음 콘텐츠를 main.bicep 파일에 복사합니다. 자세한 내용은 Microsoft.AppPlatform Spring/monitoringSettings를 참조하세요.

param springName string
param location string = resourceGroup().location

resource spring 'Microsoft.AppPlatform/Spring@2020-07-01' = {
  name: springName
  location: location
  properties: {}
}

resource monitorSetting 'Microsoft.AppPlatform/Spring/monitoringSettings@2020-11-01-preview' = {
  parent: spring
  name: 'default'
  properties: {
    appInsightsInstrumentationKey: '00000000-0000-0000-0000-000000000000'
    appInsightsSamplingRate: 88
  }
}

ARM 템플릿

ARM 템플릿을 사용하여 배포하려면 다음 콘텐츠를 azuredeploy.json 파일에 복사합니다. 자세한 내용은 Microsoft.AppPlatform Spring/monitoringSettings를 참조하세요.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "springName": {
      "type": "string"
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "resources": [
    {
      "type": "Microsoft.AppPlatform/Spring",
      "apiVersion": "2020-07-01",
      "name": "[parameters('springName')]",
      "location": "[parameters('location')]",
      "properties": {}
    },
    {
      "type": "Microsoft.AppPlatform/Spring/monitoringSettings",
      "apiVersion": "2020-11-01-preview",
      "name": "[format('{0}/{1}', parameters('springName'), 'default')]",
      "properties": {
        "appInsightsInstrumentationKey": "00000000-0000-0000-0000-000000000000",
        "appInsightsSamplingRate": 88
      },
      "dependsOn": [
        "[resourceId('Microsoft.AppPlatform/Spring', parameters('springName'))]"
      ]
    }
  ]
}

Terraform

Terraform 배포의 경우 다음 템플릿을 사용합니다. 자세한 내용은 azurerm_spring_cloud_service를 참조하세요.

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_application_insights" "example" {
  name                = "tf-test-appinsights"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  application_type    = "web"
}

resource "azurerm_spring_cloud_service" "example" {
  name                = "example-springcloud"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  sku_name            = "S0"

  config_server_git_setting {
    uri          = "https://github.com/Azure-Samples/piggymetrics"
    label        = "config"
    search_paths = ["dir1", "dir2"]
  }

  trace {
    connection_string = azurerm_application_insights.example.connection_string
    sample_rate       = 10.0
  }

  tags = {
    Env = "staging"
  }
}

Enterprise 계획의 자동화는 지원 보류 중입니다. 설명서는 사용 가능한 즉시 추가됩니다.

Java 에이전트 업데이트/업그레이드

Java 에이전트는 JDK를 사용하여 정기적으로 업데이트/업그레이드되며, 이는 다음 시나리오에 영향을 줄 수 있습니다.

참고 항목

JDK 버전은 매년 분기별로 업데이트/업그레이드됩니다.

  • 업데이트/업그레이드하기 전에 Java 에이전트를 사용하는 기존 애플리케이션은 영향을 받지 않습니다.
  • 업데이트/업그레이드 후 만든 애플리케이션은 새 버전의 Java 에이전트를 사용합니다.
  • 이전에 Java 에이전트를 사용하지 않았던 기존 애플리케이션은 새 버전의 Java 에이전트를 사용하려면 다시 시작하거나 다시 배포해야 합니다.

빌드팩이 업데이트되면 Java 에이전트가 업데이트/업그레이드됩니다.

Java 에이전트 구성 핫 로드

Azure Spring Apps에는 애플리케이션을 다시 시작하지 않고 에이전트 구성 설정을 조정하는 핫 로딩 메커니즘이 있습니다.

참고 항목

핫 로드 메커니즘에는 몇 분 정도의 지연이 있습니다.

  • Java 에이전트를 이미 사용하도록 설정한 경우 Application Insights 인스턴스 또는 SamplingRate 값을 변경해도 애플리케이션을 다시 시작할 필요가 없습니다.

  • Java 에이전트를 사용하도록 설정하면 애플리케이션을 다시 시작해야 합니다.

  • Java 에이전트를 사용하지 않도록 설정하면 애플리케이션은 몇 분 후에 모든 모니터링 데이터 전송을 중지합니다. 애플리케이션을 다시 시작하여 Java 런타임 환경에서 에이전트를 제거할 수 있습니다.

Azure Spring Apps와 Application Insights 간의 개념 일치

Azure Spring Apps Application Insights
App * 애플리케이션 맵/역할
* 라이브 메트릭/역할
* 실패/역할/클라우드 역할
* 성능/역할/할 수 있는 역할
App Instance * 애플리케이션 맵/역할 인스턴스
* 라이브 메트릭/서비스 이름
* 오류/역할/클라우드 인스턴스
* 성능/역할/가능한 인스턴스

Azure Spring Apps의 이름은 App Instance 다음 시나리오에서 변경되거나 생성됩니다.

  • 새 애플리케이션을 만듭니다.
  • JAR 파일 또는 소스 코드를 기존 애플리케이션에 배포합니다.
  • 블루/그린 배포를 시작합니다.
  • 애플리케이션을 다시 시작합니다.
  • 애플리케이션 배포를 중지한 다음 다시 시작합니다.

데이터가 Application Insights에 저장되면 Java 에이전트를 사용하도록 설정한 이후 만들어지거나 배포된 Azure Spring Apps 앱 인스턴스의 기록이 여기에 포함됩니다. 예를 들어 Application Insights 포털에서 어제 만들어졌지만 지난 24시간과 같이 특정 시간 범위 내에서 삭제된 애플리케이션 데이터를 볼 수 있습니다. 다음 시나리오는 이것의 작동 방식을 보여 줍니다.

  • Java 에이전트가 사용하도록 설정된 Azure Spring Apps에서 오늘 오전 8시경에 애플리케이션을 만든 다음, 오늘 오전 8시 10분경에 JAR 파일을 이 애플리케이션에 배포했습니다. 몇 가지 테스트가 끝나면 코드를 변경하고 오늘 오전 8시 30분에 이 애플리케이션에 새 JAR 파일을 배포합니다. 그런 다음 휴식을 취하고 오전 11시 경에 돌아오면 Application Insights에서 일부 데이터를 검사. 있잖아요:
    • 지난 24시간 동안의 시간 범위와 실패, 성능 및 메트릭이 있는 애플리케이션 맵의 3개 인스턴스
    • 지난 1시간 동안의 시간 범위와 실패, 성능 및 메트릭이 있는 애플리케이션 맵의 1개 인스턴스
    • 라이브 메트릭의 인스턴스 1개.
  • Java 에이전트가 사용하도록 설정된 Azure Spring Apps에서 오늘 오전 8시경에 애플리케이션을 만든 다음, 오늘 오전 8시 10분경에 JAR 파일을 이 애플리케이션에 배포했습니다. 오늘 오전 8시 30분경, 다른 JAR 파일을 사용하여 파란색/녹색 배포를 시도합니다. 현재 이 애플리케이션에 대해 두 개의 배포가 있습니다. 오늘 오전 11시 경에 휴식을 취한 후 Application Insights에서 일부 데이터를 검사 합니다. 있잖아요:
    • 지난 24시간 동안의 시간 범위와 실패, 성능 및 메트릭이 있는 애플리케이션 맵의 3개 인스턴스
    • 지난 1시간 동안의 시간 범위와 실패, 성능 및 메트릭이 있는 애플리케이션 맵의 2개 인스턴스
    • 라이브 메트릭의 2개 인스턴스

다음 단계