-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored LogRecords to be mutable so that attributes can be modifie…
…d after creation
- Loading branch information
1 parent
8e35e04
commit 4df5c2e
Showing
7 changed files
with
225 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module OpenTelemetry.Logging.CoreSpec where | ||
|
||
import qualified Data.HashMap.Strict as H | ||
import Data.IORef | ||
import qualified OpenTelemetry.Attributes as A | ||
import OpenTelemetry.Internal.Logging.Types | ||
import qualified OpenTelemetry.LogAttributes as LA | ||
import OpenTelemetry.Logging.Core | ||
import OpenTelemetry.Resource | ||
import OpenTelemetry.Resource.OperatingSystem | ||
import Test.Hspec | ||
|
||
|
||
spec :: Spec | ||
spec = describe "Core" $ do | ||
describe "getGlobalLoggerProvider" $ do | ||
it "Returns a no-op LoggerProvider when not initialized" $ do | ||
LoggerProvider {..} <- getGlobalLoggerProvider | ||
loggerProviderResource `shouldBe` emptyMaterializedResources | ||
loggerProviderAttributeLimits `shouldBe` LA.defaultAttributeLimits | ||
describe "setGlobalLoggerProvider" $ do | ||
it "works" $ do | ||
lp <- | ||
createLoggerProvider $ | ||
LoggerProviderOptions | ||
{ loggerProviderOptionsResource = | ||
materializeResources $ | ||
toResource | ||
OperatingSystem | ||
{ osType = "exampleOs" | ||
, osDescription = Nothing | ||
, osName = Nothing | ||
, osVersion = Nothing | ||
} | ||
, loggerProviderOptionsAttributeLimits = | ||
LA.AttributeLimits | ||
{ attributeCountLimit = Just 50 | ||
, attributeLengthLimit = Just 50 | ||
} | ||
} | ||
setGlobalLoggerProvider lp | ||
glp <- getGlobalLoggerProvider | ||
glp `shouldBe` lp | ||
describe "addAttribute" $ do | ||
it "works" $ do | ||
lp <- getGlobalLoggerProvider | ||
let l = makeLogger lp InstrumentationLibrary {libraryName = "exampleLibrary", libraryVersion = "", librarySchemaUrl = "", libraryAttributes = A.emptyAttributes} | ||
lr <- | ||
emitLogRecord | ||
l | ||
LogRecordArguments | ||
{ timestamp = Nothing | ||
, observedTimestamp = Nothing | ||
, context = Nothing | ||
, severityText = Nothing | ||
, severityNumber = Nothing | ||
, body = Nothing | ||
, attributes = | ||
H.fromList | ||
[ ("something", "a thing") | ||
] | ||
} | ||
addAttribute lr "anotherThing" ("another thing" :: LA.AnyValue) | ||
|
||
(_, attrs) <- LA.getAttributes <$> logRecordGetAttributes lr | ||
|
||
attrs | ||
`shouldBe` H.fromList | ||
[ ("anotherThing", "another thing") | ||
, ("something", "a thing") | ||
] | ||
describe "addAttributes" $ do | ||
it "works" $ do | ||
lp <- getGlobalLoggerProvider | ||
let l = makeLogger lp InstrumentationLibrary {libraryName = "exampleLibrary", libraryVersion = "", librarySchemaUrl = "", libraryAttributes = A.emptyAttributes} | ||
lr <- | ||
emitLogRecord | ||
l | ||
LogRecordArguments | ||
{ timestamp = Nothing | ||
, observedTimestamp = Nothing | ||
, context = Nothing | ||
, severityText = Nothing | ||
, severityNumber = Nothing | ||
, body = Nothing | ||
, attributes = | ||
H.fromList | ||
[ ("something", "a thing") | ||
] | ||
} | ||
addAttributes lr $ | ||
H.fromList | ||
[ ("anotherThing", "another thing" :: LA.AnyValue) | ||
, ("twoThing", "the second another thing") | ||
] | ||
|
||
(_, attrs) <- LA.getAttributes <$> logRecordGetAttributes lr | ||
|
||
attrs | ||
`shouldBe` H.fromList | ||
[ ("anotherThing", "another thing") | ||
, ("something", "a thing") | ||
, ("twoThing", "the second another thing") | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters