getsentry / relay

Sentry event forwarding and ingestion service.
https://docs.sentry.io/product/relay/
Other
321 stars 91 forks source link

[Support Request] How to configure Sentry Relay in proxy mode? #1935

Closed span closed 1 year ago

span commented 1 year ago

Hi!

I am not able to set up a Sentry Relay in proxy mode. I am running in AKS.

Example output log:

Defaulted container "sentry-relay" out of: sentry-relay, sentry-relay-init (init)
2023-03-14T19:57:08Z [relay::setup] INFO: launching relay from config folder /work/.relay
2023-03-14T19:57:08Z [relay::setup] INFO:   relay mode: proxy
2023-03-14T19:57:08Z [relay::setup] INFO:   relay id: <some generated guid>
2023-03-14T19:57:08Z [relay::setup] INFO:   public key: <some generated key>
2023-03-14T19:57:08Z [relay::setup] INFO:   log level: TRACE
2023-03-14T19:57:08Z [relay_server::actors::outcome] INFO: Configured to emit outcomes as client reports
2023-03-14T19:57:08Z [relay_server::actors::outcome] INFO: OutcomeProducer started.
2023-03-14T19:57:08Z [relay_server::actors::outcome_aggregator] INFO: outcome aggregator started
2023-03-14T19:57:08Z [relay_server::actors::processor] INFO: starting 2 envelope processing workers
2023-03-14T19:57:08Z [relay_server::actors::envelopes] INFO: envelope manager started
2023-03-14T19:57:08Z [relay_server::actors::project_cache] INFO: project cache started
2023-03-14T19:57:08Z [relay_server::utils::garbage] DEBUG: Start garbage collection thread
2023-03-14T19:57:08Z [relay_server::actors::project_upstream] INFO: project upstream cache started
2023-03-14T19:57:08Z [relay_server::actors::project_local] INFO: project local cache started
2023-03-14T19:57:08Z [relay_server::actors::relays] INFO: key cache started
2023-03-14T19:57:08Z [relay_metrics::aggregation] INFO: aggregator started
2023-03-14T19:57:08Z [relay_server::actors::project_local] DEBUG: Loading local states from directory "/work/.relay/projects"
2023-03-14T19:57:08Z [relay_server::service] INFO: spawning http server
2023-03-14T19:57:08Z [relay_server::service] INFO:   listening on: http://127.0.0.1:3000/
2023-03-14T19:57:08Z [actix_net::server::server] INFO: Starting 2 workers
2023-03-14T19:57:08Z [actix_net::server::server] INFO: Starting server on 127.0.0.1:3000
2023-03-14T19:57:08Z [relay_system::controller] INFO: relay server starting
2023-03-14T19:57:18Z [relay_server::actors::project_local] DEBUG: Loading local states from directory "/work/.relay/projects"

My configuration (excluding service) is currently as follows:

apiVersion: v1
kind: ConfigMap
metadata:
  name: sentry-relay
  labels:
    app: sentry
data:
  config.yml: |-
    relay:
      mode: proxy
      upstream: https://o1296801.ingest.sentry.io
      host: 0.0.0.0
      port: 3000
    logging:
      level: TRACE
  6524158.json: |
    {
      "slug": "<project name as displayed in sentry gui>",
      "publicKeys": [
        {
          "publicKey": "<redacted dsn key>",
          "isEnabled": true
        }
      ],
      "config": {
        "allowedDomains": ["*"]
      }
    }

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sentry-relay
  labels:
    app: sentry
spec:
  selector:
    matchLabels:
      app: sentry
      role: relay
  replicas: 1
  revisionHistoryLimit: 3
  template:
    metadata:
      labels:
        app: sentry
        role: relay
    spec:
      initContainers:
        - name: sentry-relay-init
          image: getsentry/relay
          imagePullPolicy: IfNotPresent
          args:
            - "credentials"
            - "generate"
          env:
            - name: RELAY_PORT
              value: '3000'
          volumeMounts:
            - name: credentials
              mountPath: /work/.relay
            - name: config
              mountPath: /work/.relay/config.yml
              subPath: config.yml
              readOnly: true
      containers:
        - name: sentry-relay
          image: getsentry/relay
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 3000
          env:
            - name: RELAY_PORT
              value: '3000'
          volumeMounts:
            - name: credentials
              mountPath: /work/.relay
            - name: config
              mountPath: /work/.relay/config.yml
              subPath: config.yml
              readOnly: true
            - name: config
              mountPath: /work/.relay/projects/6524158.json
              subPath: 6524158.json
              readOnly: true
      volumes:
      - name: config
        configMap:
          name: sentry-relay
          defaultMode: 0644
      - name: credentials
        emptyDir: {}

I am sending events using a sentry-cli container as follow:

/work # export SENTRY_DSN='http://<redacted dsn key>@sentry-relay:3000/6524158'
/work # sentry-cli send-event -m 'A test event'
Event dispatched: 1a6a0e30-34b6-45df-86be-cbc8cfb47f3d

So it seems the event is sent to the Relay and a Guid is returned. If I I for example remove the port from the SENTRY_DSN variable, the event dispatching seems to time out so I'm pretty sure my Relay receives the event.

There is nothing in the logs of the Relay however, and nothing is the Sentry issue list. It seems strange to me that I do not configure the organisation id anywhere, but instead the project id and slug.

I have not been able to find a complete example on how to configure Relay in either Static or Proxy mode.

Can you please help in providing such examples?

span commented 1 year ago

For some magic reason it seems to relay events now. Hopefully this can work as an example for others.

GabrielPeral commented 1 year ago

HI, I am in the same situation than you, I have a couple of questions regarding your config. Why do you use credentials? According to docs, credentials are only supported in managed mode, not in proxy or static, right? Second is, the upstream field is another relay host? I would like to know if I can define a Sentry PoP as upstream instead of the SaaS (sentry.io) one Thanks in advance