Skip to content

Allow custom metrics endpoint#1037

Merged
danieljackins merged 4 commits intomasterfrom
metrics-config
Mar 5, 2024
Merged

Allow custom metrics endpoint#1037
danieljackins merged 4 commits intomasterfrom
metrics-config

Conversation

@danieljackins
Copy link
Copy Markdown
Contributor

@danieljackins danieljackins commented Feb 13, 2024

Allows users to set a custom metrics endpoint when loading Analytics. Tested locally by setting a custom endpoint and confirming it was used.

  • I've included a changeset (psst. run yarn changeset. Read about changesets here).

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 13, 2024

🦋 Changeset detected

Latest commit: 9baea6d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@segment/analytics-next Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/browser/src/browser/index.ts Outdated
Comment on lines +361 to +363
Stats.initRemoteMetrics(
legacySettings.metrics ?? { host: options.metricsEndpoint }
)
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.

What happens if Stats.initRemoteMetrics receives { host: undefined } ? Given that we were always sending the legacySettings.metrics object which looks like could be either full or undefined.

I'm also curious if we need this coalescing here as just above we're already overriding it.

/**
* Allows you to change the metrics endpoint used
*/
metricsEndpoint?: string
Copy link
Copy Markdown
Contributor

@silesky silesky Feb 14, 2024

Choose a reason for hiding this comment

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

Can you provide some background about the impetus / use case for a new setting (maybe link to the issue / description is OK)? (I saw an issue around this, but I figured we would just default to the overridden apiHost / protocol.)

i.e.

integrations: {
        'Segment.io': {
          // assume https://MY-CUSTOM-API-PROXY.com/v1/m  proxies to
          // https://api.segment.io/v1/m
          apiHost: 'MY-CUSTOM-API-PROXY.com/v1',
          protocol: 'https' // optional
        }

(forgive me if I am missing something silly)

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.

No that makes sense! Updated to default to that value and to respect protocol if set

Comment thread packages/browser/src/browser/index.ts
@danieljackins danieljackins merged commit e435279 into master Mar 5, 2024
@danieljackins danieljackins deleted the metrics-config branch March 5, 2024 21:00
@github-actions github-actions bot mentioned this pull request Mar 5, 2024
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