Skip to content

Add telemetry-to-caas kind for CaaS (Collector as a Service) support - #436

Open
vkozyura wants to merge 30 commits into
mainfrom
feature/caas-support
Open

Add telemetry-to-caas kind for CaaS (Collector as a Service) support#436
vkozyura wants to merge 30 commits into
mainfrom
feature/caas-support

Conversation

@vkozyura

Copy link
Copy Markdown
Contributor
  • Add telemetry-to-caas kind definition in package.json
  • Add getCredsForCaaS() to extract credentials from caas-service binding
  • Add augmentCaaSCreds() to configure OTLP endpoint URL
  • Handle CaaS in tracing and metrics exporters

Note: CaaS requires mTLS authentication with SAP-signed certificates. The certificate must be obtained separately via BTP Certificate Service.

- Add telemetry-to-caas kind definition in package.json
- Add getCredsForCaaS() to extract credentials from caas-service binding
- Add augmentCaaSCreds() to configure OTLP endpoint URL
- Handle CaaS in tracing and metrics exporters

Note: CaaS requires mTLS authentication with SAP-signed certificates.
The certificate must be obtained separately via BTP Certificate Service.

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is generally well-structured, but has one logic bug: when only a gRPC OTLP endpoint is present in the CaaS binding, credentials.url is set to undefined (the falsy http value), silently breaking the exporter. Please address the flagged issues before merging.

PR Bot Information

Version: 1.26.5

  • Event Trigger: pull_request.opened
  • LLM: anthropic--claude-4.6-sonnet
  • Correlation ID: be7942dc-b11a-457c-a83d-2aafac5eb2c3
  • File Content Strategy: Full file content

Comment thread lib/utils.js Outdated
Comment thread lib/utils.js
Comment thread lib/tracing/index.js Outdated
Comment thread lib/utils.js Fixed
Comment thread lib/utils.js Fixed
Comment thread lib/utils.js Fixed
This file should not be committed to the feature branch.
@vkozyura
vkozyura marked this pull request as ready for review June 30, 2026 12:41
@vkozyura
vkozyura requested a review from sjvans June 30, 2026 12:41
@hyperspace-pr-bot

Copy link
Copy Markdown
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Add telemetry-to-caas Kind for CaaS (Collector as a Service) Support

New Features

✨ Introduces a new telemetry-to-caas predefined kind that enables exporting traces and metrics to CaaS (Collector as a Service) — a managed OpenTelemetry Collector that can route telemetry to downstream backends like SAP Cloud Logging. The integration uses OTLP HTTP/protobuf and supports mTLS authentication with SAP-signed certificates.

Changes

  • package.json: Added the telemetry-to-caas kind definition with caas-service VCAP binding label, mtls_service_pattern default (caas-mtls|caas-cert), and OTLP protobuf exporters for both traces and metrics.
  • lib/utils.js: Added getCredsForCaaSMtls() to locate mTLS credentials from a user-provided VCAP service matching the configured pattern, and augmentCaaSCreds() to extract the OTLP HTTP endpoint and configure httpAgentOptions (cert/key) for mTLS. Both functions are exported.
  • lib/tracing/index.js: Imported augmentCaaSCreds and added a to-caas handler that applies CaaS credentials, sets OTEL_EXPORTER_OTLP_ENDPOINT, and configures the trace exporter URL (/v1/traces) with mTLS agent options.
  • lib/metrics/index.js: Imported augmentCaaSCreds and added a to-caas handler that applies CaaS credentials, sets OTEL_EXPORTER_OTLP_ENDPOINT, and configures the metrics exporter URL (/v1/metrics) with mTLS agent options.
  • README.md: Added telemetry-to-caas to the table of contents, updated predefined kinds count to six, and added a dedicated section documenting setup steps including mTLS certificate binding and user-provided service configuration.
  • CHANGELOG.md: Added entry for telemetry-to-caas kind support.
  • test/caas.test.js: Added unit tests for augmentCaaSCreds covering URL extraction, mTLS option setup, error on missing OTLP endpoint, idempotency guard, and missing mTLS credentials scenario.

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.26.11

  • Event Trigger: pull_request.ready_for_review
  • Output Template: Default Template
  • Correlation ID: 66d6ae55-ae8a-46ec-9f81-f076100fcf4a
  • LLM: anthropic--claude-4.6-sonnet
  • Summary Prompt: Default Prompt
  • File Content Strategy: Full file content

