Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week 16 sentry and google analytics logging files added #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Week-16/googleanalytics/Screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions Week-16/googleanalytics/frontend-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />

<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />

<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-8BSCRC95HC"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-8BSCRC95HC');
</script>
<div id="root"></div>

</body>
</html>
9 changes: 9 additions & 0 deletions Week-16/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Assignment 16
## Sentry frontend and backend logging

![img](./sentry/Screenshot1.PNG)
![img](./sentry/Screenshot2.PNG)
![img](./sentry/Screenshot3.PNG)

## Google Analytics user logging.
![img](./googleanalytics/Screenshot1.PNG)
Binary file added Week-16/sentry/Screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Week-16/sentry/Screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Week-16/sentry/Screenshot3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions Week-16/sentry/backend-routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const express = require("express");
const Sentry= require("@sentry/node")

require("@sentry/tracing")
const Model = require("../models/model");
const router = express.Router();
const axios = require("axios");
require("dotenv").config();
const API_KEY = process.env.API_KEY;
Sentry.init({
dsn: "https://c1b7c10c133f45f6867d9e48b1b5279a@o1408070.ingest.sentry.io/6743473",


tracesSampleRate: 1.0,
});
const transaction = Sentry.startTransaction({
op: "test",
name: "My First Test Transaction",
});
router.get("/current", async (req, res) => {
const result = [];
const cities =new Set(req.query.city.split(","));

for (let city of cities) {
console.log(city)
let url = `http://api.weatherapi.com/v1/current.json?key=${API_KEY}&q=${city}`;
console.log(url)

try {
let results = await axios.get(url);
json = results.data;

result.push(json);
} catch (err) {

console.log('ERROR IS COMING')
console.log(err)
Sentry.captureException(err);
}finally{
transaction.finish();
}



}


});

router.get("/forecast", async (req, res) => {

const result = [];

if (!req.query.city || !req.query.days) return [];
const cities = req.query.city.split(",");
const { days } = req.query;
for (let i = 0; i < cities.length; i++) {
try {let url = `http://api.weatherapi.com/v1/forecast.json?key=${API_KEY}&q=${cities[i]}&days=${days}`;
let results = await axios.get(url);
results = results.data;
result.push(results);
} catch (err) {
console.log("data not found");
}
}
res.send(result);
});
module.exports = router;
17 changes: 17 additions & 0 deletions Week-16/sentry/frontend-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import * as Sentry from "@sentry/react";
import { BrowserTracing } from "@sentry/tracing";
Sentry.init({
dsn: "https://c1b7c10c133f45f6867d9e48b1b5279a@o1408070.ingest.sentry.io/6743473",
integrations: [new BrowserTracing()],
tracesSampleRate: 1.0,
});
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);