Merge pull request #1 from ai-chat-os/chore/new-relic

Add Newrelic
This commit is contained in:
Fabiano Martins 2025-02-05 17:14:24 -03:00 committed by GitHub
commit 3fb7b66fe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 824 additions and 4 deletions

View File

@ -51,8 +51,10 @@ COPY --from=builder /evolution/Docker ./Docker
COPY --from=builder /evolution/runWithProvider.js ./runWithProvider.js COPY --from=builder /evolution/runWithProvider.js ./runWithProvider.js
COPY --from=builder /evolution/tsup.config.ts ./tsup.config.ts COPY --from=builder /evolution/tsup.config.ts ./tsup.config.ts
COPY newrelic.js .
ENV DOCKER_ENV=true ENV DOCKER_ENV=true
EXPOSE 8080 EXPOSE 8080
ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ] ENTRYPOINT ["/bin/bash", "-c", ". ./Docker/scripts/deploy_database.sh && npm run start:prod" ]

87
chatfluxctl Executable file
View File

@ -0,0 +1,87 @@
#!/bin/bash
if [ "$#" -lt 3 ]; then
echo "Usage: $0 <environment> <action> <service_name>"
echo "Environment: staging|production"
echo "Action: start|stop"
echo "Service: service_name|all"
exit 1
fi
ENVIRONMENT=$1
ACTION=$2
SERVICE_NAME=$3
BASE_COMPOSE=""
ENV_COMPOSE=""
DOCKER_COMPOSE_CMD="docker compose"
# Check for both yml and yaml extensions for base compose
if [ -f "docker-compose.yml" ]; then
BASE_COMPOSE="docker-compose.yml"
elif [ -f "docker-compose.yaml" ]; then
BASE_COMPOSE="docker-compose.yaml"
else
echo "Error: Base docker-compose file not found (tried .yml and .yaml)"
exit 1
fi
# Check for both yml and yaml extensions for environment compose
if [ -f "docker-compose.${ENVIRONMENT}.yml" ]; then
ENV_COMPOSE="docker-compose.${ENVIRONMENT}.yml"
elif [ -f "docker-compose.${ENVIRONMENT}.yaml" ]; then
ENV_COMPOSE="docker-compose.${ENVIRONMENT}.yaml"
else
echo "Error: Environment docker-compose file not found (tried .yml and .yaml)"
exit 1
fi
# Validate environment
if [ "$ENVIRONMENT" != "staging" ] && [ "$ENVIRONMENT" != "production" ]; then
echo "Error: Environment must be either 'staging' or 'production'"
exit 1
fi
# Validate action
if [ "$ACTION" != "start" ] && [ "$ACTION" != "stop" ]; then
echo "Error: Action must be either 'start' or 'stop'"
exit 1
fi
# Function to check if service exists in compose files
check_service() {
local service=$1
if [ "$service" != "all" ]; then
if ! $DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE config --services | grep -q "^$service$"; then
echo "Error: Service '$service' not found in docker-compose files"
exit 1
fi
fi
}
# Validate service exists
check_service $SERVICE_NAME
if [ "$ACTION" == "stop" ]; then
echo "Stopping service(s): $SERVICE_NAME"
if [ "$SERVICE_NAME" == "all" ]; then
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE down
else
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE stop $SERVICE_NAME
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE rm -f $SERVICE_NAME
fi
else
echo "Starting service(s): $SERVICE_NAME"
if [ "$SERVICE_NAME" == "all" ]; then
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE up -d
else
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE up -d $SERVICE_NAME
fi
fi
# Check service status
echo "Service status:"
if [ "$SERVICE_NAME" == "all" ]; then
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE ps
else
$DOCKER_COMPOSE_CMD -f $BASE_COMPOSE -f $ENV_COMPOSE ps $SERVICE_NAME
fi

View File

@ -0,0 +1,5 @@
services:
api:
environment:
CHATFLUX_ENV: Staging
NEW_RELIC_APP_NAME: "Staging Evolution API"

View File

@ -1,10 +1,22 @@
services: services:
api: api:
container_name: evolution_api container_name: evolution_api
image: atendai/evolution-api:v2.2.1 image: ghcr.io/ai-chat-os/evolution-api:v2.2.1
restart: always restart: always
depends_on: depends_on:
- postgres - postgres
environment:
# 1- Add the Env key values pair to /etc/environment file
# 2- Run source /etc/environment
# 3- Run env |grep -i relic; to validate it being loaded.
# 4- If didn't, CTRL+d to logout
# 5- Login to the server
# 6- Run env |grep -i relic again;
NEW_RELIC_LICENSE_KEY: ${NEW_RELIC_LICENSE_KEY}
NEW_RELIC_NO_CONFIG_FILE: true
NEW_RELIC_DISTRIBUTED_TRACING_ENABLED: true
NEW_RELIC_LOG: stdout
NODE_ENV: PROD
ports: ports:
- 8080:8080 - 8080:8080
volumes: volumes:

22
newrelic.js Normal file
View File

@ -0,0 +1,22 @@
exports.config = {
app_name: [`${process.env.CHATFLUX_ENV} Evolution API`],
license_key: process.env.NEW_RELIC_LICENSE_KEY,
logging: {
level: 'trace'
},
allow_all_headers: true,
attributes: {
exclude: [
'request.headers.cookie',
'request.headers.authorization',
'request.headers.proxyAuthorization',
'request.headers.setCookie*',
'request.headers.x*',
'response.headers.cookie',
'response.headers.authorization',
'response.headers.proxyAuthorization',
'response.headers.setCookie*',
'response.headers.x*'
]
}
}

691
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -82,6 +82,7 @@
"mime-types": "^2.1.35", "mime-types": "^2.1.35",
"minio": "^8.0.3", "minio": "^8.0.3",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"newrelic": "^12.11.3",
"node-cache": "^5.1.2", "node-cache": "^5.1.2",
"node-cron": "^3.0.3", "node-cron": "^3.0.3",
"openai": "^4.77.3", "openai": "^4.77.3",

View File

@ -1,5 +1,6 @@
// Import this first from sentry instrument! // Import this first from sentry instrument!
import '@utils/instrumentSentry'; import '@utils/instrumentSentry';
import './newrelic';
// Now import other modules // Now import other modules
import { ProviderFiles } from '@api/provider/sessions'; import { ProviderFiles } from '@api/provider/sessions';

3
src/newrelic.ts Normal file
View File

@ -0,0 +1,3 @@
if (process.env.NODE_ENV === 'PROD') {
require('newrelic');
}