Skip to content

Commit

Permalink
revert whatever happened
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr committed Nov 12, 2024
1 parent dfd20e9 commit 8f4e842
Show file tree
Hide file tree
Showing 116 changed files with 6,834 additions and 7,666 deletions.
161 changes: 104 additions & 57 deletions NEWS.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bin/run-bench.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
/*
* Copyright 2022 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
Expand Down
25 changes: 24 additions & 1 deletion changelog.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
{
"repository": "newrelic/node-newrelic",
"entries": [
{
"version": "12.7.0",
"changes": {
"security": [],
"bugfixes": [],
"features": [
"Added `cloud.resource_id` attribute to dynamo spans",
"Enhance Proxy Request Handling to Display Actual External URLs"
]
}
},
{
"version": "12.6.1",
"changes": {
"security": [],
"bugfixes": [
"Fixed issue parsing docker container id"
],
"features": [
"added `cloud.aws.account_id` to default config"
]
}
},
{
"version": "12.6.0",
"changes": {
Expand Down Expand Up @@ -657,4 +680,4 @@
}
}
]
}
}
28 changes: 14 additions & 14 deletions compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ version.
| --- | --- | --- | --- |
| `@apollo/gateway` | 2.3.0 | 2.9.3 | `@newrelic/[email protected]` |
| `@apollo/server` | 4.0.0 | 4.11.2 | `@newrelic/[email protected]` |
| `@aws-sdk/client-bedrock-runtime` | 3.474.0 | 3.682.0 | 11.13.0 |
| `@aws-sdk/client-dynamodb` | 3.0.0 | 3.682.0 | 8.7.1 |
| `@aws-sdk/client-sns` | 3.0.0 | 3.682.0 | 8.7.1 |
| `@aws-sdk/client-sqs` | 3.0.0 | 3.682.0 | 8.7.1 |
| `@aws-sdk/lib-dynamodb` | 3.377.0 | 3.682.0 | 8.7.1 |
| `@aws-sdk/client-bedrock-runtime` | 3.474.0 | 3.687.0 | 11.13.0 |
| `@aws-sdk/client-dynamodb` | 3.0.0 | 3.687.0 | 8.7.1 |
| `@aws-sdk/client-sns` | 3.0.0 | 3.687.0 | 8.7.1 |
| `@aws-sdk/client-sqs` | 3.0.0 | 3.687.0 | 8.7.1 |
| `@aws-sdk/lib-dynamodb` | 3.377.0 | 3.687.0 | 8.7.1 |
| `@aws-sdk/smithy-client` | 3.47.0 | 3.374.0 | 8.7.1 |
| `@elastic/elasticsearch` | 7.16.0 | 8.15.1 | 11.9.0 |
| `@grpc/grpc-js` | 1.4.0 | 1.12.2 | 8.17.0 |
| `@hapi/hapi` | 20.1.2 | 21.3.12 | 9.0.0 |
| `@koa/router` | 11.0.2 | 13.1.0 | 3.2.0 |
| `@langchain/core` | 0.1.17 | 0.3.16 | 11.13.0 |
| `@nestjs/cli` | 9.0.0 | 10.4.5 | 10.1.0 |
| `@prisma/client` | 5.0.0 | 5.21.1 | 11.0.0 |
| `@langchain/core` | 0.1.17 | 0.3.17 | 11.13.0 |
| `@nestjs/cli` | 9.0.0 | 10.4.7 | 10.1.0 |
| `@prisma/client` | 5.0.0 | 5.22.0 | 11.0.0 |
| `@smithy/smithy-client` | 2.0.0 | 3.4.2 | 11.0.0 |
| `amqplib` | 0.5.0 | 0.10.4 | 2.0.0 |
| `apollo-server` | 3.0.0 | 3.13.0 | `@newrelic/[email protected]` |
| `apollo-server-express` | 3.0.0 | 3.13.0 | `@newrelic/[email protected]` |
| `aws-sdk` | 2.2.48 | 2.1691.0 | 6.2.0 |
| `aws-sdk` | 2.2.48 | 2.1692.0 | 6.2.0 |
| `bluebird` | 2.0.0 | 3.7.2 | 1.27.0 |
| `bunyan` | 1.8.12 | 1.8.15 | 9.3.0 |
| `cassandra-driver` | 3.4.0 | 4.7.2 | 1.7.1 |
| `connect` | 3.0.0 | 3.7.0 | 2.6.0 |
| `express` | 4.6.0 | 4.21.1 | 2.6.0 |
| `fastify` | 2.0.0 | 5.0.0 | 8.5.0 |
| `fastify` | 2.0.0 | 5.1.0 | 8.5.0 |
| `generic-pool` | 3.0.0 | 3.9.0 | 0.9.0 |
| `ioredis` | 4.0.0 | 5.4.1 | 1.26.2 |
| `kafkajs` | 2.0.0 | 2.2.4 | 11.19.0 |
Expand All @@ -46,9 +46,9 @@ version.
| `memcached` | 2.2.0 | 2.2.2 | 1.26.2 |
| `mongodb` | 4.1.4 | 6.10.0 | 1.32.0 |
| `mysql` | 2.2.0 | 2.18.1 | 1.32.0 |
| `mysql2` | 2.0.0 | 3.11.3 | 1.32.0 |
| `next` | 13.4.19 | 15.0.2 | 12.0.0 |
| `openai` | 4.0.0 | 4.69.0 | 11.13.0 |
| `mysql2` | 2.0.0 | 3.11.4 | 1.32.0 |
| `next` | 13.4.19 | 15.0.3 | 12.0.0 |
| `openai` | 4.0.0 | 4.71.1 | 11.13.0 |
| `pg` | 8.2.0 | 8.13.1 | 9.0.0 |
| `pg-native` | 3.0.0 | 3.2.0 | 9.0.0 |
| `pino` | 7.0.0 | 9.5.0 | 8.11.0 |
Expand All @@ -58,7 +58,7 @@ version.
| `superagent` | 3.0.0 | 10.1.1 | 4.9.0 |
| `undici` | 5.0.0 | 6.20.1 | 11.1.0 |
| `when` | 3.7.0 | 3.7.8 | 1.26.2 |
| `winston` | 3.0.0 | 3.15.0 | 8.11.0 |
| `winston` | 3.0.0 | 3.17.0 | 8.11.0 |

*When package is not specified, support is within the `newrelic` package.

Expand Down
11 changes: 11 additions & 0 deletions lib/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,17 @@ defaultConfig.definition = () => ({
default: false
}
},
cloud: {
aws: {
/**
* The AWS account ID for the AWS account associated with this app.
*/
account_id: {
formatter: int,
default: null
}
}
},
/**
* Options regarding collecting system information. Used for system
* utilization based pricing scheme.
Expand Down
54 changes: 0 additions & 54 deletions lib/db/parsed-statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

'use strict'

const { DB, ALL } = require('../metrics/names')
const { DESTINATIONS } = require('../config/attribute-filter')

function ParsedStatement(type, operation, collection, raw) {
this.type = type
this.operation = operation
Expand All @@ -21,55 +18,4 @@ function ParsedStatement(type, operation, collection, raw) {
}
}

ParsedStatement.prototype.recordMetrics = function recordMetrics(segment, scope) {
const duration = segment.getDurationInMillis()
const exclusive = segment.getExclusiveDurationInMillis()
const transaction = segment.transaction
const type = transaction.isWeb() ? DB.WEB : DB.OTHER
const thisTypeSlash = this.type + '/'
const operation = DB.OPERATION + '/' + thisTypeSlash + this.operation

// Note, an operation metric should _always_ be created even if the action was
// a statement. This is part of the spec.

// Rollups
transaction.measure(operation, null, duration, exclusive)
transaction.measure(DB.PREFIX + type, null, duration, exclusive)
transaction.measure(DB.PREFIX + thisTypeSlash + type, null, duration, exclusive)
transaction.measure(DB.PREFIX + thisTypeSlash + ALL, null, duration, exclusive)
transaction.measure(DB.ALL, null, duration, exclusive)

// If we can parse the SQL statement, create a 'statement' metric, and use it
// as the scoped metric for transaction breakdowns. Otherwise, skip the
// 'statement' metric and use the 'operation' metric as the scoped metric for
// transaction breakdowns.
let collection
if (this.collection) {
collection = DB.STATEMENT + '/' + thisTypeSlash + this.collection + '/' + this.operation
transaction.measure(collection, null, duration, exclusive)
if (scope) {
transaction.measure(collection, scope, duration, exclusive)
}
} else if (scope) {
transaction.measure(operation, scope, duration, exclusive)
}

// This recorder is side-effectful Because we are depending on the recorder
// setting the transaction name, recorders must always be run before generating
// the final transaction trace
segment.name = collection || operation

// Datastore instance metrics.
const attributes = segment.attributes.get(DESTINATIONS.TRANS_SEGMENT)
if (attributes.host && attributes.port_path_or_id) {
const instanceName =
DB.INSTANCE + '/' + thisTypeSlash + attributes.host + '/' + attributes.port_path_or_id
transaction.measure(instanceName, null, duration, exclusive)
}

if (this.raw) {
transaction.agent.queries.add(segment, this.type.toLowerCase(), this.raw, this.trace)
}
}

module.exports = ParsedStatement
69 changes: 57 additions & 12 deletions lib/instrumentation/aws-sdk/v3/dynamodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,66 @@ function dynamoMiddleware(shim, config, next, context) {
}
}

const dynamoMiddlewareConfig = {
middleware: dynamoMiddleware,
init(shim) {
shim.setDatastore(shim.DYNAMODB)
return true
},
type: InstrumentationDescriptor.TYPE_DATASTORE,
config: {
name: 'NewRelicDynamoMiddleware',
step: 'initialize',
priority: 'high',
override: true
/**
* Wraps the deserialize middleware step to add the
* cloud.resource_id segment attributes for the AWS command
*
* @param {Shim} shim
* @param {Object} config AWS command configuration
* @param {function} next next function in middleware chain
* @returns {function}
*/
function resourceIdMiddlerware(shim, config, next) {
return async function wrappedResourceIdMiddlerware(args) {
let region
try {
region = await config.region()
const segment = shim.getSegment()

const accountId = shim.agent.config.cloud.aws.account_id

if (accountId) {
const attributes = segment.getAttributes()
segment.addAttribute(
'cloud.resource_id',
`arn:aws:dynamodb:${region}:${accountId}:table/${attributes.collection}`
)
}
} catch (err) {
shim.logger.debug(err, 'Failed to add AWS cloud resource id to segment')
}

return next(args)
}
}

