Skip to content

Conversation

@travis-hoover-glean
Copy link
Contributor

@travis-hoover-glean travis-hoover-glean commented Jan 22, 2026

Summary

  • Add XGlean beforeRequest hook that sets X-Glean-Exclude-Deprecated-After and X-Glean-Experimental headers
  • Introduce new SDK options excludeDeprecatedAfter and includeExperimental with corresponding environment variable support
  • Add documentation for testing experimental features and deprecation testing

Test plan

  • Verify headers are set correctly when using SDK constructor options
  • Verify headers are set correctly when using environment variables
  • Confirm environment variables take precedence over SDK options
  • Ensure no headers are set when neither option is configured
import { Glean } from "@gleanwork/api-client";

process.env["X_Glean_Exclude_Deprecated_After"] = "2027-10-15";
process.env["X_Glean_Include_Experimental"] = "true";

// Test with SDK options
const glean = new Glean({
  apiToken: process.env["GLEAN_API_TOKEN"] ?? "",
  instance: process.env["GLEAN_INSTANCE"] ?? "",
  excludeDeprecatedAfter: "2026-10-15",
  includeExperimental: true,
  debugLogger: console,
});

async function run() {
  const result = await glean.client.search.query({ query: "test" });
  console.log("Response received:", result);
}

run().catch(console.error);
2026-01-22 at 14 43 50@2x

…esting

Add a new beforeRequest hook that sets X-Glean-Exclude-Deprecated-After
and X-Glean-Experimental headers based on SDK options or environment
variables. This allows users to test upcoming API changes and preview
experimental features before they become the default behavior.
@travis-hoover-glean travis-hoover-glean requested a review from a team as a code owner January 22, 2026 22:43
Copy link
Member

@rwjblue-glean rwjblue-glean left a comment

Choose a reason for hiding this comment

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

Overall looks good to me, only a few minor inline comments. I would like to see some tests for this though.

README.md Outdated
Comment on lines 1154 to 1156
// Set environment variables before initializing the SDK
process.env.X_Glean_Exclude_Deprecated_After = '2026-10-15';
process.env.X_Glean_Include_Experimental = 'true';
Copy link
Member

Choose a reason for hiding this comment

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

1/5 (nit, non-blocking)

I think I'd expect all caps for environment variables like this, WDYT?

Suggested change
// Set environment variables before initializing the SDK
process.env.X_Glean_Exclude_Deprecated_After = '2026-10-15';
process.env.X_Glean_Include_Experimental = 'true';
// Set environment variables before initializing the SDK
process.env.X_GLEAN_EXCLUDE_DEPRECATED_AFTER = '2026-10-15';
process.env.X_GLEAN_INCLUDE_EXPERIMENTAL = 'true';

I know the header values are not case-sensitive, but the environment variables are.

I don't feel strongly here at all, so feel free to do whatever you think is best.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lets do all caps, will update.

Comment on lines 43 to 48
/**
* Exclude API endpoints that will be deprecated after this date.
* Use this to test your integration against upcoming deprecations.
* Format: YYYY-MM-DD (e.g., '2026-10-15')
*/
excludeDeprecatedAfter?: string | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

3/5 (strong opinion: non-blocking)

Can you add a link to the developers.glean.com site for this (I think you've already written a guide that we can link to).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep!

Comment on lines +49 to +53
/**
* When true, enables experimental API features that are not yet generally available.
* Use this to preview and test new functionality.
*/
includeExperimental?: boolean | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

3/5 (strong opinion: non-blocking)

Same thing here, maybe a link to the website would be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now we dont have anything on the experimental stuff (not sure if we want to list out experiments or not) but if we do then I will add a link to that here

Comment on lines 17 to 25
const deprecatedValue = getFirstValue(
process.env["X_Glean_Exclude_Deprecated_After"],
hookCtx.options.excludeDeprecatedAfter,
);

const experimentalValue = getFirstValue(
process.env["X_Glean_Include_Experimental"],
hookCtx.options.includeExperimental === true ? "true" : undefined,
);
Copy link
Member

Choose a reason for hiding this comment

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

2/5 (minor preference, non-blocking)

This is interesting. I do agree with you that the environment variable should override, but it feels a little bit weird for the constructor arg to be completely ignored without any sort of message, warning, or anything.

Also, is it possible in the current implementation to use the environment variable to disable or only enable? Like, if you pass true to the constructor, how do you unset it via environment variable?

I don't think we fundamentally have to do that, just something I thought about while reviewing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya right now if you pass via the constructor there isn't a way to unset that programmatically. I think for now if you need to be setting/unsetting our suggestion is to use environment vars or just create 2 separate instances (one experimental and one regular one)

Rename environment variables to follow standard uppercase naming:
- X_Glean_Exclude_Deprecated_After -> X_GLEAN_EXCLUDE_DEPRECATED_AFTER
- X_Glean_Include_Experimental -> X_GLEAN_INCLUDE_EXPERIMENTAL
Add comprehensive tests covering:
- Headers set correctly via SDK constructor options
- Headers set correctly via environment variables
- Environment variables take precedence over SDK options
- No headers set when neither option is configured
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.

4 participants