Skip to content

Commit

Permalink
Merge pull request #85 from axiomhq/netlify-deploy-env-vars
Browse files Browse the repository at this point in the history
debug netlify site and deploy env vars
  • Loading branch information
dasfmi authored Dec 1, 2022
2 parents 724badd + c904bca commit 4d6f3a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ For more information check out the [official documentation](https://axiom.co/doc
- If you are using Vercel, make sure you have the [Axiom Vercel integration](https://www.axiom.co/vercel)
installed. On other platforms you must create an API token and set those environment variables:

:warning: next-axiom is still experimental for non-Vercel platforms and is subject to change.

```
AXIOM_DATASET: the dataset the logs will be ingested into
AXIOM_TOKEN: the API token you created for ingestion to the dataset
Expand Down
6 changes: 3 additions & 3 deletions src/platform/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export default class GenericConfig implements Provider {
injectPlatformMetadata(logEvent: LogEvent, source: string) {
logEvent.platform = {
environment: this.environment,
region: this.environment,
source: source,
region: this.region,
source: source + '-log',
};
}

generateRequestMeta(req: any): RequestReport {
generateRequestMeta(req: NextApiRequest): RequestReport {
return {
startTime: new Date().getTime(),
path: req.url!,
Expand Down
33 changes: 19 additions & 14 deletions src/platform/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import { LogEvent, PlatformInfo } from '../logger';
import type Provider from './base';
import GenericConfig from './generic';

const netlifySiteId = process.env.SITE_ID;
const netlifyBuildId = process.env.BUILD_ID;
const netlifyContext = process.env.CONTEXT;
const netlifyDeploymentUrl = process.env.DEPLOYMENT_URL;
const netlifyDeploymentId = process.env.DEPLOYMENT_ID;

export interface NetlifyInfo extends PlatformInfo {
buildId?: string;
context?: string;
deploymentUrl?: string;
deploymentId?: string;
siteId?: string;
}

export default class NetlifyConfig extends GenericConfig implements Provider {
netlifyBuildId = process.env.BUILD_ID;
netlifyContext = process.env.CONTEXT;
netlifyDeploymentUrl = process.env.DEPLOY_URL;
netlifyDeploymentId = process.env.DEPLOY_ID;

wrapWebVitalsObject(metrics: any[]): any {
return metrics.map(m => ({
Expand All @@ -22,23 +25,25 @@ export default class NetlifyConfig extends GenericConfig implements Provider {
netlify: {
environment: this.environment,
source: 'web-vital',
buildId: this.netlifyBuildId,
context: this.netlifyContext,
deploymentUrl: this.netlifyDeploymentUrl,
deploymentId: this.netlifyDeploymentId,
siteId: netlifySiteId,
buildId: netlifyBuildId,
context: netlifyContext,
deploymentUrl: netlifyDeploymentUrl,
deploymentId: netlifyDeploymentId,
},
}))
}

injectPlatformMetadata(logEvent: LogEvent, source: string) {
logEvent.netlify = {
environment: this.environment,
region: this.region,
source: source,
buildId: this.netlifyBuildId,
context: this.netlifyContext,
deploymentUrl: this.netlifyDeploymentUrl,
deploymentId: this.netlifyDeploymentId,
region: source === 'edge' ? process.env.DENO_REGION : process.env.AWS_REGION,
source: source + '-log',
siteId: netlifySiteId,
buildId: netlifyBuildId,
context: netlifyContext,
deploymentUrl: netlifyDeploymentUrl,
deploymentId: source === 'edge' ? process.env.DENO_DEPLOYMENT_ID : netlifyDeploymentId,
};
}
}

1 comment on commit 4d6f3a0

@vercel
Copy link

@vercel vercel bot commented on 4d6f3a0 Dec 1, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

next-axiom-example – ./

next-axiom-example-lemon.vercel.app
next-axiom-example-git-main.axiom.dev
next-axiom-example.axiom.dev

Please sign in to comment.