zuplo 7.15.1 → 7.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,16 +53,16 @@ bodies. How long Zuplo keeps them depends on your plan. See
53
53
  These features handle prompt or completion text when you turn them on. Each one
54
54
  is off until you add it.
55
55
 
56
- | Feature | Content it handles | Where the content goes |
57
- | ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
58
- | [Semantic Cache](../../policies/ai-gateway-semantic-cache-inbound.mdx) | The system prompt and the most recent messages, which form the match key, and the provider's response. | Zuplo's semantic cache, which keeps each app's entries apart. Entries expire after `expirationSecondsTtl` seconds: one hour by default, up to 30 days. |
59
- | [Comet Opik Tracing](../../policies/ai-gateway-opik-tracing-inbound.mdx) | Prompt messages or input, completion text, model, token counts, temperature and maximum tokens, request ID, and route. | Your Comet Opik workspace and project. |
60
- | [Galileo Tracing](../../policies/ai-gateway-galileo-tracing-inbound.mdx) | Prompt and completion text, model parameters, finish reasons, token counts, duration, request ID, and route. | Your Galileo project and log stream. |
61
- | [Akamai AI Firewall](../../policies/ai-gateway-akamai-firewall-inbound.mdx) | Prompts and completions, for inspection. | Akamai Firewall for AI. |
62
- | [Prompt Injection Protection](../../policies/ai-gateway-prompt-injection.mdx) | The newest message of each request, for classification. | The classifier you configure: an OpenAI-compatible API, or another app on the same gateway and its provider. |
63
- | [Smart Router](../../policies/ai-gateway-smart-router-inbound.mdx) | The last user prompt, for classification. | The classifier you configure, such as another app on the same gateway and its provider. |
64
- | [Log plugins](../../articles/logging.mdx#log-integrations) | The request logs described earlier and messages that policies write with `context.log`. Content appears only if a custom policy logs it. | Your logging service, such as Datadog, Splunk, or AWS CloudWatch. |
65
- | [OpenTelemetry plugin](./tracing.mdx) | Span timings, HTTP method, URL, status code, and request ID. No prompt or completion text. | Zuplo's trace storage or your OpenTelemetry backend. |
56
+ | Feature | Content it handles | Where the content goes |
57
+ | ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
58
+ | [Semantic Cache](../../policies/ai-gateway-semantic-cache-inbound.mdx) | The system prompt and the most recent messages, which form the match key, and the provider's response. | Zuplo's semantic cache, which keeps each app's entries apart. Entries expire after `expirationSecondsTtl` seconds: one hour by default, up to 30 days. |
59
+ | [Comet Opik Tracing](../../policies/ai-gateway-opik-tracing-inbound.mdx) | Prompt messages or input, completion text, model, token counts, temperature and maximum tokens, request ID, and route. | Your Comet Opik workspace and project. |
60
+ | [Galileo Tracing](../../policies/ai-gateway-galileo-tracing-inbound.mdx) | Prompt and completion text, model parameters, finish reasons, token counts, duration, request ID, and route. | Your Galileo project and log stream. |
61
+ | [Akamai AI Firewall](../../policies/ai-gateway-akamai-firewall-inbound.mdx) | Prompts and completions, for inspection. | Akamai Firewall for AI. |
62
+ | [Prompt Injection Protection](../../policies/ai-gateway-prompt-injection.mdx) | The newest message of each request, for classification. | The classifier you configure: an OpenAI-compatible API, or another app on the same gateway and its provider. |
63
+ | [Smart Router](../../policies/ai-gateway-smart-router-inbound.mdx) | The last user prompt, for classification. | The classifier you configure, such as another app on the same gateway and its provider. |
64
+ | [Log plugins](../../articles/logging.mdx#log-integrations) | The request logs described earlier and messages that policies write with `context.log`. Content appears only if a custom policy logs it. | Your logging service, such as Datadog, Splunk, or AWS CloudWatch. |
65
+ | [OpenTelemetry plugin](./tracing.mdx) | Span timings, HTTP method, URL, status code, request ID, model, token usage, and cost. Prompt and completion text only when you turn on content capture. | Zuplo's trace storage or your OpenTelemetry backend. |
66
66
 
67
67
  The [Data Loss Prevention](../../policies/ai-gateway-dlp-inbound.mdx) policy
68
68
  scans content inside the gateway and doesn't send it to another service.
@@ -1,10 +1,10 @@
1
1
  ---
2
- title: AI Gateway Tracing
2
+ title: AI Gateway OpenTelemetry Tracing
3
3
  sidebar_label: Tracing
4
4
  description:
5
- Add the OpenTelemetry plugin to an AI Gateway to trace each request through
6
- its policies and provider call, and join model calls and tool calls in a
7
- trace.
5
+ Trace AI Gateway requests with OpenTelemetry GenAI spans that record model,
6
+ provider, token usage, cost, fallbacks, and optional prompt and completion
7
+ content.
8
8
  applies_to:
9
9
  product: gateway
10
10
  hosting: all
@@ -13,10 +13,11 @@ applies_to:
13
13
  An AI Gateway runs the same
14
14
  [OpenTelemetry plugin](../../articles/opentelemetry.mdx) as any Zuplo project.
15
15
  With the plugin on, each request to an app becomes a trace with a span for every
16
- policy in the app's chain, the AI Gateway handler, and the call to the LLM
17
- provider. The gateway reads W3C trace context (`traceparent`) from the caller
18
- and sends it on to the provider, so an agent's model calls join the agent's own
19
- trace.
16
+ policy in the app's chain, the AI Gateway handler, and every call to an LLM
17
+ provider. Provider calls are recorded as OpenTelemetry GenAI spans that carry
18
+ the model, token usage, cost, and outcome of each attempt. The gateway reads W3C
19
+ trace context (`traceparent`) from the caller and sends it on to the provider,
20
+ so an agent's model calls join the agent's own trace.
20
21
 
21
22
  <Diagram height="h-64">
22
23
  <DiagramNode id="agent">Agent</DiagramNode>
@@ -108,11 +109,12 @@ to change it.
108
109
  ## What a trace contains
109
110
 
110
111
  A request to an app produces a trace like the following. The app's policy chain
111
- appears inside the Configuration Executor span, one span per entry, and the call
112
- to the provider is a client span named after the provider's host:
112
+ appears inside the Configuration Executor span, one span per entry. Each call to
113
+ an LLM provider gets a GenAI inference span, with the HTTP call to the
114
+ provider's host nested under it:
113
115
 
114
116
  ```text
115
- POST <route>
117
+ POST <route> gen_ai.request.model, zuplo.ai_gateway.*
116
118
  ├── policies:inbound
117
119
  │ ├── policy:ai-gateway-configuration-loader-inbound
118
120
  │ └── policy:ai-gateway-configuration-executor-inbound
@@ -121,16 +123,203 @@ POST <route>
121
123
  │ ├── policy:ai-gateway-metering-inbound
122
124
  │ └── policy:ai-gateway-semantic-cache-inbound
123
125
  └── handler:aiGatewayHandlerV2
124
- └── POST: api.openai.com
126
+ └── chat gpt-5 gen_ai.*, zuplo.ai_gateway.cost.*
127
+ └── POST: api.openai.com
125
128
  ```
126
129
 
127
- Spans carry timings, the HTTP method, URL, and status code, and the request ID
128
- (`zp-rid`) that also appears in the gateway's logs. They don't carry prompt or
129
- completion text. To record content for evaluation, see
130
+ Every span carries timings and the request ID (`zp-rid`) that also appears in
131
+ the gateway's logs. HTTP spans add the method, URL, and status code. Prompt and
132
+ completion text is recorded only when you
133
+ [turn on content capture](#capture-prompts-and-completions).
134
+
135
+ ## GenAI inference spans
136
+
137
+ The gateway records one inference span for each attempt to call a provider: the
138
+ primary call, each [fallback](../fallback.mdx), a
139
+ [quota fallback](../usage-limits.mdx#when-a-limit-is-exceeded) after a usage
140
+ limit is exceeded, and each retry after a provider returns `429`. The spans
141
+ follow the
142
+ [OpenTelemetry semantic conventions for generative AI](https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/),
143
+ so backends that understand GenAI telemetry, such as Langfuse, Datadog LLM
144
+ Observability, Honeycomb, and Grafana, show model, token, and cost views without
145
+ any mapping.
146
+
147
+ There's nothing extra to enable. With the OpenTelemetry plugin registered,
148
+ inference spans appear for every sampled request. All of them use the
149
+ instrumentation scope `ai-gateway`.
150
+
151
+ ### Span names and kinds
152
+
153
+ Each inference span is a `CLIENT` span named `{operation} {model}`, for example
154
+ `chat gpt-5` or `embeddings text-embedding-3-small`. The operation comes from
155
+ the endpoint the client called:
156
+
157
+ | Endpoint | `gen_ai.operation.name` |
158
+ | ------------------------------------------------- | ----------------------- |
159
+ | `/v1/chat/completions`, `/v1/messages` | `chat` |
160
+ | `POST /v1/responses` | `chat` |
161
+ | `GET /v1/responses/{id}` | `fetch_response` |
162
+ | `DELETE /v1/responses/{id}` | `delete_response` |
163
+ | `/v1/messages/count_tokens` | `count_tokens` |
164
+ | `/v1/embeddings` | `embeddings` |
165
+ | Bedrock Runtime `converse` and `invoke` endpoints | `chat` |
166
+
167
+ A request that never reaches a provider, such as one a policy rejects or one
168
+ that fails validation, has no inference span. A semantic cache hit has none
169
+ either, because the gateway answers from the cache.
170
+
171
+ ### Inference span attributes
172
+
173
+ | Attribute | Description |
174
+ | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
175
+ | `gen_ai.operation.name` | The operation, from the table above. |
176
+ | `gen_ai.provider.name` | The provider, for example `openai`, `anthropic`, `gcp.vertex_ai`, `aws.bedrock`, or `azure.ai.openai`. |
177
+ | `zuplo.ai_gateway.provider.label` | The name of the provider in your gateway's **AI Providers** settings. |
178
+ | `gen_ai.request.model` | The model sent to the provider. |
179
+ | `gen_ai.request.stream` | `true` for a streamed request, otherwise `false`. |
180
+ | `gen_ai.request.max_tokens`, `temperature`, `top_p`, `top_k`, `seed`, and others | Sampling parameters, when the request sets them. |
181
+ | `gen_ai.response.id` | The provider's response ID. |
182
+ | `gen_ai.response.model` | The model that answered, as the provider reported it. |
183
+ | `gen_ai.response.finish_reasons` | The provider's own finish reasons, for example `["stop"]` or `["end_turn"]`. |
184
+ | `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens` | Token usage. Matches the usage that [AI Gateway analytics](./analytics.mdx) and usage limits record. |
185
+ | `gen_ai.usage.cache_read.input_tokens`, `gen_ai.usage.cache_write.input_tokens` | Prompt cache tokens, when the provider reports them. |
186
+ | `gen_ai.usage.reasoning.output_tokens` | Reasoning tokens, when the provider reports them. |
187
+ | `zuplo.ai_gateway.cost.usd` | The cost of the attempt in US dollars. |
188
+ | `zuplo.ai_gateway.cost.source` | Where the cost came from: `provider`, `catalog`, or `unpriced`. |
189
+ | `zuplo.ai_gateway.cost.accuracy` | `exact`, `estimated`, or `unpriced`. |
190
+ | `zuplo.ai_gateway.attempt` | `primary`, `fallback`, `quota_fallback`, or `retry` (a retry after a `429`). |
191
+ | `server.address`, `server.port` | The provider host. |
192
+ | `error.type` | Set on a failed attempt. See [Errors and fallbacks](#errors-and-fallbacks). |
193
+
194
+ Cost uses the same prices as budgets and spend analytics, including any
195
+ [custom pricing](../custom-pricing.mdx) you set.
196
+
197
+ ### Request span attributes
198
+
199
+ The request's root `SERVER` span summarizes what the gateway did with the
200
+ request:
201
+
202
+ | Attribute | Description |
203
+ | --------------------------------- | -------------------------------------------------------------------------------------------------------------- |
204
+ | `gen_ai.request.model` | The model the client asked for, before any routing or fallback policy changed it. |
205
+ | `zuplo.ai_gateway.cache.status` | `hit` or `miss`, when the app uses the [semantic cache](../../policies/ai-gateway-semantic-cache-inbound.mdx). |
206
+ | `zuplo.ai_gateway.refused_by` | The name of the policy that rejected the request, or `handler` when the gateway's handler rejected it. |
207
+ | `zuplo.ai_gateway.quota_fallback` | `true` when a usage limit sent the request to its quota fallback model. |
208
+
209
+ ### Errors and fallbacks
210
+
211
+ A failed attempt sets the span status to error and records a low-cardinality
212
+ `error.type`:
213
+
214
+ - The provider's HTTP status code, for example `503` or `429`.
215
+ - `timeout` when the attempt hit the fallback timeout.
216
+ - The error name, for example `TypeError`, when the call threw before a response
217
+ arrived.
218
+
219
+ The provider's error message isn't recorded, because it can quote the request.
220
+
221
+ Attempts for one request are siblings under the handler span. A request whose
222
+ primary model returns `503` and whose fallback succeeds looks like this:
223
+
224
+ ```text
225
+ handler:aiGatewayHandlerV2
226
+ ├── chat gpt-5 error.type=503, zuplo.ai_gateway.attempt=primary
227
+ │ └── POST: api.openai.com
228
+ └── chat claude-sonnet-4-5 zuplo.ai_gateway.attempt=fallback, usage, cost
229
+ └── POST: api.anthropic.com
230
+ ```
231
+
232
+ ### Streaming responses
233
+
234
+ For a streamed response, the HTTP span ends when the provider starts streaming,
235
+ and the inference span stays open until the stream finishes. The inference span
236
+ records:
237
+
238
+ - `gen_ai.response.time_to_first_chunk`: seconds from sending the request to the
239
+ first chunk of the stream.
240
+ - `zuplo.ai_gateway.stream.end`: `complete`, `error` (including an error event
241
+ inside the stream), or `client_cancelled` when the client disconnected first.
242
+ - Token usage and cost, read from the finished stream.
243
+
244
+ The plugin waits for an open inference span before it exports the trace, up to
245
+ five minutes after the response starts, so long streams export complete.
246
+
247
+ ## Capture prompts and completions
248
+
249
+ Inference spans don't record prompt or completion text by default. To record it,
250
+ set `instrumentation.genAi.captureContent` to `true`:
251
+
252
+ ```ts title="modules/zuplo.runtime.ts"
253
+ runtime.addPlugin(
254
+ new OpenTelemetryPlugin({
255
+ exporter: {
256
+ url: environment.OTEL_TRACES_URL,
257
+ headers: { "api-key": environment.OTEL_API_KEY },
258
+ },
259
+ instrumentation: {
260
+ genAi: { captureContent: true },
261
+ },
262
+ }),
263
+ );
264
+ ```
265
+
266
+ With capture on, each inference span records these attributes as JSON in the
267
+ OpenTelemetry GenAI message format:
268
+
269
+ - `gen_ai.system_instructions`: the system prompt.
270
+ - `gen_ai.input.messages`: the messages sent to the provider. Embeddings
271
+ requests don't record input.
272
+ - `gen_ai.output.messages`: the response the client received, including a
273
+ streamed response.
274
+
275
+ Each attribute is capped at 8 KiB and stays valid JSON when it's truncated. The
276
+ plugin turns capture on only for the boolean `true`.
277
+
278
+ Input is recorded as sent to the provider, after policies such as
279
+ [Data Loss Prevention](../../policies/ai-gateway-dlp-inbound.mdx) changed it.
280
+ Output is recorded as returned to the client, after every policy and hook that
281
+ changes the response. Well-known credential formats, such as API keys, bearer
282
+ tokens, JWTs, private keys, and cloud and GitHub tokens, are replaced with
283
+ placeholders such as `[REDACTED:api_key]`.
284
+
285
+ :::warning
286
+
287
+ Prompts and completions often contain personal or otherwise sensitive data.
288
+ Turning on content capture sends that content to Zuplo's trace storage and to
289
+ any backend you export to. Content capture doesn't remove personal data, so mask
290
+ it with the Data Loss Prevention policy, which runs before the content is
291
+ recorded.
292
+
293
+ :::
294
+
295
+ To capture content for a single app instead of the whole gateway, use a tracing
296
+ policy. See
130
297
  [AI Gateway data handling](./data-handling.mdx#capture-prompts-and-completions-for-an-app).
131
298
 
132
- For a streaming response, the provider span ends when the provider starts
133
- streaming, so it shows the provider's time to first byte.
299
+ ## Query GenAI spans in your backend
300
+
301
+ Because the attributes follow the semantic conventions, you can query model
302
+ activity directly in your backend. For example:
303
+
304
+ - Compare models by latency: filter on `gen_ai.operation.name = chat` and group
305
+ span duration by `gen_ai.response.model`.
306
+ - Find spend by provider: sum `zuplo.ai_gateway.cost.usd` grouped by
307
+ `zuplo.ai_gateway.provider.label`.
308
+ - Find failing providers: filter on `error.type` and group by
309
+ `gen_ai.provider.name`.
310
+ - See how often fallbacks serve traffic: count spans where
311
+ `zuplo.ai_gateway.attempt` is `fallback` or `quota_fallback`.
312
+ - Measure time to first token: chart `gen_ai.response.time_to_first_chunk` for
313
+ streamed requests.
314
+ - Find rejected requests: filter request spans on `zuplo.ai_gateway.refused_by`.
315
+
316
+ :::note
317
+
318
+ The OpenTelemetry plugin exports traces and logs, not metrics. Use span
319
+ durations and attributes to measure latency and usage, or see
320
+ [AI Gateway analytics](./analytics.mdx) for built-in dashboards.
321
+
322
+ :::
134
323
 
135
324
  ## Follow an agent run across gateways
136
325
 
@@ -90,4 +90,3 @@ builds and deploys the reverted branch like any other change.
90
90
  - [Environments](./environments.mdx)
91
91
  - [Branch-Based Deployments](./branch-based-deployments.mdx)
92
92
  - [Source Control and Deployment](../concepts/source-control-and-deployment.mdx)
93
- - [Blue-Green Deployments for Your Backend](../guides/blue-green-deployments.mdx)
@@ -40,6 +40,9 @@ By default, when the OpenTelemetry plugin is enabled, the following is traced:
40
40
  [MCP Gateway](../mcp-gateway/overview.mdx) handles gets a span that follows
41
41
  the OpenTelemetry semantic conventions for MCP. See
42
42
  [MCP tracing](#mcp-tracing).
43
+ - AI Gateway calls: Every call the AI Gateway makes to an LLM provider gets a
44
+ GenAI inference span with the model, token usage, and cost. See
45
+ [AI Gateway tracing](../ai-gateway/observability/tracing.mdx).
43
46
 
44
47
  ### Limitations
45
48
 
@@ -112,6 +112,5 @@ hides it from your users. See
112
112
 
113
113
  ## Next steps
114
114
 
115
- - [Blue-Green Deployments for Your Backend](./blue-green-deployments.mdx)
116
115
  - [Route to Different Backends Based on Geolocation](./geolocation-backend-routing.mdx)
117
116
  - [Securing your backend](../articles/securing-your-backend.mdx)
@@ -109,6 +109,37 @@ as Entra tenant admin consent. If connections start requiring frequent
109
109
  reauthorization after setting `prompt: false`, remove the option so the consent
110
110
  grant is requested again.
111
111
 
112
+ ## Extra Authorization Parameters
113
+
114
+ `authorizationParams` adds query parameters to the upstream authorization
115
+ request, for providers that need a parameter the MCP authorization flow does not
116
+ send. A configured value replaces any parameter of the same name. It supports
117
+ `user-oauth` and `shared-oauth`.
118
+
119
+ Google is the common case. Google issues a refresh token only when the
120
+ authorization request carries `access_type=offline`, and it does not advertise
121
+ the `offline_access` scope, so the MCP SDK never asks for one on its own.
122
+ Without it, every Google connection lasts only as long as its one-hour access
123
+ token and then needs a new sign-in. Set `access_type` to `offline` and `prompt`
124
+ to `consent`: Google returns a refresh token only on a fresh consent, so users
125
+ who approved the app before would otherwise still get none.
126
+
127
+ ```json
128
+ {
129
+ "authMode": "user-oauth",
130
+ "scopes": ["https://www.googleapis.com/auth/gmail.modify"],
131
+ "prompt": "consent",
132
+ "authorizationParams": {
133
+ "access_type": "offline"
134
+ }
135
+ }
136
+ ```
137
+
138
+ `authorizationParams` cannot set parameters the gateway manages:
139
+ `response_type`, `response_mode`, `client_id`, `redirect_uri`, `scope`, `state`,
140
+ `code_challenge`, `code_challenge_method`, and `resource`. Use the `scopes`
141
+ option for scopes and the `prompt` option for `prompt`.
142
+
112
143
  ## OAuth Metadata Validation
113
144
 
114
145
  The gateway checks OAuth metadata before connecting to an upstream. If a
@@ -197,9 +228,9 @@ Use this mode in enterprise deployments where the gateway and the upstream trust
197
228
  the same identity provider (for example, Okta Cross-App Access), so upstream
198
229
  access follows the caller's identity without a per-user upstream consent flow.
199
230
  The `user-oauth`/`shared-oauth` options — `scopes`, `scopeDelimiter`, `prompt`,
200
- `skipIssuerMetadataValidation`, `skipResourceIndicatorValidation`, and
201
- `clientRegistration` — do not apply; the `id-jag` mode is configured entirely
202
- through the `idJag` option.
231
+ `authorizationParams`, `skipIssuerMetadataValidation`,
232
+ `skipResourceIndicatorValidation`, and `clientRegistration` — do not apply; the
233
+ `id-jag` mode is configured entirely through the `idJag` option.
203
234
 
204
235
  ```json
205
236
  {
@@ -56,6 +56,9 @@
56
56
  {
57
57
  "required": ["prompt"]
58
58
  },
59
+ {
60
+ "required": ["authorizationParams"]
61
+ },
59
62
  {
60
63
  "required": ["skipIssuerMetadataValidation"]
61
64
  },
@@ -126,6 +129,31 @@
126
129
  }
127
130
  ]
128
131
  },
132
+ "authorizationParams": {
133
+ "type": "object",
134
+ "x-advanced": true,
135
+ "description": "Extra query parameters added to upstream authorization requests, for providers that need a parameter the MCP authorization flow does not send. For example, Google issues a refresh token only when the request carries `access_type=offline`, so Google upstreams set `{ \"access_type\": \"offline\" }`, usually with `prompt: \"consent\"`. A value replaces any parameter of the same name. Parameters the gateway manages cannot be set here: `response_type`, `response_mode`, `client_id`, `redirect_uri`, `scope`, `state`, `code_challenge`, `code_challenge_method`, `resource`, and `prompt` (use the `prompt` option). Available only with `user-oauth` and `shared-oauth`.",
136
+ "propertyNames": {
137
+ "minLength": 1,
138
+ "not": {
139
+ "enum": [
140
+ "response_type",
141
+ "response_mode",
142
+ "client_id",
143
+ "redirect_uri",
144
+ "scope",
145
+ "state",
146
+ "code_challenge",
147
+ "code_challenge_method",
148
+ "resource",
149
+ "prompt"
150
+ ]
151
+ }
152
+ },
153
+ "additionalProperties": {
154
+ "type": "string"
155
+ }
156
+ },
129
157
  "skipIssuerMetadataValidation": {
130
158
  "type": "boolean",
131
159
  "x-advanced": true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zuplo",
3
- "version": "7.15.1",
3
+ "version": "7.15.3",
4
4
  "type": "module",
5
5
  "description": "The official Zuplo CLI for local development and platform management",
6
6
  "homepage": "https://zuplo.com/docs/cli/overview",
@@ -32,9 +32,9 @@
32
32
  "zuplo": "zuplo.js"
33
33
  },
34
34
  "dependencies": {
35
- "@zuplo/cli": "7.15.1",
36
- "@zuplo/core": "7.15.1",
37
- "@zuplo/runtime": "7.15.1",
38
- "@zuplo/test": "7.15.1"
35
+ "@zuplo/cli": "7.15.3",
36
+ "@zuplo/core": "7.15.3",
37
+ "@zuplo/runtime": "7.15.3",
38
+ "@zuplo/test": "7.15.3"
39
39
  }
40
40
  }
@@ -1,199 +0,0 @@
1
- ---
2
- title: Blue-Green Deployments for Your Backend
3
- sidebar_label: Blue-Green Deployments
4
- description:
5
- Run blue and green backend stacks behind Zuplo, test the idle stack through a
6
- staging gateway with the same policies, then switch traffic and roll back
7
- safely.
8
- tags:
9
- - backends
10
- - deployment
11
- - testing
12
- applies_to:
13
- product: gateway
14
- hosting: all
15
- ---
16
-
17
- A blue-green deployment runs two copies of your backend, called blue and green.
18
- One copy serves live traffic while you deploy and test the next release on the
19
- other. When the new release passes its tests, you switch traffic to it, and the
20
- old copy stays ready as a fallback.
21
-
22
- This guide shows how to run a blue-green release behind a Zuplo gateway: a
23
- staging gateway environment sends test traffic to the idle backend with the same
24
- routes and policies as production, and production keeps serving the live backend
25
- until you switch.
26
-
27
- :::tip
28
-
29
- Zuplo already deploys changes to the gateway itself without downtime, and you
30
- can roll back to any earlier build. You don't need two gateways to change your
31
- gateway safely. See
32
- [Deployments and Rollbacks](../articles/deployments-and-rollbacks.mdx). This
33
- guide is about releasing your backend.
34
-
35
- :::
36
-
37
- ## How it works
38
-
39
- Each backend copy has its own URL, for example its own load balancer or its own
40
- hostname. Two Zuplo environments run the same project:
41
-
42
- - **Production** is deployed from your default branch and forwards requests to
43
- the live backend.
44
- - **Staging** is a preview environment deployed from a separate branch. It
45
- forwards requests to the idle backend, so you can test a release through the
46
- same routes and policies that production uses.
47
-
48
- <Diagram height="h-72">
49
- <DiagramNode id="clients">API clients</DiagramNode>
50
- <DiagramNode id="testers">Testers</DiagramNode>
51
- <DiagramNode id="prod" variant="zuplo">
52
- Production environment
53
- </DiagramNode>
54
- <DiagramNode id="staging" variant="zuplo">
55
- Staging environment
56
- </DiagramNode>
57
- <DiagramNode id="blue" variant="blue">
58
- Blue backend (live)
59
- </DiagramNode>
60
- <DiagramNode id="green" variant="green">
61
- Green backend (idle)
62
- </DiagramNode>
63
- <DiagramEdge from="clients" to="prod" />
64
- <DiagramEdge from="testers" to="staging" />
65
- <DiagramEdge from="prod" to="blue" label="BACKEND_URL" />
66
- <DiagramEdge from="staging" to="green" label="BACKEND_URL" />
67
- </Diagram>
68
-
69
- ## Prerequisites
70
-
71
- - A Zuplo project connected to [source control](../articles/source-control.mdx),
72
- so that branches deploy as environments
73
- - Two copies of your backend, each reachable at its own URL
74
-
75
- ## 1/ Read the backend URL from an environment variable
76
-
77
- Set each route's backend URL from an
78
- [environment variable](../articles/environment-variables.mdx), so the production
79
- and staging environments can forward to different backends with the same code.
80
- With the [URL Forward handler](../handlers/url-forward.mdx):
81
-
82
- ```json title="config/routes.oas.json"
83
- {
84
- "handler": {
85
- "export": "urlForwardHandler",
86
- "module": "$import(@zuplo/runtime)",
87
- "options": {
88
- "baseUrl": "${env.BACKEND_URL}"
89
- }
90
- }
91
- }
92
- ```
93
-
94
- In the Zuplo Portal, open
95
- [**Settings**](https://portal.zuplo.com/+/account/project/settings/general) and
96
- select **Environment Variables**. Add `BACKEND_URL` for the **Production**
97
- environment, set to the URL of the live backend, for example
98
- `https://blue.api.example.com`.
99
-
100
- ## 2/ Create the staging environment
101
-
102
- Create a branch, for example `staging`, and push it. Zuplo deploys it as a
103
- preview environment with its own URL. See
104
- [Branch-Based Deployments](../articles/branch-based-deployments.mdx).
105
-
106
- Then set up the staging environment:
107
-
108
- - **Backend URL:** add `BACKEND_URL` for the `staging` preview environment, set
109
- to the idle backend, for example `https://green.api.example.com`. A variable
110
- can apply to one named preview environment, so it doesn't affect other
111
- branches.
112
- - **Secrets:** give every secret your policies read, such as a shared secret
113
- from your CDN, a value for the staging environment.
114
- - **API keys:** preview environments use a separate
115
- [API key bucket](../articles/api-key-buckets.mdx) from production, so
116
- production keys don't work there. Create test consumers in the preview bucket,
117
- or see
118
- [Custom bucket configuration](../articles/api-key-buckets.mdx#custom-bucket-configuration).
119
- - **mTLS client certificates:** if your backend requires a
120
- [client certificate](../articles/securing-backend-mtls.mdx), enable the
121
- certificate for the preview environment type.
122
- - **Custom domain (optional):** give the staging environment its own hostname,
123
- such as `staging-api.example.com`. See
124
- [Custom Domains](../articles/custom-domains.mdx).
125
-
126
- Redeploy the staging environment after you change its variables, because
127
- variable changes take effect on the next deployment.
128
-
129
- ## 3/ Release a new backend version
130
-
131
- 1. Deploy the new version of your backend to the idle copy (green).
132
- 2. Test it through the staging environment's URL. Requests pass through the same
133
- routes and policies as production, so the test covers authentication, rate
134
- limits, and request validation, not only the backend.
135
- 3. When the release passes, switch production traffic to green (see the next
136
- section).
137
- 4. Point the staging environment at the copy that's now idle (blue), ready for
138
- the next release.
139
-
140
- ## 4/ Switch production traffic
141
-
142
- Choose where the switch happens:
143
-
144
- | Switch at | How | Zuplo deployment needed |
145
- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
146
- | Your load balancer or DNS | Point the hostname that production's `BACKEND_URL` uses at green, for example by changing a load balancer rule or DNS record | No |
147
- | The production `BACKEND_URL` | Change the variable to green's URL, then redeploy the production environment | Yes |
148
-
149
- Switching at the load balancer is the fastest option, in both directions,
150
- because it doesn't wait for a gateway deployment. Changing `BACKEND_URL` keeps
151
- the switch in Zuplo, and the redeploy rolls out without downtime.
152
-
153
- ## Roll back
154
-
155
- Switch back the same way you switched forward. Blue is still running the
156
- previous release, so rolling back only changes where traffic goes:
157
-
158
- - If you switched at the load balancer or DNS, point it back at blue.
159
- - If you switched with `BACKEND_URL`, set it back to blue's URL and redeploy
160
- production.
161
-
162
- :::caution
163
-
164
- Redeploying an earlier build of the production environment doesn't restore an
165
- earlier value of `BACKEND_URL`, because a redeploy uses current settings. Change
166
- the variable itself to roll back a `BACKEND_URL` switch.
167
-
168
- :::
169
-
170
- ## Test through production instead of a staging environment
171
-
172
- If the gateway configuration doesn't change between releases, testers can reach
173
- the idle backend through the production environment itself. A routing policy
174
- sends requests with a header such as `x-stage: canary`, or from users on an
175
- allow list, to the idle backend, and everyone else to the live one. You don't
176
- need a staging environment or a second hostname. The trade-off is that both
177
- backends share one gateway deployment. See
178
- [Route Employees to Canary or Staging Backends](./canary-routing-for-employees.mdx).
179
-
180
- ## When to run blue and green gateway environments
181
-
182
- Most releases only need the pattern above. If a release also changes the gateway
183
- configuration in a risky way, such as new authentication policies, you can run
184
- two long-lived environments from `blue` and `green` branches and switch traffic
185
- in front of Zuplo, for example by changing your CDN's origin.
186
-
187
- Both environments are preview environments, which serve traffic the same way as
188
- production. Production-scoped settings don't apply to them, so set their
189
- [environment variables](../articles/environment-variables.mdx) for each named
190
- environment and choose which [API key bucket](../articles/api-key-buckets.mdx)
191
- they use. See
192
- [Preview vs Production Environments](../articles/environments.mdx#preview-vs-production-environments-or-multiple-production-environments).
193
-
194
- ## Next steps
195
-
196
- - [Deployments and Rollbacks](../articles/deployments-and-rollbacks.mdx)
197
- - [Testing Preview Environments](../articles/testing-preview-environments.mdx)
198
- - [Fail Over Between Backends](./backend-failover.mdx)
199
- - [Connect to an AWS ALB with mTLS](../articles/connect-to-aws-alb-with-mtls.mdx)