Skip to content

Commit

Permalink
Merge pull request #259 from senacor/feature/add-logging-capabilities
Browse files Browse the repository at this point in the history
Provide Logging-Capabilities
  • Loading branch information
maaaNu authored Sep 19, 2023
2 parents 75beeac + fc1a030 commit d4f1cd4
Show file tree
Hide file tree
Showing 23 changed files with 2,893 additions and 8,856 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
node-version: [ 14.x, 15.x, 16.x ]
node-version: [ 15.x, 16.x ]

steps:
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
test:
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/azure-functions/node:3.0-node12
image: mcr.microsoft.com/azure-functions/node:4-node18
env:
FUNCTIONS_WORKER_RUNTIME: node

Expand All @@ -24,7 +24,7 @@ jobs:
shell: bash
working-directory: ./example
run: |
npm ci && npm install -g azure-functions-core-tools@3 --unsafe-perm true
npm ci && npm install -g azure-functions-core-tools@4 --unsafe-perm true
- name: start-test-function
shell: bash
working-directory: ./example
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ name: Release

on:
push:
branches: [ master ]
branches:
- master
- 'alpha/**'

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [ 14.x ]
node-version: [ 16.x ]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -38,3 +40,4 @@ jobs:
with:
name: Release v${{ steps.publish.outputs.version }}
tag_name: v${{ steps.publish.outputs.version }}
prerelease: ${{ contains(github.head_ref, 'alpha') }}
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 2.0.0 (01.04.2023)
- Added auto-logging functionality to the library that enhances searchability of saved log statements in Azure AppInsights by storing context properties in commonProperties.
- Removed the MiddlewareFunction-Type in favor for the azure-built-in one
- There are now two types of middleware available: one with error handling and one without. This is helpful because durable functions must throw their errors, otherwise the orchestrator will not restart a failed function.


## 1.5.0 (27.03.2023)

- Added additional helper function to authentication requests by header parameters
Expand Down Expand Up @@ -28,5 +34,5 @@
Features:

- add middleware for azure function to use generic functionality across multiple azure functions
- add [joi](https://github.com/sideway/joi) validation as integration for the middleware to validate incomming requests against a schema
- add [joi](https://github.com/sideway/joi) validation as integration for the middleware to validate incoming requests against a schema
- add JWT authorization as integration for the middleware to authorize requests against a passed JWT
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,17 @@ const afterFunction = (context: Context, request: HttpRequest): Promise<void> =>

export default middleware(functionHandler, [], [afterFunction]);
```

### Logging and Tracing with appInsights

To enhance the logging and tracing with appInsights you can wrap your function with the appInsightWrapper. Currently, this will log the query-parameter
and binding-context of request into the customProperties, which will make your logs more searchable.

Use the `AppInsightForHttpTrigger` for your http-functions:
```typescript
import {AppInsightForHttpTrigger} from "./appInsightsWrapper";

export default middleware([AppInsightForHttpTrigger.setup], handler, [AppInsightForHttpTrigger.finalizeAppInsight])
```

and the `AppInsightForNonHttpTrigger` for functions with different kinds of trigger (e.g. `activityTrigger` or `timerTrigger`).
2 changes: 1 addition & 1 deletion example/.nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14.18.1
18.15.0
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const functionHandler = async (context: Context): Promise<void> => {
context.res = { status: 204 };
};

export default middleware(functionHandler, [headerAuthentication()]);
export default middleware([headerAuthentication()], functionHandler, []);
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ const functionHandler = async (context: Context): Promise<void> => {
context.res = { status: 204 };
};

export default middleware(functionHandler, [
authorization([
{
parameterExtractor: (parameters: ContextBindingData) => parameters.id,
jwtExtractor: (jwt: { userId: string }) => jwt.userId,
},
]),
]);
export default middleware(
[
authorization([
{
parameterExtractor: (parameters: ContextBindingData) => parameters.id,
jwtExtractor: (jwt: { userId: string }) => jwt.userId,
},
]),
],
functionHandler,
[],
);
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ const afterFunction = (context: Context): Promise<void> => {
return;
};

export default middleware(functionHandler, [validation(schema)], [afterFunction]);
export default middleware([validation(schema)], functionHandler, [afterFunction]);
8 changes: 3 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module.exports = {
clearMocks: true,
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ["/node_modules/", "/dist/", "/config/"],
moduleDirectories: [
"node_modules"
],
}
testPathIgnorePatterns: ['/node_modules/', '/dist/', '/config/'],
moduleDirectories: ['node_modules'],
};
18 changes: 7 additions & 11 deletions jest.integration.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: [
'**/*.integration.ts'
],
testPathIgnorePatterns: ["/node_modules/", "/dist/", "/config/"],
moduleDirectories: [
"node_modules"
],
testTimeout: 10000,
testMatch: ['**/*.integration.ts'],
testPathIgnorePatterns: ['/node_modules/', '/dist/', '/config/'],
moduleDirectories: ['node_modules'],
testTimeout: 30000,
moduleNameMapper: {
"axios": "axios/dist/node/axios.cjs"
}
}
axios: 'axios/dist/node/axios.cjs',
},
};
Loading

0 comments on commit d4f1cd4

Please sign in to comment.