server: support environment variable template for open telemetry URLs

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10165
Co-authored-by: Rob Dominguez <24390149+robertjdominguez@users.noreply.github.com>
GitOrigin-RevId: ef145deb469007c4a04237ec2219e0f81be8d6c9
This commit is contained in:
Toan Nguyen 2023-08-24 09:23:00 +07:00 committed by hasura-bot
parent 3f9abc4477
commit d40f9057e4
5 changed files with 26 additions and 24 deletions

View File

@ -27,8 +27,8 @@ import ProductBadge from '@site/src/components/ProductBadge';
## Introduction
[Distributed traces](/observability/cloud-monitoring/tracing.mdx) track and map journeys of user requests across various services or
components which can then be analyzed via observability tools.
[Distributed traces](/observability/cloud-monitoring/tracing.mdx) track and map journeys of user requests across various
services or components which can then be analyzed via observability tools.
Traces are typically used to diagnose or debug which part of your application could potentially be responsible for a
failure or error state and to monitor the performance of end-user interactions with your application.
@ -40,8 +40,7 @@ be configured in the `Settings` section of the Hasura Console.
:::info Support for metrics and logs
Currently, the OpenTelemetry Integration exports traces and metrics. The support for logs will be added in the
future.
Currently, the OpenTelemetry Integration exports traces and metrics. The support for logs will be added in the future.
:::
@ -49,9 +48,12 @@ future.
:::info Supported from
OpenTelemetry traces are supported for Hasura GraphQL Engine versions `v2.18.0` and above on Self-Hosted Enterprise, with support for metrics export added in `v2.31.0` and made available to all cloud tiers.
OpenTelemetry traces are supported for Hasura GraphQL Engine versions `v2.18.0` and above on Self-Hosted Enterprise,
with support for metrics export added in `v2.31.0` and made available to all cloud tiers.
We have deprecated the previous Open Telemetry exporter integration on Hasura Cloud in favor of this native feature, and you can now configure this directly via the Hasura Console's `Settings` page under the `Monitoring & Observability` section.
We have deprecated the previous Open Telemetry exporter integration on Hasura Cloud in favor of this native feature, and
you can now configure this directly via the Hasura Console's `Settings` page under the `Monitoring & Observability`
section.
All users are encouraged to migrate to this new integration.
@ -124,8 +126,9 @@ supported yet), so ensure that you use the appropriate endpoint for your chosen
#### Endpoint Notes
- You may have to append `/v1/traces` to the end of the receiver endpoint URL if the provided URL does not contain this
already. This depends on the observability vendor.
- Environment variable templating is available for the endpoint URL, e.g. `https://{{ENV_VAR}}/v1/traces`
- You may need to append `/v1/traces` or `/v1/metrics` to the end of the receiver endpoint URL if the provided URL does
not contain this already. This depends on the observability vendor.
- If you are running Hasura as a Docker container without host networking enabled, and want to connect to a local
[OpenTelemetry Collector](#opentelemetry-collector), you may want to use this as the endpoint:
`http://host.docker.internal:4318/v1/traces`.
@ -146,8 +149,8 @@ OpenTelemetry Protocol over HTTP (OTLP/HTTP with binary-encoded Protobuf payload
### Data Type
Selects the type of observability data points to be exported. `Traces` and `Metrics` are the only data types that are currently
supported.
Selects the type of observability data points to be exported. `Traces` and `Metrics` are the only data types that are
currently supported.
### Batch Size

View File

@ -65,7 +65,7 @@ export function Form(props: FormProps) {
name="tracesEndpoint"
label="Traces Endpoint"
placeholder="Your OpenTelemetry traces endpoint"
tooltip="OpenTelemetry-compliant traces receiver endpoint URL(At the moment, only HTTP is supported). This usually ends in /v1/traces"
tooltip="OpenTelemetry-compliant traces receiver endpoint URL(At the moment, only HTTP is supported). This usually ends in /v1/traces. Environment variable templating is available using the {{VARIABLE}} tag"
learnMoreLink="https://hasura.io/docs/latest/observability/opentelemetry/#endpoint"
clearButton
loading={skeletonMode}
@ -89,7 +89,7 @@ export function Form(props: FormProps) {
name="metricsEndpoint"
label="Metrics Endpoint"
placeholder="Your OpenTelemetry metrics endpoint"
tooltip="OpenTelemetry-compliant metrics receiver endpoint URL(At the moment, only HTTP is supported). This usually ends in /v1/metrics. Metrics will be sampled and exported every 15 seconds."
tooltip="OpenTelemetry-compliant metrics receiver endpoint URL(At the moment, only HTTP is supported). This usually ends in /v1/metrics. Metrics will be sampled and exported every 15 seconds. Environment variable templating is available using the {{VARIABLE}} tag"
learnMoreLink="https://hasura.io/docs/latest/observability/opentelemetry/#endpoint"
clearButton
loading={skeletonMode}

View File

@ -1,7 +1,7 @@
import { z } from 'zod';
import { requestHeadersSelectorSchema } from '../../../../../new-components/RequestHeadersSelector';
const endPointSchema = z.string().url({ message: 'Invalid URL' });
const endPointSchema = z.string();
// --------------------------------------------------
// SCHEMA

View File

@ -3,7 +3,7 @@ import { z } from 'zod';
// --------------------------------------------------
// UTILS
// --------------------------------------------------
const validUrlSchema = z.string().url({ message: 'Invalid URL' });
const validUrlSchema = z.string();
// --------------------------------------------------
// ATTRIBUTES

View File

@ -12,7 +12,8 @@ import Data.Environment (Environment)
import Data.Map.Strict qualified as Map
import Data.Set qualified as Set
import Data.Text qualified as Text
import Hasura.Base.Error (Code (InvalidParams), QErr, err400)
import Data.URL.Template (parseTemplate, renderTemplate)
import Hasura.Base.Error
import Hasura.EncJSON
import Hasura.Metadata.Class ()
import Hasura.Prelude hiding (first)
@ -66,13 +67,11 @@ parseOtelExporterConfig ::
parseOtelExporterConfig env enabledDataTypes OtelExporterConfig {..} = do
-- First validate everything but the trace endpoint
headers <- makeHeadersFromConf env _oecHeaders
let mkExportReq rawEndpoint = do
uri <-
maybeToEither (err400 InvalidParams "Invalid URL")
$ parseURI
$ Text.unpack rawEndpoint
uriRequest <-
first (err400 InvalidParams . tshow) $ requestFromURI uri
let mkExportReq rawEndpoint = mapLeft (err400 InvalidParams) $ do
rawTemplateEndpoint <- mapLeft Text.pack $ parseTemplate rawEndpoint
rawUri <- renderTemplate env rawTemplateEndpoint
uri <- maybeToEither "Invalid URL" $ parseURI (Text.unpack rawUri)
uriRequest <- first tshow $ requestFromURI uri
pure
$ Just
$ uriRequest
@ -91,9 +90,9 @@ parseOtelExporterConfig env enabledDataTypes OtelExporterConfig {..} = do
Nothing
| OtelMetrics `Set.member` enabledDataTypes ->
Left (err400 InvalidParams "Metrics export is enabled but metrics endpoint missing")
Just rawTracesEndpoint
Just rawMetricsEndpoint
| OtelMetrics `Set.member` enabledDataTypes ->
mkExportReq rawTracesEndpoint
mkExportReq rawMetricsEndpoint
_ -> pure Nothing -- disabled
pure
$ OtelExporterInfo