[Yandex Cloud documentation](../../index.md) > [Monium](../index.md) > [Data delivery](index.md) > Otel Collector > Java demo application example with an agent

# Setting up a demo Java app and collecting telemetry

## Getting started {#before-you-begin}

Sign up for Yandex Cloud and create a [billing account](../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../billing/quickstart/index.md) and [link](../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../resource-manager/concepts/resources-hierarchy.md).


## Setting up a demo app and telemetry delivery {#example-app}

In this example, you will install the [Spring PetClinic](https://github.com/spring-projects/spring-petclinic) demo app and configure it to send telemetry to Monium. 

To install the demo application, you can temporarily create a Yandex Compute Cloud [VM](../../compute/concepts/vm.md). Learn more about creating a suitable VM [here](../../compute/operations/vm-create/create-linux-vm.md).

Below are examples of commands for installing the demo application on Linux Ubuntu.

{% note warning %}

For the `OTel Collector` agent to work correctly, the VM or server must allow _outgoing traffic_ on TCP port `443`.

For the demo application to work correctly, the VM or server must allow _incoming traffic_ on TCP ports `4317`, `4318`, and `8080`.

If you are using a Compute Cloud VM, [create](../../vpc/operations/security-group-create.md) and [link](../../compute/operations/vm-control/vm-change-security-groups-set.md) to it a [security group](../../vpc/concepts/security-groups.md) allowing these traffic types.

{% endnote %}

{% list tabs group=instructions %}

- Your infrastructure {#user-infrastructure}

  1. Install [Git](https://git-scm.com/install/) and [Java](https://jdk.java.net/) suitable for your OS. For example:
  
      ```bash
      sudo apt update
      sudo apt install -y git openjdk-17-jdk
      ```
  1. Download and install an [OTel Collector](https://github.com/open-telemetry/opentelemetry-collector-releases/releases) agent suitable for your OS. For example:
  
      ```bash
      wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.144.0/otelcol_0.144.0_linux_amd64.tar.gz
      tar xvf otelcol_0.144.0_linux_amd64.tar.gz
      ```
  1. Set environment variables containing data for agent authentication in Monium:
  
      ```bash
      export MONIUM_PROJECT=folder__<folder_ID>
      export MONIUM_API_KEY=<API_key>
      ```
  
      Where:
  
      * `<folder_ID>`: [ID of the folder](../../resource-manager/operations/folder/get-id.md) to house your Monium [project](../concepts/glossary.md#project).
      * `<api_key>`: Service account [API key](../../iam/concepts/authorization/api-key.md).
  
          This [service account](../../iam/concepts/users/service-accounts.md) must have the `monium.telemetry.writer` [role](../security/index.md#monium-telemetry-writer) or more granular roles to writing metrics, logs, or traces. The API key must have the `yc.monium.telemetry.write` [scope](../../iam/concepts/authorization/api-key.md#scoped-api-keys) or narrower scopes for writing metrics, logs, or traces.
  1. Create a file named `otel-collector.yaml` and paste the following contents to it:
  
      ```yaml
      receivers:
        otlp:
          protocols:
            grpc:
            http:
  
      exporters:
        otlp_grpc/monium:
          compression: zstd
          endpoint: ingest.monium.yandex.cloud:443
          headers:
            Authorization: "Api-Key ${env:MONIUM_API_KEY}"
            x-monium-project: "${env:MONIUM_PROJECT}"
          sending_queue:
            batch:
  
      service:
        pipelines:
          metrics:
            receivers: [ otlp ]
            exporters: [ otlp_grpc/monium ]
          traces:
            receivers: [ otlp ]
            exporters: [ otlp_grpc/monium ]
          logs:
            receivers: [ otlp ]
            exporters: [ otlp_grpc/monium ]
        telemetry:
          metrics:
            level: normal
            readers:
              - periodic:
                  exporter:
                    otlp:
                      protocol: http/protobuf
                      endpoint: http://localhost:4318
                  interval: 30000
                  timeout: 5000
      ```
  1. Run the [OTel Collector](opentelemetry.md) agent:
  
      ```bash
      ./otelcol --config otel-collector.yaml
      ```
  
      Once active, the agent will start listening on ports `4317` (gRPC) and `4318` (HTTP).
  1. Open a new terminal window, then download and build the `Spring PetClinic` application:
  
      ```bash
      git clone https://github.com/spring-projects/spring-petclinic
      cd spring-petclinic
      ./mvnw -DskipTests package
      ```
  
      Result:
  
      ```text
      ...
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESS
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time:  53.308 s
      [INFO] Finished at: 2026-05-05T18:56:22Z
      [INFO] ------------------------------------------------------------------------
      ```
  1. Download the OpenTelemetry Java agent:
  
      ```bash
      curl -L -o opentelemetry-javaagent.jar \
      https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
      ```
  1. Run the demo application using the Java agent to send telemetry to OTel Collector:
  
      ```bash
      cd ~/spring-petclinic
      OTEL_SERVICE_NAME=spring-petclinic \
      OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE="delta" \
      java -javaagent:./opentelemetry-javaagent.jar -jar target/*.jar
      ```
  
      Result:
  
      ```text
      ...
      2026-05-05T19:00:31.981Z  INFO 3657 --- [           main] 
      o.s.s.petclinic.PetClinicApplication     : Started PetClinicApplication in 9.287 seconds (process running for 12.883)
      ```
  1. Open the running `Spring PetClinic` demo app in your browser:
  
      * If the application is installed on your local computer, its address is `http://localhost:8080`.
      * If you used a VM to install the application, its address is `http://<VM_public_IP_address>:8080`.
  
  1. Interact with the demo application UI as a user: open a menu, click a button, enter new owner details, schedule an appointment, etc.

{% endlist %}
  
## Viewing telemetry in Monium {#view-telemetry}

{% list tabs group=instructions %}

- Monium UI {#console}

  1. On the [Monium](https://monium.yandex.cloud) home page, select a data type section on the left:

      {% list tabs group=monium_telemetry_type %}

      - Metrics {#metrics}

        1. At the top, set the data search time period on the timeline.
        1. In the search bar, enter a query to search for telemetry data:
        
            * `project = <project_ID>`: Select the project specified in `x-monium-project` of the application's telemetry transmission configuration.
            
                This may be a cloud (`cloud__<cloud_ID>`) or folder (`folder__<folder_ID>`) project, or another [project](project.md#project-create).
            * `cluster = <cluster_name>`: Select the name of the installation that runs your application. If no cluster is specified, `cluster = default` is used.
            * `service = <service_name>`: Name of your application or service. You can use the `OTEL_SERVICE_NAME` environment variable to provide it.
            
              If you do not see the required labels in the suggestions, you can enter them manually. However, the system most likely has not received data with these labels. See [Data delivery troubleshooting](troubleshooting.md) for possible solutions.
        
        1. Click **Execute query** or **Execute**.
        
            The page will show data that matches the query.

        ![image](../../_assets/monium/petclinic-metrics.png)

        More on [metrics](../metrics/metric-explorer.md).

      - Logs {#logs}

        1. At the top, set the data search time period on the timeline.
        1. In the search bar, enter a query to search for telemetry data:
        
            * `project = <project_ID>`: Select the project specified in `x-monium-project` of the application's telemetry transmission configuration.
            
                This may be a cloud (`cloud__<cloud_ID>`) or folder (`folder__<folder_ID>`) project, or another [project](project.md#project-create).
            * `cluster = <cluster_name>`: Select the name of the installation that runs your application. If no cluster is specified, `cluster = default` is used.
            * `service = <service_name>`: Name of your application or service. You can use the `OTEL_SERVICE_NAME` environment variable to provide it.
            
              If you do not see the required labels in the suggestions, you can enter them manually. However, the system most likely has not received data with these labels. See [Data delivery troubleshooting](troubleshooting.md) for possible solutions.
        
        1. Click **Execute query** or **Execute**.
        
            The page will show data that matches the query.

        ![image](../../_assets/monium/petclinic-logs.png)

        More on [logs](../logs/logs-explorer.md).

      - Traces {#traces}

        1. At the top, set the data search time period on the timeline.
        1. In the search bar, enter a query to search for telemetry data:
        
            * `project = <project_ID>`: Select the project specified in `x-monium-project` of the application's telemetry transmission configuration.
            
                This may be a cloud (`cloud__<cloud_ID>`) or folder (`folder__<folder_ID>`) project, or another [project](project.md#project-create).
            * `cluster = <cluster_name>`: Select the name of the installation that runs your application. If no cluster is specified, `cluster = default` is used.
            * `service = <service_name>`: Name of your application or service. You can use the `OTEL_SERVICE_NAME` environment variable to provide it.
            
              If you do not see the required labels in the suggestions, you can enter them manually. However, the system most likely has not received data with these labels. See [Data delivery troubleshooting](troubleshooting.md) for possible solutions.
        
        1. Click **Execute query** or **Execute**.
        
            The page will show data that matches the query.

        ![image](../../_assets/monium/petclinic-traces.png)

        More on [traces](../traces/operations/traces-explorer.md).

      {% endlist %}

  1. To view information about the data shard, select **Shards** on the left and then, the shard with your service name.

{% endlist %}