const dynamoMiddlewareConfig = [
{
middleware: dynamoMiddleware,
init(shim) {
shim.setDatastore(shim.DYNAMODB)
return true
},
type: InstrumentationDescriptor.TYPE_DATASTORE,
config: {
name: 'NewRelicDynamoMiddleware',
step: 'initialize',
priority: 'high',
override: true
}
},
{
middleware: resourceIdMiddlerware,
type: InstrumentationDescriptor.TYPE_GENERIC,
config: {
name: 'NewRelicCloudResource',
step: 'deserialize',
priority: 'low',
override: true
}
}
]

module.exports = {
dynamoMiddlewareConfig
}
4 changes: 2 additions & 2 deletions lib/instrumentation/aws-sdk/v3/smithy-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const middlewareByClient = {
BedrockRuntime: [...middlewareConfig, bedrockMiddlewareConfig],
SNS: [...middlewareConfig, snsMiddlewareConfig],
SQS: [...middlewareConfig, sqsMiddlewareConfig],
DynamoDB: [...middlewareConfig, dynamoMiddlewareConfig],
DynamoDBDocument: [...middlewareConfig, dynamoMiddlewareConfig]
DynamoDB: [...middlewareConfig, ...dynamoMiddlewareConfig],
DynamoDBDocument: [...middlewareConfig, ...dynamoMiddlewareConfig]
}

