Skip to content

Commit

Permalink
attempt to load fromend rum config from .env file. Did not succeed
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPSplunk committed Jun 12, 2024
1 parent bf76a5d commit e5bc8c8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const myEnv = dotEnv.config({
path: resolve(__dirname, '../../.env'),
});
dotenvExpand.expand(myEnv);
console.log(`in next.config.js, process.env: ${JSON.stringify(process.env, null, 2)}`)


const {
AD_SERVICE_ADDR = '',
Expand All @@ -24,6 +26,10 @@ const {
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '',
OTEL_SERVICE_NAME = 'frontend',
PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = '',
NEXT_PUBLIC_SPLUNK_REALM = '',
NEXT_PUBLIC_SPLUNK_RUM_TOKEN = '',
NEXT_PUBLIC_SPLUNK_RUM_APP_NAME = '',
NEXT_PUBLIC_SPLUNK_RUM_ENV = '',
} = process.env;

const nextConfig = {
Expand Down Expand Up @@ -100,6 +106,10 @@ const nextConfig = {
NEXT_PUBLIC_PLATFORM: ENV_PLATFORM,
NEXT_PUBLIC_OTEL_SERVICE_NAME: OTEL_SERVICE_NAME,
NEXT_PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
NEXT_PUBLIC_SPLUNK_REALM,
NEXT_PUBLIC_SPLUNK_RUM_TOKEN,
NEXT_PUBLIC_SPLUNK_RUM_APP_NAME,
NEXT_PUBLIC_SPLUNK_RUM_ENV,
},
};

Expand Down
48 changes: 42 additions & 6 deletions src/frontend/splunk-rum.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
import React, { useEffect } from 'react';
import SplunkRum from '@splunk/otel-web';

SplunkRum.init({
realm: "us1",
rumAccessToken: "Qad35m7E6ld6p_-O_RxwEg",
applicationName: "astroshop",
deploymentEnvironment: "astroshop"
});
export async function getStaticProps() {
// Logs will be printed to the terminal
console.log('in splunk-rum.js, getStaticProps(), NEXT_PUBLIC_SPLUNK_REALM=', process.env.NEXT_PUBLIC_SPLUNK_REALM);

return {
props: {
rumRealm: process.env.NEXT_PUBLIC_SPLUNK_REALM,
rumToken: process.env.NEXT_PUBLIC_SPLUNK_RUM_TOKEN,
rumAppName: process.env.NEXT_PUBLIC_SPLUNK_RUM_APP_NAME,
rumEnv: process.env.NEXT_PUBLIC_SPLUNK_RUM_ENV,
},
};
}

const HomePage = ({ rumRealm, rumToken, rumAppName, rumEnv }) => {
useEffect(() => {
console.log('HomePage component mounted');
SplunkRum.init({
realm: rumRealm,
rumAccessToken: rumToken,
applicationName: rumAppName,
deploymentEnvironment: rumEnv,
});
}, [rumRealm, rumToken, rumAppName, rumEnv]);

return (
<div>
<h1> Splunk RUM Enabled</h1>
</div>
);
};

export default HomePage;

//SplunkRum.init({
// realm: rumRealm,
// rumAccessToken: rumToken,
// applicationName: rumAppName,
// deploymentEnvironment: rumEnv,
// });

0 comments on commit e5bc8c8

Please sign in to comment.