Skip to content

Commit 6660f8a

Browse files
committed
Fix Dash0 web sdk
1 parent 983d244 commit 6660f8a

6 files changed

Lines changed: 81 additions & 19 deletions

File tree

frontend-project/src/App.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ function App() {
3838
path: location.pathname,
3939
search: location.search,
4040
hash: location.hash,
41-
timestamp: new Date().toISOString(),
41+
timestamp: Date.now(),
4242
})
4343

4444
// Track custom event for navigation
4545
sendEvent('navigation', {
4646
from: location.pathname,
47-
timestamp: new Date().toISOString(),
47+
timestamp: Date.now(),
4848
})
4949
}, [location.pathname, location.search, location.hash])
5050

@@ -58,7 +58,7 @@ function App() {
5858
return (
5959
<Box>
6060
<Navbar scrollToSection={scrollToSection} />
61-
<Dash0Test />
61+
{/* <Dash0Test /> */}
6262
<Routes>
6363
<Route path="/" element={<HomePage scrollToSection={scrollToSection} />} />
6464
<Route path="/cocktails" element={<CocktailsPageBasic />} />

frontend-project/src/components/Dash0Test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Dash0Test = () => {
2020
const handleTestClick = () => {
2121
trackButtonClick('test-button', {
2222
testType: 'basic-click',
23-
timestamp: new Date().toISOString()
23+
timestamp: Date.now()
2424
})
2525

2626
toaster.create({

frontend-project/src/config/dash0-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const baseConfig = {
1717
const developmentConfig = {
1818
...baseConfig,
1919
endpoint: {
20-
url: "https://devfreddy.com",
20+
url: "https://ingress.us-west-2.aws.dash0.com",
2121
authToken: "auth_Ro2pVbBZ47ZS2Sq48ieIRl9seWOl8P7B",
2222
dataset: "devfreddycom-dev"
2323
},
@@ -29,7 +29,7 @@ const developmentConfig = {
2929
const productionConfig = {
3030
...baseConfig,
3131
endpoint: {
32-
url: "https://devfreddy.com",
32+
url: "https://ingress.us-west-2.aws.dash0.com",
3333
authToken: "auth_Ro2pVbBZ47ZS2Sq48ieIRl9seWOl8P7B",
3434
dataset: "devfreddycom"
3535
},

frontend-project/src/hooks/useDash0Tracking.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const useDash0Tracking = () => {
1717
action,
1818
element,
1919
...properties,
20-
timestamp: new Date().toISOString(),
20+
timestamp: Date.now(),
2121
})
2222
}, [])
2323

@@ -78,7 +78,7 @@ export const useDash0Tracking = () => {
7878
*/
7979
const trackCustom = useCallback((eventName, properties = {}) => {
8080
sendEvent(eventName, {
81-
timestamp: new Date().toISOString(),
81+
timestamp: Date.now(),
8282
...properties,
8383
})
8484
}, [])
@@ -93,7 +93,7 @@ export const useDash0Tracking = () => {
9393
sendEvent('performance', {
9494
metric: metricName,
9595
value,
96-
timestamp: new Date().toISOString(),
96+
timestamp: Date.now(),
9797
...properties,
9898
})
9999
}, [])

frontend-project/src/instrumentation-client.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import { init, addSignalAttribute, sendEvent, reportError } from "@dash0/sdk-web
22
import { dash0Config, isDev } from './config/dash0-config.js';
33

44
// Initialize Dash0 for devfreddy.com with environment-specific configuration
5-
init(dash0Config);
5+
try {
6+
init(dash0Config);
67

7-
// Log initialization in development
8-
if (isDev) {
9-
console.log('Dash0 initialized with config:', {
10-
serviceName: dash0Config.serviceName,
11-
dataset: dash0Config.endpoint.dataset,
12-
environment: import.meta.env.MODE,
13-
});
8+
// Log initialization in development
9+
if (isDev) {
10+
console.log('Dash0 initialized with config:', {
11+
serviceName: dash0Config.serviceName,
12+
dataset: dash0Config.endpoint.dataset,
13+
environment: import.meta.env.MODE,
14+
endpoint: dash0Config.endpoint.url,
15+
});
16+
}
17+
} catch (error) {
18+
console.error('Failed to initialize Dash0:', error);
1419
}
1520

1621
// Add custom attributes for better filtering
@@ -25,7 +30,7 @@ sendEvent('page_view', {
2530
search: window.location.search,
2631
hash: window.location.hash,
2732
referrer: document.referrer,
28-
timestamp: new Date().toISOString(),
33+
timestamp: Date.now(),
2934
});
3035

3136
// Set up global error handler
@@ -59,7 +64,7 @@ if ('performance' in window) {
5964
domContentLoaded: navigation.domContentLoadedEventEnd - navigation.domContentLoadedEventStart,
6065
loadComplete: navigation.loadEventEnd - navigation.loadEventStart,
6166
totalTime: navigation.loadEventEnd - navigation.fetchStart,
62-
timestamp: new Date().toISOString(),
67+
timestamp: Date.now(),
6368
});
6469
}
6570
}, 0);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Demonstration of import.meta.env in Vite
3+
* This file shows what environment variables are available
4+
*/
5+
6+
// Vite provides import.meta.env which contains:
7+
console.log('=== Vite Environment Variables ===');
8+
9+
// Built-in variables provided by Vite
10+
console.log('MODE:', import.meta.env.MODE); // 'development' or 'production'
11+
console.log('DEV:', import.meta.env.DEV); // true in development
12+
console.log('PROD:', import.meta.env.PROD); // true in production
13+
console.log('SSR:', import.meta.env.SSR); // true during server-side rendering
14+
15+
// Custom environment variables from .env files
16+
// Only variables prefixed with VITE_ are exposed to the client
17+
console.log('VITE_GA_MEASUREMENT_ID:', import.meta.env.VITE_GA_MEASUREMENT_ID);
18+
19+
// BASE_URL is the public path when served in development or production
20+
console.log('BASE_URL:', import.meta.env.BASE_URL);
21+
22+
// Show all available environment variables
23+
console.log('\n=== All Available Environment Variables ===');
24+
Object.keys(import.meta.env).forEach(key => {
25+
console.log(`${key}:`, import.meta.env[key]);
26+
});
27+
28+
/**
29+
* How import.meta.env works:
30+
*
31+
* 1. Vite automatically provides import.meta.env in your code
32+
* 2. It loads variables from .env files in this order:
33+
* - .env.local (Always loaded, ignored by git)
34+
* - .env.[mode] (e.g., .env.development, .env.production)
35+
* - .env (Loaded in all cases)
36+
*
37+
* 3. Only variables prefixed with VITE_ are exposed to the client code
38+
* for security reasons
39+
*
40+
* 4. During build, Vite statically replaces import.meta.env with the actual values
41+
*
42+
* 5. You can access environment variables in your code like:
43+
* - const isDev = import.meta.env.DEV
44+
* - const apiUrl = import.meta.env.VITE_API_URL
45+
*/
46+
47+
export const getEnvironment = () => {
48+
return {
49+
mode: import.meta.env.MODE,
50+
isDevelopment: import.meta.env.DEV,
51+
isProduction: import.meta.env.PROD,
52+
baseUrl: import.meta.env.BASE_URL,
53+
gaMeasurementId: import.meta.env.VITE_GA_MEASUREMENT_ID,
54+
}
55+
}
56+
57+
export default getEnvironment

0 commit comments

Comments
 (0)