module.exports = function instrumentSmithyClient(shim, smithyClientExport) {
Expand Down
26 changes: 25 additions & 1 deletion lib/instrumentation/core/http-outbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const copy = require('../../util/copy')
const symbols = require('../../symbols')
const http = require('http')
const synthetics = require('../../synthetics')
const { URL } = require('node:url')

const NAMES = require('../../metrics/names')
const DEFAULT_HOST = 'localhost'
Expand Down Expand Up @@ -93,6 +94,27 @@ function extractHostPort(opts) {
return { host, hostname, port }
}

/**
* Extracts the host, hostname, and port from HTTP request options when using a proxy
*
* @param {object} opts HTTP request options
* @returns {object|null} { host, hostname, port } if proxy request is detected, or null otherwise.
*/
function extractHostPortViaProxy(opts) {
const pathname = opts.pathname || opts.path

if (pathname && (pathname.startsWith('https://') || pathname.startsWith('http://'))) {
const url = new URL(pathname)
return {
host: url.host,
hostname: url.hostname,
port: url.port || url.protocol === 'https:' ? '443' : '80'
}
}

return null
}

/**
* Instruments an outbound HTTP request.
*
Expand All @@ -103,7 +125,9 @@ function extractHostPort(opts) {
*/
module.exports = function instrumentOutbound(agent, opts, makeRequest) {
opts = parseOpts(opts)
const { host, hostname, port } = extractHostPort(opts)

const viaProxy = extractHostPortViaProxy(opts)
const { host, hostname, port } = viaProxy ? viaProxy : extractHostPort(opts)

if (!hostname || port < 1) {
logger.warn('Invalid host name (%s) or port (%s) for outbound request.', hostname, port)
Expand Down
2 changes: 1 addition & 1 deletion lib/instrumentation/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function wrapResponse(shim, response) {
if (!shim.isFunction(cb)) {
++cbIdx
cb = function defaultRenderCB(err, str) {
// https://github.com/expressjs/express/blob/4.x/lib/response.js#L961-L962
// https://github.com/expressjs/express/blob/4.x/lib/response.js#L961-L962
if (err) {
return res.req.next(err)
}
Expand Down
6 changes: 5 additions & 1 deletion lib/llm-events/aws-bedrock/bedrock-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ class BedrockCommand {
result = this.#body.prompt
} else if (this.isClaude3() === true) {
result = this.#body?.messages?.reduce((acc, curr) => {
acc += curr?.content ?? ''
if (typeof curr?.content === 'string') {
acc += curr?.content
} else if (Object.keys(curr?.content).length) {
acc += curr?.content.text ?? ''
}
return acc
}, '')
}
Expand Down
Loading

0 comments on commit 8f4e842

Please sign in to comment.