> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-parallel-read-in-order-multi-part.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> SDK de Java para ClickStack - la pila de observabilidad de ClickHouse

# Java

export const ClickStackIntegrates = ({signals = []}) => {
  const list = Array.isArray(signals) ? signals : String(signals).split(",");
  const supported = list.map(s => String(s).trim().toLowerCase());
  const pillStyle = {
    display: "inline-flex",
    alignItems: "center",
    padding: "0.125rem 0.625rem",
    borderRadius: "9999px",
    fontSize: "0.8125rem",
    fontWeight: 500,
    lineHeight: 1.6,
    color: "#161517",
    backgroundColor: "#faff69",
    border: "1px solid rgba(0, 0, 0, .1)",
    marginRight: "0.5rem"
  };
  return <div style={{
    margin: "0 0 1.25rem"
  }}>
      <span style={{
    marginRight: "0.5rem"
  }}>Esta guía integra:</span>
      {supported.includes("logs") && <span style={pillStyle}>Logs</span>}
      {supported.includes("metrics") && <span style={pillStyle}>Métricas</span>}
      {supported.includes("traces") && <span style={pillStyle}>Trazas</span>}
    </div>;
};

ClickStack usa el estándar OpenTelemetry para recopilar datos de telemetría (logs y
trazas). Las trazas se generan automáticamente mediante instrumentación automática, por lo que no se
requiere instrumentación manual para aprovecharlas.

<ClickStackIntegrates signals={['logs', 'metrics', 'traces']} />

<h2 id="getting-started">
  Primeros pasos
</h2>

<Note>
  Actualmente, la integración es compatible exclusivamente con **Java 8+**
</Note>

<h3 id="download-opentelemetry-java-agent">
  Descargar el agente de Java de OpenTelemetry
</h3>

Descarga [`opentelemetry-javaagent.jar`](https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar)
y coloca el archivo JAR en el directorio que prefieras. El archivo JAR contiene el agente
y las bibliotecas de instrumentación. También puedes usar el siguiente comando para
descargar el agente:

```shell theme={null}
curl -L -O https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
```

<h3 id="configure-environment-variables">
  Configurar variables de entorno
</h3>

Después, tendrás que configurar las siguientes variables de entorno en tu shell para enviar telemetría a ClickStack a través del OpenTelemetry Collector:

<Tabs>
  <Tab title="Managed ClickStack">
    ```shell theme={null}
    export JAVA_TOOL_OPTIONS="-javaagent:PATH/TO/opentelemetry-javaagent.jar" \
    OTEL_EXPORTER_OTLP_ENDPOINT=<YOUR_OTEL_COLLECTOR_HTTP_ENDPOINT> \
    OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
    OTEL_LOGS_EXPORTER=otlp \
    OTEL_SERVICE_NAME='<YOUR_SERVICE_NAME>'
    ```
  </Tab>

  <Tab title="ClickStack de código abierto">
    ```shell theme={null}
    export JAVA_TOOL_OPTIONS="-javaagent:PATH/TO/opentelemetry-javaagent.jar" \
    OTEL_EXPORTER_OTLP_ENDPOINT=<YOUR_OTEL_COLLECTOR_HTTP_ENDPOINT> \
    OTEL_EXPORTER_OTLP_HEADERS='authorization=<YOUR_INGESTION_API_KEY>' \
    OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
    OTEL_LOGS_EXPORTER=otlp \
    OTEL_SERVICE_NAME='<YOUR_SERVICE_NAME>'
    ```
  </Tab>
</Tabs>

*La variable de entorno `OTEL_SERVICE_NAME` se usa para identificar tu servicio en la aplicación HyperDX; puede ser cualquier nombre que quieras.*

La variable de entorno `OTEL_EXPORTER_OTLP_HEADERS` contiene la clave de API disponible en la aplicación HyperDX, en `Team Settings → API Keys`.

<h3 id="run-the-application-with-otel-java-agent">
  Ejecuta la aplicación con el agente de Java de OpenTelemetry
</h3>

```shell theme={null}
java -jar target/<APPLICATION_JAR_FILE>
```

<br />

Obtén más información sobre la instrumentación de Java con OpenTelemetry aquí: [https://opentelemetry.io/docs/instrumentation/java/](https://opentelemetry.io/docs/instrumentation/java/)