@hyperspace-pr-bot hyperspace-pr-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR adds the telemetry-to-caas kind with reasonable structure, but there are several correctness issues that need attention: the shared OTEL_EXPORTER_OTLP_ENDPOINT env var is clobbered by both signal exporters (traces and metrics overwrite each other), invalid base64 mTLS data is silently accepted before failing at TLS handshake time, and an unsanitised user-provided regex pattern can crash the process at startup.

PR Bot Information

Version: 1.26.11

  • LLM: anthropic--claude-4.6-sonnet
  • Event Trigger: pull_request.ready_for_review
  • Correlation ID: 66d6ae55-ae8a-46ec-9f81-f076100fcf4a
  • File Content Strategy: Full file content

Comment thread lib/utils.js
Comment thread lib/tracing/index.js Outdated
Comment thread lib/metrics/index.js Outdated
Comment thread lib/utils.js Outdated
Comment thread lib/utils.js Outdated
Comment thread lib/tracing/index.js Outdated
Comment on lines +132 to +133
// Set OTLP env vars to binding credentials (prevents stale env values from taking precedence)
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = credentials.baseUrl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Set OTLP env vars to binding credentials (prevents stale env values from taking precedence)
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = credentials.baseUrl

they should take precedence and should not be altered

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjvans: The forced override is intentional for certificate renewal. During renewal the CaaS service is unbound/rebound and the app is restaged. After cf restage, stale OTEL_EXPORTER_OTLP_ENDPOINT values can persist in the environment while the binding credentials contain the current correct endpoint. Without forcing the binding value, the app would use the stale endpoint, causing connection failures with the renewed certificates.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjvans: I tested certificate renewal as described in https://github.tools.sap/D051920/test_caas/blob/main/assets/CLI_GUIDE.md. It works also without this assignment above. Suggested changes are applied.

Comment thread lib/tracing/index.js Outdated
Comment thread lib/metrics/index.js Outdated
Comment on lines +85 to +86
// Set OTLP env vars to binding credentials (prevents stale env values from taking precedence)
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = credentials.baseUrl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Set OTLP env vars to binding credentials (prevents stale env values from taking precedence)
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = credentials.baseUrl

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjvans: same as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread lib/metrics/index.js Outdated
Comment thread lib/logging/index.js Outdated
Comment on lines +52 to +53
// Set OTLP env vars to binding credentials (prevents stale env values from taking precedence)
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = credentials.baseUrl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Set OTLP env vars to binding credentials (prevents stale env values from taking precedence)
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = credentials.baseUrl

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjvans: same as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread lib/utils.js Outdated
Comment thread lib/utils.js Outdated
Comment on lines +162 to +163
// Also set url for backwards compatibility (without path - exporter will append it)
credentials.url = credentials.otlp.http

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who needs this backwards compat?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment thread lib/utils.js Outdated

// Check for mTLS credentials (cert + key) in user-provided service
const mtlsCreds = getCredsForCaaSMtls()
if (mtlsCreds && mtlsCreds.cert && mtlsCreds.key) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (mtlsCreds && mtlsCreds.cert && mtlsCreds.key) {
if (mtlsCreds) {

mtlsCreds is only truthy if cert and key were available in getCredsForCaaSMtls

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread lib/utils.js Outdated
LOG._error && LOG.error('Failed to configure CaaS mTLS:', err.message)
}
} else {
LOG._warn && LOG.warn('CaaS requires mTLS authentication. No mTLS credentials found. Bind a user-provided service with cert and key (base64 encoded).')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated warning text

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment thread README.md Outdated
Comment on lines +306 to +325
1. **Bind the CaaS service** to your app with subject/issuer configuration:
```yaml
# mta.yaml
requires:
- name: my-caas-instance
parameters:
config:
subject: "CN=my-app,..."
issuer: "CN=SAP PKI Certificate Service Client CA,..."
```

2. **Obtain and bind mTLS credentials** via a user-provided service containing `cert` and `key` (base64 encoded):
```bash
cf create-user-provided-service caas-mtls-creds -p '{"cert":"<base64>","key":"<base64>"}'
cf bind-service my-app caas-mtls-creds
```

The mTLS certificate must be created (e.g., via `openssl`) and signed through SAP BTP Certificate Service. The certificate must be renewed periodically (typically every 7 days).

> Note: The user-provided service name must match the pattern configured in `mtls_service_pattern` (default: `caas-mtls|caas-cert`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

vkozyura and others added 12 commits August 17, 2026 12:09
Co-authored-by: sjvans <30337871+sjvans@users.noreply.github.com>
Co-authored-by: sjvans <30337871+sjvans@users.noreply.github.com>
Co-authored-by: sjvans <30337871+sjvans@users.noreply.github.com>
Co-authored-by: sjvans <30337871+sjvans@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants